Best JavaScript code snippet using best
instanceComparisonSummarizer.js
Source:instanceComparisonSummarizer.js
1(function () {2 summarizer = {};3 summarizer.instanceMap = {};4 summarizer.featureMap = {};5 summarizer.intercept = null;6 summarizer.globalSummaryMap = {7 "housing-gam-instance-data" : {8 "Linear-positive" : {9 "description" : "For <b>1 feature</b>, the final prediction increases when any feature value increases.",10 "features" : ["CHAS"]11 },12 "Linear-negative" : {13 "description" : "For <b>4 features</b>, the final prediction decreases when any feature value decreases.",14 "features" : ["INDUS","RAD","PTRATIO","LSTAT"]15 },16 "Non-linear" : {17 "description" : "For <b>8 features</b>, the final prediction is not proportional to a change in any feature value.",18 "features" : ["CRIM","ZN","NOX","RM","AGE","DIS","TAX","B"]19 },20 "Flat": {21 "description" : "",22 "features" : []23 }24 },25 "diamonds-gam-instance-data" : {26 "Linear-positive" : {27 "description" : "For <b>5 features</b>, the final prediction increases when any feature value increases.",28 "features" : ["carat","color","clarity","depth","y"]29 },30 "Linear-negative" : {31 "description" : "",32 "features" : []33 },34 "Non-linear" : {35 "description" : "For <b>2 features</b>, the final prediction is not proportional to a change in any feature value.",36 "features" : ["x","z"]37 },38 "Flat": {39 "description" : "For <b>2 features</b>, the final prediction remains constant when any feature value changes.",40 "features" : ["cut","table"]41 }42 },43 "red-wine-gam-instance-data" : {44 "Linear-positive" : {45 "description" : "For <b>2 features</b>, the final prediction increases when any feature value increases.",46 "features" : ["alcohol","residualSugar"]47 },48 "Linear-negative" : {49 "description" : "For <b>4 features</b>, the final prediction decreases when any feature value decreases.",50 "features" : ["volatileAcidity","chlorides","density","pH"]51 },52 "Non-linear" : {53 "description" : "For <b>5 features</b>, the final prediction is not proportional to a change in any feature value.",54 "features" : ["fixedAcidity","citricAcid","freeSulfurDioxide","totalSulfurDioxide","sulphates"]55 },56 "Flat" : {57 "description" : "",58 "features" : []59 }60 },61 "ames-housing-gam-instance-data" : {62 "Linear-positive" : {63 "description" : "For <b>9 features</b>, the final prediction increases when any feature value increases.",64 "features" : ["LotFrontage","LotArea","OverallQual","OverallCond","TotalBsmtSF","FirstFlrSF"65 ,"SecondFlrSF","GarageCars","ThreeSsnPorch"]66 },67 "Linear-negative" : {68 "description" : "For <b>2 features</b>, the final prediction decreases when any feature value decreases.",69 "features" : ["KitchenAbvGr","EnclosedPorch"]70 },71 "Non-linear" : {72 "description" : "For <b>6 features</b>, the final prediction is not proportional to a change in any feature value.",73 "features" : ["GarageArea","GrLivArea","BsmtFinSFOne","WoodDeckSF","OpenPorchSF","PoolArea"]74 },75 "Flat" : {76 "description" : "For <b>18 features</b>, the final prediction remains constant when any feature value changes.",77 "features" : ["MSSubClass","YearRemodAdd","TotRmsAbvGrd","MasVnrArea","BsmtFinSFTwo","BsmtUnfSF",78 "LowQualFinSF","BsmtFullBath","BsmtHalfBath","FullBath","HalfBath","BedroomAbvGr",79 "Fireplaces","ScreenPorch","MiscVal","GarageYrBlt","MoSold","YrSold"]80 }81 }82 };83 summarizer.globalSummaryMap_old = {84 "ames-housing-gam-instance-data" : [85 {86 "description":"Not coded yet",87 "features" : []88 }89 ],90 "housing-gam-instance-data" : [91 {92 "description":"5/13 features (<b>CRIM</b>, <b>ZN</b>, <b>NOX</b>, <b>AGE</b>, <b>RAD</b>) have a varying trend in predictions",93 "features" : ["CRIM", "ZN", "NOX", "AGE", "RAD"]94 },95 {96 "description":"3/13 features (<b>CHAS</b>, <b>RM</b>, <b>B</b>) have an upward trend in predictions (i.e., the prediction increases with an increase in data values)",97 "features" : ["CHAS", "RM", "B"]98 },99 {100 "description":"5/13 features (<b>INDUS</b>, <b>DIS</b>, <b>TAX</b>, <b>PTRATIO</b>, <b>LSTAT</b>) have a downward trend in predictions (i.e., the prediction decreases with an increase in data values)",101 "features" : ["INDUS", "DIS", "TAX", "PTRATIO", "LSTAT"]102 }103 ],104 "diamonds-gam-instance-data" : [105 {106 "description":"6/9 features (<b>carat</b>, <b>cut</b>, <b>color</b>, <b>clarity</b>, <b>depth</b>, <b>y</b>) have a varying trend in predictions",107 "features" : ["carat","cut","color","clarity","depth","y"]108 },109 {110 "description":"2/9 features (<b>x</b>, <b>z</b>) have an upward trend in predictions (i.e., the prediction increases with an increase in data values)",111 "features" : ["x","z"]112 },113 {114 "description":"1/9 features (<b>table</b>) have a downward trend in predictions (i.e., the prediction decreases with an increase in data values)",115 "features" : ["table"]116 }117 ],118 "red-wine-gam-instance-data" : [119 {120 "description":"3/11 features (<b>residualSugar</b>,<b>freeSulfurDioxide</b>, <b>alcohol</b>) have a varying trend in predictions",121 "features" : ["residualSugar", "freeSulfurDioxide","alcohol"]122 },123 {124 "description":"4/11 features (<b>volatileAcidity</b>, <b>chlorides</b>, <b>density</b>, <b>pH</b>) have an upward trend in predictions (i.e., the prediction increases with an increase in data values)",125 "features" : ["volatileAcidity", "chlorides", "density", "pH"]126 },127 {128 "description":"4/11 features (<b>fixedAcidity</b>, <b>citricAcid</b>, <b>totalSulfurDioxide</b>, <b>sulphates</b>) have a downward trend in predictions (i.e., the prediction decreases with an increase in data values)",129 "features" : ["fixedAcidity", "citricAcid", "totalSulfurDioxide", "sulphates"]130 }131 ]132 };133 summarizer.instanceSummaryParams = {};134 summarizer.instanceSummaryParams.contributionThreshold = .2;135 summarizer.instanceSummaryParams.summaryDetailLevel = 1;136 summarizer.comparisonParams = {};137 summarizer.comparisonParams.totalPredictionSimilarityThreshold = .25;138 summarizer.comparisonParams.totalPredictionDifferenceThreshold = .75;139 summarizer.comparisonParams.featurePredictionThreshold = .25;140 summarizer.comparisonParams.featurePredictionCountThreshold = .5;141 summarizer.comparisonParams.summaryDetailLevel = 1;142 summarizer.init = function (data, intercept) {143 summarizer.instanceMap = {};144 summarizer.featureMap = {};145 for(let instanceObj of data){146 let predictionObjs = instanceObj['data'];147 let totalPrediction = intercept;148 summarizer.intercept = intercept;149 summarizer.instanceMap[instanceObj['id']] = instanceObj;150 for(let predictionObj of predictionObjs){151 let feature = predictionObj['name'];152 let predictedValue = +predictionObj['pdep'];153 if(feature in summarizer.featureMap){154 summarizer.featureMap[feature]['values'].push(predictedValue);155 if(summarizer.featureMap[feature]['min']>predictedValue){156 summarizer.featureMap[feature]['min'] = predictedValue;157 }158 if(summarizer.featureMap[feature]['max']<predictedValue){159 summarizer.featureMap[feature]['max'] = predictedValue;160 }161 }else{162 summarizer.featureMap[feature] = {};163 summarizer.featureMap[feature]['values'] = [predictedValue];164 summarizer.featureMap[feature]['min'] = predictedValue;165 summarizer.featureMap[feature]['max'] = predictedValue;166 }167 totalPrediction += +(predictionObj['pdep']);168 }169 if('totalPrediction' in summarizer.featureMap){170 summarizer.featureMap['totalPrediction']['values'].push(totalPrediction);171 if(summarizer.featureMap['totalPrediction']['min']>totalPrediction){172 summarizer.featureMap['totalPrediction']['min'] = totalPrediction;173 }174 if(summarizer.featureMap['totalPrediction']['max']<totalPrediction){175 summarizer.featureMap['totalPrediction']['max'] = totalPrediction;176 }177 }else{178 summarizer.featureMap['totalPrediction'] = {};179 summarizer.featureMap['totalPrediction']['values'] = [totalPrediction];180 summarizer.featureMap['totalPrediction']['min'] = totalPrediction;181 summarizer.featureMap['totalPrediction']['max'] = totalPrediction;182 }183 summarizer.instanceMap[instanceObj['id']]['totalPrediction'] = totalPrediction;184 }185 for(let feature in summarizer.featureMap){186 let featureMinValue = summarizer.featureMap[feature]['min'];187 let featureMaxValue = summarizer.featureMap[feature]['max'];188 summarizer.featureMap[feature]['scale'] = d3.scaleLinear().domain([featureMinValue,featureMaxValue]).range([0,1]);189 }190 summarizer.featureCount = Object.keys(summarizer.featureMap).length-1;191 };192 summarizer.generateInstanceSummary = function(instanceObj) {193 let summaryObj = {}, instanceObjPredictionObjs = instanceObj['data'];194 let totalIndividualPredictions = 0;195 for(let i=0;i<instanceObjPredictionObjs.length;i++){196 totalIndividualPredictions += Math.abs(instanceObjPredictionObjs[i]['pdep']);197 }198 let featureContributionMap = {}, highlyContributingFeatures = [], highlyContributingFeaturesTotalContribution = 0;199 for(let i=0;i<instanceObjPredictionObjs.length;i++){200 featureContributionMap[instanceObjPredictionObjs[i]['name']] = Math.abs(instanceObjPredictionObjs[i]['pdep'])/totalIndividualPredictions;201 if(featureContributionMap[instanceObjPredictionObjs[i]['name']]>summarizer.instanceSummaryParams.contributionThreshold){202 highlyContributingFeatures.push(instanceObjPredictionObjs[i]['name']);203 highlyContributingFeaturesTotalContribution += featureContributionMap[instanceObjPredictionObjs[i]['name']];204 }205 }206 highlyContributingFeaturesTotalContribution = (highlyContributingFeaturesTotalContribution*100).toFixed(2);207 if(highlyContributingFeatures.length==0){208 summaryObj = {209 "highlyContributingFeatures":[],210 "highlyContributingFeaturesTotalContribution":0,211 "summarySentence":"<b>None</b> of the features individually have a notable impact on the prediction."212 }213 }else {214 summaryObj = {215 "highlyContributingFeatures":highlyContributingFeatures,216 "highlyContributingFeaturesTotalContribution":highlyContributingFeaturesTotalContribution217 };218 if(summarizer.instanceSummaryParams.summaryDetailLevel==1){219 summaryObj["summarySentence"]="<b>Some features</b> <b>have a notable impact</b> on the prediction.";220 }else if(summarizer.instanceSummaryParams.summaryDetailLevel==2){221 if(highlyContributingFeatures.length==1){222 summaryObj["summarySentence"]="<b>1 feature</b> has a notable impact and <b>individually accounts for over "+summarizer.instanceSummaryParams.contributionThreshold*100+"%</b> of the prediction.";223 }else {224 summaryObj["summarySentence"]= "<b>"+highlyContributingFeatures.length + " features</b> have a notable impact and <b>individually account for over "+summarizer.instanceSummaryParams.contributionThreshold*100+"%</b> of the prediction.";225 }226 }else if(summarizer.instanceSummaryParams.summaryDetailLevel==3){227 if(highlyContributingFeatures.length==1){228 summaryObj["summarySentence"]="<b>1 feature</b> individually has a notable impact <b>accounting for " + highlyContributingFeaturesTotalContribution + "%</b> of the prediction.";229 }else {230 summaryObj["summarySentence"]= "<b>"+highlyContributingFeatures.length + " features</b> individually have a notable impact and <b>account for a total of " + highlyContributingFeaturesTotalContribution + "%</b> of the prediction.";231 }232 }233 }234 return summaryObj;235 };236 summarizer.generateComparisonSummary = function (instanceObj1, instanceObj2, method) {237 let summaryObj;238 if(method=='quartiles'){239 }else {240 summaryObj = getComparisonSummaryUsingThresholds(instanceObj1,instanceObj2);241 }242 return summaryObj;243 };244 function getComparisonSummaryUsingThresholds(instanceObj1,instanceObj2){245 let summaryObj;246 let totalPredictionDifferenceStatus = 'MODERATE', totalPredictionRawDifference;247 let totalPredictionScale = summarizer.featureMap['totalPrediction']['scale'];248 let instanceObj1TotalPrediction = summarizer.instanceMap[instanceObj1.id]['totalPrediction'], instanceObj2TotalPrediction = summarizer.instanceMap[instanceObj2.id]['totalPrediction'];249 let totalPredictionDiff = totalPredictionScale(instanceObj1TotalPrediction) - totalPredictionScale(instanceObj2TotalPrediction);250 totalPredictionRawDifference = Math.abs(instanceObj1TotalPrediction-instanceObj2TotalPrediction);251 if(Math.abs(totalPredictionDiff)<=summarizer.comparisonParams.totalPredictionSimilarityThreshold){252 totalPredictionDifferenceStatus = 'SMALL';253 }else if(Math.abs(totalPredictionDiff)>=summarizer.comparisonParams.totalPredictionDifferenceThreshold){254 totalPredictionDifferenceStatus = 'LARGE';255 }256 let instanceObj1PredictionObjs = instanceObj1['data'], instanceObj2PredictionObjs = instanceObj2['data'];257 let featurePredictionDifferenceStatus, featurePredictionDifferenceObjs = [];258 for(let i in instanceObj1PredictionObjs){259 let instanceObj1PredictionObj = instanceObj1PredictionObjs[i];260 let instanceObj2PredictionObj = instanceObj2PredictionObjs[i];261 // console.log(instanceObj1PredictionObj['name'],instanceObj2PredictionObj['name']);262 let instanceObj1FeaturePrediction = instanceObj1PredictionObj['pdep'];263 let instanceObj2FeaturePrediction = instanceObj2PredictionObj['pdep'];264 let feature = instanceObj1PredictionObj['name'];265 if(feature!='totalPrediction'){266 let featureScale = summarizer.featureMap[feature]['scale'];267 let featurePredictionDiff = featureScale(instanceObj1FeaturePrediction) - featureScale(instanceObj2FeaturePrediction);268 if(Math.abs(featurePredictionDiff)>summarizer.comparisonParams.featurePredictionThreshold){269 featurePredictionDifferenceObjs.push({270 'name' : feature,271 'diff' : Math.abs(instanceObj1FeaturePrediction-instanceObj2FeaturePrediction),272 'diff_normalized' : Math.abs(featurePredictionDiff)273 });274 }275 }276 }277 let totalPredictionDifferenceObj = {278 'totalPredictionDifferenceStatus' : totalPredictionDifferenceStatus,279 'totalPredictionRawDifference' : totalPredictionRawDifference,280 'instance1TotalPrediction': instanceObj1TotalPrediction,281 'instance2TotalPrediction': instanceObj2TotalPrediction282 };283 let featurePredictionDifferenceObj;284 if((featurePredictionDifferenceObjs.length/(summarizer.featureCount))<summarizer.comparisonParams.featurePredictionCountThreshold){ // -1 for totalPrediction285 if(featurePredictionDifferenceObjs.length==0){286 featurePredictionDifferenceObj = {287 'featurePredictionDifferenceStatus': 'CONSISTENT_SIMILAR',288 'featurePredictionDifferenceObjs' : featurePredictionDifferenceObjs289 }290 }else {291 featurePredictionDifferenceObj = {292 'featurePredictionDifferenceStatus': 'VARIED',293 'featurePredictionDifferenceObjs' : featurePredictionDifferenceObjs294 }295 }296 summaryObj = generateComparisonSummaryObj(totalPredictionDifferenceObj,featurePredictionDifferenceObj);297 }else{298 featurePredictionDifferenceObj = {299 'featurePredictionDifferenceStatus': 'CONSISTENT_DIFFERENT',300 'featurePredictionDifferenceObjs' : featurePredictionDifferenceObjs301 };302 summaryObj = generateComparisonSummaryObj(totalPredictionDifferenceObj,featurePredictionDifferenceObj);303 }304 return summaryObj;305 }306 function generateComparisonSummaryObj(totalPredictionDifferenceObj,featurePredictionDifferenceObj){307 let totalPredictionDifferenceStatus = totalPredictionDifferenceObj['totalPredictionDifferenceStatus'];308 let totalPredictionRawDifference = totalPredictionDifferenceObj['totalPredictionRawDifference'];309 let featurePredictionDifferenceStatus = featurePredictionDifferenceObj['featurePredictionDifferenceStatus'];310 let featurePredictionDifferenceObjs = featurePredictionDifferenceObj['featurePredictionDifferenceObjs'];311 let summary;312 if(totalPredictionDifferenceStatus=='SMALL'){313 if(featurePredictionDifferenceStatus=="CONSISTENT_SIMILAR"){314 if(summarizer.comparisonParams.summaryDetailLevel==1){315 summary = "<b>Overall predictions are similar</b> with <b>all features contributing similarly</b> from both instances";316 }else if(summarizer.comparisonParams.summaryDetailLevel==2){317 summary = "<b>Overall predictions are similar</b> with <b>all " + (summarizer.featureCount) + " features contributing similarly</b> from both instances";318 }else if(summarizer.comparisonParams.summaryDetailLevel==3){319 summary = "<b>Overall predictions of "+totalPredictionDifferenceObj['instance1TotalPrediction'].toFixed(2)+" and "+totalPredictionDifferenceObj['instance2TotalPrediction'].toFixed(2)+" are similar</b> with <b>all " + (summarizer.featureCount) + " features contributing similarly</b> from both instances";320 }321 }else if(featurePredictionDifferenceStatus=="CONSISTENT_DIFFERENT"){322 if(summarizer.comparisonParams.summaryDetailLevel==1) {323 summary = "<b>Overall predictions are similar</b> but <b>most features contribute differently</b> from both instances";324 }else if(summarizer.comparisonParams.summaryDetailLevel==2){325 summary = "<b>Overall predictions are similar</b> but <b>over "+(summarizer.comparisonParams.featurePredictionCountThreshold*100).toFixed(2)+"% of the features contribute differently</b> from both instances";326 }else if(summarizer.comparisonParams.summaryDetailLevel==3){327 summary = "<b>Overall predictions of "+totalPredictionDifferenceObj['instance1TotalPrediction'].toFixed(2)+" and "+totalPredictionDifferenceObj['instance2TotalPrediction'].toFixed(2)+" are similar</b> but <b>"+featurePredictionDifferenceObj['featurePredictionDifferenceObjs'].length+" (i.e. over "+(summarizer.comparisonParams.featurePredictionCountThreshold*100).toFixed(2)+"%) features contribute differently</b> from both instances";328 }329 }else if(featurePredictionDifferenceStatus=="VARIED"){330 if(summarizer.comparisonParams.summaryDetailLevel==1) {331 summary = "<b>Overall predictions are similar</b> but <b>some features contribute differently</b> from both instances";332 }else if(summarizer.comparisonParams.summaryDetailLevel==2){333 summary = "<b>Overall predictions are similar</b> but <b>"+featurePredictionDifferenceObj['featurePredictionDifferenceObjs'].length+" features contribute differently</b> from both instances";334 }else if(summarizer.comparisonParams.summaryDetailLevel==3){335 summary = "<b>Overall predictions of "+totalPredictionDifferenceObj['instance1TotalPrediction'].toFixed(2)+" and "+totalPredictionDifferenceObj['instance2TotalPrediction'].toFixed(2)+" are similar</b> but <b>"+featurePredictionDifferenceObj['featurePredictionDifferenceObjs'].length+" features (i.e. "+((featurePredictionDifferenceObjs.length/summarizer.featureCount)*100).toFixed(2)+"%) contribute differently</b> from both instances";336 }337 }338 }else if(totalPredictionDifferenceStatus=='MODERATE'){339 if(featurePredictionDifferenceStatus=="CONSISTENT_SIMILAR"){340 if(summarizer.comparisonParams.summaryDetailLevel==1) {341 summary = "<b>Overall predictions vary</b> but <b>all features contribute similarly</b> from both instances";342 }else if(summarizer.comparisonParams.summaryDetailLevel==2){343 summary = "<b>Overall predictions vary</b> but <b>all "+summarizer.featureCount+" features contribute similarly</b> from both instances";344 }else if(summarizer.comparisonParams.summaryDetailLevel==3){345 summary = "<b>Overall predictions of "+totalPredictionDifferenceObj['instance1TotalPrediction'].toFixed(2)+" and "+totalPredictionDifferenceObj['instance2TotalPrediction'].toFixed(2)+" vary</b> but <b>all "+summarizer.featureCount+" features contribute similarly</b> from both instances";346 }347 }else if(featurePredictionDifferenceStatus=="CONSISTENT_DIFFERENT"){348 if(summarizer.comparisonParams.summaryDetailLevel==1) {349 summary = "<b>Overall predictions vary</b> and <b>most features contribute differently</b> from both instances";350 }else if(summarizer.comparisonParams.summaryDetailLevel==2){351 summary = "<b>Overall predictions vary</b> and <b>"+featurePredictionDifferenceObj['featurePredictionDifferenceObjs'].length+" features contribute differently</b> from both instances";352 }else if(summarizer.comparisonParams.summaryDetailLevel==3){353 summary = "<b>Overall predictions of "+totalPredictionDifferenceObj['instance1TotalPrediction'].toFixed(2)+" and "+totalPredictionDifferenceObj['instance2TotalPrediction'].toFixed(2)+" vary</b> and <b>"+featurePredictionDifferenceObj['featurePredictionDifferenceObjs'].length+" features (i.e. over "+(summarizer.comparisonParams.featurePredictionCountThreshold*100).toFixed(2)+"%) contribute differently</b> from both instances";354 }355 }else if(featurePredictionDifferenceStatus=="VARIED"){356 if(summarizer.comparisonParams.summaryDetailLevel==1) {357 summary = "<b>Overall predictions vary</b> potentially due to <b>some features contributing differently</b> from both instances";358 }else if(summarizer.comparisonParams.summaryDetailLevel==2){359 summary = "<b>Overall predictions vary</b> potentially due to <b>"+featurePredictionDifferenceObj['featurePredictionDifferenceObjs'].length+" features contributing differently</b> from both instances";360 }else if(summarizer.comparisonParams.summaryDetailLevel==3){361 summary = "<b>Overall predictions of "+totalPredictionDifferenceObj['instance1TotalPrediction'].toFixed(2)+" and "+totalPredictionDifferenceObj['instance2TotalPrediction'].toFixed(2)+" vary</b> potentially due to <b>"+featurePredictionDifferenceObj['featurePredictionDifferenceObjs'].length+" features (i.e. "+((featurePredictionDifferenceObj['featurePredictionDifferenceObjs'].length/summarizer.featureCount)*100).toFixed(2)+"%) contributing differently</b> from both instances";362 }363 }364 }else if(totalPredictionDifferenceStatus=='LARGE'){365 if(featurePredictionDifferenceStatus=="CONSISTENT_SIMILAR"){366 if(summarizer.comparisonParams.summaryDetailLevel==1) {367 summary = "<b>Overall predictions are very different</b> but <b>all features contribute similarly</b> from both instances";368 }else if(summarizer.comparisonParams.summaryDetailLevel==2){369 summary = "<b>Overall predictions are very different</b> but <b>all "+summarizer.featureCount+" features contribute similarly</b> from both instances";370 }else if(summarizer.comparisonParams.summaryDetailLevel==3){371 summary = "<b>Overall predictions of "+totalPredictionDifferenceObj['instance1TotalPrediction'].toFixed(2)+" and "+totalPredictionDifferenceObj['instance2TotalPrediction'].toFixed(2)+" are very different</b> but <b>all "+summarizer.featureCount+" features contribute similarly</b> from both instances";372 }373 }else if(featurePredictionDifferenceStatus=="CONSISTENT_DIFFERENT"){374 if(summarizer.comparisonParams.summaryDetailLevel==1) {375 summary = "<b>Overall predictions are very different</b> with <b>most features contributing differently</b> from both instances";376 }else if(summarizer.comparisonParams.summaryDetailLevel==2){377 summary = "<b>Overall predictions are very different</b> with <b>"+featurePredictionDifferenceObj['featurePredictionDifferenceObjs'].length+" features contributing differently</b> from both instances";378 }else if(summarizer.comparisonParams.summaryDetailLevel==3){379 summary = "<b>Overall predictions of "+totalPredictionDifferenceObj['instance1TotalPrediction'].toFixed(2)+" and "+totalPredictionDifferenceObj['instance2TotalPrediction'].toFixed(2)+" are very different</b> with <b>"+featurePredictionDifferenceObj['featurePredictionDifferenceObjs'].length+" features (i.e. over "+(summarizer.comparisonParams.featurePredictionCountThreshold*100).toFixed(2)+"%) contributing differently</b> from both instances";380 }381 }else if(featurePredictionDifferenceStatus=="VARIED"){382 if(summarizer.comparisonParams.summaryDetailLevel==1) {383 summary = "<b>Overall predictions are very different</b> potentially due to <b>some features that contribute differently</b> from both instances";384 }else if(summarizer.comparisonParams.summaryDetailLevel==2){385 summary = "<b>Overall predictions are very different</b> potentially due to the <b>"+featurePredictionDifferenceObj['featurePredictionDifferenceObjs'].length+" features that contribute differently</b> from both instances";386 }else if(summarizer.comparisonParams.summaryDetailLevel==3){387 summary = "<b>Overall predictions of "+totalPredictionDifferenceObj['instance1TotalPrediction'].toFixed(2)+" and "+totalPredictionDifferenceObj['instance2TotalPrediction'].toFixed(2)+" are very different</b> potentially due to the <b>"+featurePredictionDifferenceObj['featurePredictionDifferenceObjs'].length+" features (i.e. "+((featurePredictionDifferenceObj['featurePredictionDifferenceObjs'].length/summarizer.featureCount)*100)+"%) that contribute differently</b> from both instances";388 }389 }390 }391 let summaryObj = {392 "totalPredictionDifferenceStatus" : totalPredictionDifferenceStatus,393 "totalPredictionRawDifference" : totalPredictionRawDifference,394 "featurePredictionDifferenceStatus" : featurePredictionDifferenceStatus,395 "featurePredictionDifferenceObjs" : featurePredictionDifferenceObjs,396 "summarySentence" : summary397 };398 return summaryObj;399 }...
analyze.ts
Source:analyze.ts
...131 return tables;132 }, <GroupedTables>{});133 return generateMarkdownFromGroupedTables(grouped);134}135export function generateComparisonSummary(result: BenchmarkComparison, threshold: number) {136 return generateCommentWithTables(result, (node, base, target) => {137 const changes = significantlyChangedRows(node, threshold);138 const tables: MarkdownTable[] = [];139 140 if (changes.improved.length) {141 tables.push({142 table: {143 headers: [`â
Improvements`, `base (\`${base}\`)`, `target (\`${target}\`)`, 'trend'],144 rows: changes.improved145 }146 })147 }148 if (changes.regressed.length) {149 tables.push({...
index.ts
Source:index.ts
...76}77export async function completeBenchmarkComparisonCheck(gitHubInstallation: Octokit, check: Octokit.ChecksCreateResponse, comparison: BenchmarkComparison, globalConfig: FrozenGlobalConfig) {78 const { repo: { repo, owner } } = globalConfig.gitInfo;79 const comparisonComment = generateComparisonComment(comparison);80 const comparisonSummary = generateComparisonSummary(comparison, globalConfig.commentThreshold);81 const now = (new Date()).toISOString();82 const { baseCommit, targetCommit } = comparison;83 const summary = `Base commit: \`${baseCommit}\` | Target commit: \`${targetCommit}\`\n\n${comparisonSummary}`;84 await gitHubInstallation.checks.update({85 owner,86 repo,87 check_run_id: check.id,88 completed_at: now,89 conclusion: 'success',90 output: {91 title: 'Best Summary',92 summary,93 text: comparisonComment94 }...
Using AI Code Generation
1var BestPractices = require('./BestPractices.js');2var bestPractices = new BestPractices();3var comparisonSummary = bestPractices.generateComparisonSummary();4console.log(comparisonSummary);5var BestPractices = function() {6 this.generateComparisonSummary = function() {7 return "This is a comparison summary";8 }9}10module.exports = BestPractices;
Using AI Code Generation
1var BestPractices = require('./BestPractices.js');2var bestPractices = new BestPractices();3var comparisonSummary = bestPractices.generateComparisonSummary();4console.log(comparisonSummary);5var BestPractices = function() {6 this.generateComparisonSummary = function() {7 return "This is a comparison summary";8 }9}10module.exports = BestPractices;
Using AI Code Generation
1var bestBuyComparison = new BestBuyComparison();2var comparisonSummary = bestBuyComparison.generateComparisonSummary();3console.log("Comparison Summary: " + comparisonSummary);4var bestBuyComparison = new BestBuyComparison();5var comparisonSummary = bestBuyComparison.generateComparisonSummary();6console.log("Comparison Summary: " + comparisonSummary);7var bestBuyComparison = new BestBuyComparison();8var comparisonSummary = bestBuyComparison.generateComparisonSummary();9console.log("Comparison Summary: " + comparisonSummary);10var bestBuyComparison = new BestBuyComparison();11var comparisonSummary = bestBuyComparison.generateComparisonSummary();12console.log("Comparison Summary: " + comparisonSummary);13var bestBuyComparison = new BestBuyComparison();14var comparisonSummary = bestBuyComparison.generateComparisonSummary();15console.log("Comparison Summary: " + comparisonSummary);16var bestBuyComparison = new BestBuyComparison();17var comparisonSummary = bestBuyComparison.generateComparisonSummary();18console.log("Comparison Summary: " + comparisonSummary);19var bestBuyComparison = new BestBuyComparison();20var comparisonSummary = bestBuyComparison.generateComparisonSummary();21console.log("Comparison Summary: " + comparisonSummary);22var bestBuyComparison = new BestBuyComparison();23var comparisonSummary = bestBuyComparison.generateComparisonSummary();24console.log("Comparison Summary: " + comparisonSummary);25var bestBuyComparison = new BestBuyComparison();26var comparisonSummary = bestBuyComparison.generateComparisonSummary();27console.log("Comparison Summary: " + comparisonSummary);28var bestBuyComparison = new BestBuyComparison();
Using AI Code Generation
1var bestBuyComparison = require('./bestBuyComparison.js');2var bestBuyComparisonObj = new bestBuyComparison();3var productComparisonSummary = bestBuyComparisonObj.generateComparisonSummary('product1','product2','product3','product4','product5');4console.log(productComparisonSummary);5var BestBuyComparison = function () {6 this.generateComparisonSummary = function (product1, product2, product3, product4, product5) {7 var product1 = product1 || 'product1';8 var product2 = product2 || 'product2';9 var product3 = product3 || 'product3';10 var product4 = product4 || 'product4';11 var product5 = product5 || 'product5';12 var comparisonSummary = 'The best product is ' + product1 + ' followed by ' + product2 + ' and ' + product3 + ' and ' + product4 + ' and ' + product5;13 return comparisonSummary;14 };15};16module.exports = BestBuyComparison;
Using AI Code Generation
1var BestBuy = require('./BestBuy.js');2var bestBuy = new BestBuy();3var result = bestBuy.generateComparisonSummary('Guitar', 'Acoustic Guitar');4console.log(result);5var BestBuy = require('./BestBuy.js');6var bestBuy = new BestBuy();7var result = bestBuy.generateComparisonSummary('Guitar', 'Acoustic Guitar');8console.log(result);9var BestBuy = require('./BestBuy.js');10var bestBuy = new BestBuy();11var result = bestBuy.generateComparisonSummary('Guitar', 'Acoustic Guitar');12console.log(result);13var BestBuy = require('./BestBuy.js');14var bestBuy = new BestBuy();15var result = bestBuy.generateComparisonSummary('Guitar', 'Acoustic Guitar');16console.log(result);17var BestBuy = require('./BestBuy.js');18var bestBuy = new BestBuy();19var result = bestBuy.generateComparisonSummary('Guitar', 'Acoustic Guitar');20console.log(result);21var BestBuy = require('./BestBuy.js');22var bestBuy = new BestBuy();23var result = bestBuy.generateComparisonSummary('Guitar', 'Acoustic Guitar');24console.log(result);25var BestBuy = require('./BestBuy.js');26var bestBuy = new BestBuy();27var result = bestBuy.generateComparisonSummary('Guitar', 'Acoustic Guitar');28console.log(result);e
Using AI Code Generation
1var bestMatchFinder = require('./bestMatchFinder.js');2var data = require('./data.js');3var reference = require('./reference.js');4var bestMatchFinder = new bestMatchFinder.BestMatchFinder();5var summary = bestMatchFinder.generateComparisonSummary(data, reference, 'name');6console.log(summary);7var fs = require('fs');8var stream = fs.createWriteStream("test4_output.txt");9stream.once('open', function(fd) {10 stream.write(summary);11 stream.end();12});13var bestMatchFinder = require('./bestMatchFinder.js');14var data = require('./data.js');15var reference = require('./reference.js');16var bestMatchFinder = new bestMatchFinder.BestMatchFinder();17var summary = bestMatchFinder.generateComparisonSummary(data, reference, 'name', 0.7);18console.log(summary);19var fs = require('fs');20var stream = fs.createWriteStream("test5_output.txt");21stream.once('open', function(fd) {22 stream.write(summary);23 stream.end();24});25var bestMatchFinder = require('./bestMatchFinder.js');26var data = require('./data.js');27var reference = require('./reference.js');28var BestBuy = require('./BestBuy.js');29var bestBuy = new BestBuy();30var result = bestBuy.generateComparisonSummary('Guitar', 'Acoustic Guitar');31console.log(result);32var BestBuy = require('./BestBuy.js');33var bestBuy = new BestBuy();
Using AI Code Generation
1var bestMatchFinder = require('./bestMatchFinder.js');2var data = require('./data.js');3var reference = require('./reference.js');4var bestMatchFinder = new bestMatchFinder.BestMatchFinder();5var summary = bestMatchFinder.generateComparisonSummary(data, reference, 'name');6console.log(summary);7var fs = require('fs');8var stream = fs.createWriteStream("test4_output.txt");9stream.once('open', function(fd) {10 stream.write(summary);11 stream.end();12});13var bestMatchFinder = require('./bestMatchFinder.js');14var data = require('./data.js');15var reference = require('./reference.js');16var bestMatchFinder = new bestMatchFinder.BestMatchFinder();17var summary = bestMatchFinder.generateComparisonSummary(data, reference, 'name', 0.7);18console.log(summary);19var fs = require('fs');20var stream = fs.createWriteStream("test5_output.txt");21stream.once('open', function(fd) {22 stream.write(summary);23 stream.end();24});25var bestMatchFinder = require('./bestMatchFinder.js');26var data = require('./data.js');27var reference = require('./reference.js');
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!