How to use traceTestList method in tracetest

Best JavaScript code snippet using tracetest

plotCreation.js

Source:plotCreation.js Github

copy

Full Screen

1import {PlotlyPlot, PlotlyTrace} from "./PlotlyPlot";2import {BestConfigPlot, BestConfigTrace} from "./BestConfigPlot";3import ConfusionMatrix from "ml-confusion-matrix";4export { createPlot, plotFoldComparisonData, PlotTypes, plotPerformance, plotBestConfigConfusion, plotOptimizerHistory };5// Enumeration containing plot types for use in 'createPlot' function6const PlotTypes = Object.freeze({7 showPipeline: 1,8 showOuterFold: 2,9 testedConfig: 4,10 innerFoldConfig: 511});12const ColorList = ['#1F77B4', '#FF7F0E', '#2CA02C', '#D62728', '#9467BD', '#8C564B',13 '#E377C2', '#7F7F7F', '#BCBD22', '#17BECF']14/**15 * This function interfaces with the Plot component to update data and layout variables. TODO rethink need for this function. Seems to be a lot of logic for little reward16 * @param {Object} file Pipeline file needed for processing.17 * @param {Int} config Config controlling plot generation. For details see 'Readme.md' in src/preprocessing.18 * @returns {Object} An object of various plots and other data. Check the return documentation of the individual plot* functions for more details.19 */20function createPlot(file, config) {21 switch (config.type) {22 case PlotTypes.showPipeline: //////////////////////////////////////////////////////////////////23 return plotShowPipeline(file);24 case PlotTypes.showOuterFold: //////////////////////////////////////////////////////////////////25 if (!Object.prototype.hasOwnProperty.call(config,"foldNo")) {26 alert(27 'Plottypes.showOuterFold was requested, but needed argument "foldNo" was not supplied!'28 );29 window.console.log("createPlot-showOuterFold: foldNo not found");30 return {};31 }32 return plotShowOuterFolds(file, config.foldNo);33 case PlotTypes.testedConfig: //////////////////////////////////////////////////////////////////34 if (35 !Object.prototype.hasOwnProperty.call(config,"foldNo") ||36 !Object.prototype.hasOwnProperty.call(config,"innerFoldNo") ||37 !Object.prototype.hasOwnProperty.call(config,"configIndex")38 ) {39 alert(40 "Plottypes.testedConfig was requested, but some of the needed arguments are missing. Required: foldNo, innerFoldNo, configIndex"41 );42 window.console.log(43 "Plottypes.testedConfig was requested, but some of the needed arguments are missing. Required: foldNo, innerFoldNo, configIndex"44 );45 return {};46 }47 return plotShowTestedConfig(48 file,49 config.foldNo,50 config.innerFoldNo,51 config.configIndex52 );53 default:54 //////////////////////////////////////////////////////////////////55 alert(56 `Error in plotCreation.js::createPlot - Given config is unknown and default was triggered: ${config}`57 );58 }59}60/**61 * Plotting function generating all data needed for plots in PerformancePlots component.62 * @param {Object} file Pipeline file needed for processing.63 * @return {Object} Object containing metric names as keys and plot data as values64 */65function plotPerformance(file) { // TODO integrate into createPlot function? Consider removing that system66 let outputData = {}; // result data67 // extract metrics from dummy_results for iteration68 (file.hyperpipe_info.metrics).forEach(metricName => {69 // Create empty plot70 outputData[metricName] = new PlotlyPlot(metricName, [], false);71 let shapes = []; // array containing all shape objects representing horizontal dummy result data72 let meanValues = {73 training: [],74 validation: []75 }; // object storing values for mean trace calculation in keys: training, validation76 // add dummy result77 // Extracts .MEAN value from metric list78 let dummyValueExtractor = (metric) => file.dummy_estimator.metrics_train79 .filter((metricObject) => metricObject.metric_name === metric && metricObject.operation.endsWith("mean"))80 .map((metricObject) => metricObject.value)[0];81 let dummyResult = dummyValueExtractor(metricName);82 shapes.push({83 type: "line",84 xref: "paper",85 x0: 0,86 y0: dummyResult,87 x1: 1,88 y1: dummyResult,89 line: {90 color: "#0e0e1d",91 width: 292 }93 })94 // add dummy result shapes to plot95 outputData[metricName].addStyle("shapes", shapes);96 // iterate over folds97 file.outer_folds.forEach(fold => {98 let foldIndex = fold.fold_nr;99 // get fold data100 let foldTrain = fold.best_config.best_config_score.training.metrics[metricName];101 let foldValidation = fold.best_config.best_config_score.validation.metrics[metricName];102 meanValues["training"].push(foldTrain);103 meanValues["validation"].push(foldValidation);104 let trainingTrace = new PlotlyTrace(`Fold ${foldIndex}`, undefined, undefined, undefined, "#666");105 let validationTrace = new PlotlyTrace(`Fold ${foldIndex}`, undefined, undefined, undefined, "#666");106 trainingTrace.x.push("Training");107 trainingTrace.y.push(foldTrain);108 validationTrace.x.push("Validation");109 validationTrace.y.push(foldValidation);110 outputData[metricName].traces.push(trainingTrace, validationTrace);111 })112 // calculate mean values for bar trace113 let meanTrainingTrace = new PlotlyTrace("Mean training", undefined, "bar", undefined, "#2388fe");114 let meanValidationTrace = new PlotlyTrace("Mean validation", undefined, "bar", undefined, "#231c44");115 let average = (array) => array.reduce((a, b) => a + b) / array.length;116 meanTrainingTrace.x.push("Training");117 meanTrainingTrace.y.push(average(meanValues.training))118 meanValidationTrace.x.push("Validation");119 meanValidationTrace.y.push(average(meanValues.validation))120 outputData[metricName].traces.push(meanTrainingTrace, meanValidationTrace);121 })122 return outputData;123}124/**125 * Plotting function for the general overview plot as seen in hyperpipe.py126 * @param {Object} file Object containing all needed information.127 * @returns An object of plots: One overview plot (overview) and a config plot for each fold (best plot each; bestConfigs)128 */129function plotShowPipeline(file) {130 let defaultBestConfigFold = 0;131 let trainingMetrics = {};132 let testingMetrics = {};133 let bestConfigPlots = [];134 let overviewPlotTraining = new PlotlyPlot("Training", [], false);135 let overviewPlotTesting = new PlotlyPlot('Testing', [], false);136 file.outer_folds.forEach(fold => {137 // MAIN OVERVIEW PLOT TRACES138 let overviewPlotTrainingTrace = new PlotlyTrace(139 `Fold ${fold.fold_nr}`,140 ...Array(3).fill(undefined),141 "rgb(91,91,91)"142 );143 let overviewPlotTestingTrace = new PlotlyTrace(144 `Fold ${fold.fold_nr}`,145 ...Array(3).fill(undefined),146 "rgb(91,91,91)"147 );148 for (const [key, value] of Object.entries(149 fold.best_config.inner_folds[defaultBestConfigFold].training.metrics150 )) {151 overviewPlotTrainingTrace.x.push(key);152 overviewPlotTrainingTrace.y.push(value);153 trainingMetrics[key] = value;154 }155 for (const [key, value] of Object.entries(156 fold.best_config.inner_folds[defaultBestConfigFold].validation.metrics157 )) {158 overviewPlotTestingTrace.x.push(key);159 overviewPlotTestingTrace.y.push(value);160 testingMetrics[key] = value;161 }162 overviewPlotTraining.traces.push(overviewPlotTrainingTrace);163 overviewPlotTesting.traces.push(overviewPlotTestingTrace);164 let metricTrainingTrace = new BestConfigTrace(165 "Training",166 Object.entries(trainingMetrics).map(([key, value]) => ({ key, value })),167 "",168 "bar"169 );170 let metricTestingTrace = new BestConfigTrace(171 "Testing",172 Object.entries(testingMetrics).map(([key, value]) => ({ key, value })),173 "",174 "bar"175 );176 let bestConfigPlot = new BestConfigPlot(177 "bestConfigOverviewINTERNAL",178 `Best Configuration Overview - Fold ${fold.fold_nr}`,179 metricTrainingTrace,180 metricTestingTrace181 );182 bestConfigPlots.push(bestConfigPlot);183 });184 // Start calculating mean values grouped by metrics and training or validation set185 let trainingMeanTrace = new PlotlyTrace(186 "mean_training",187 undefined,188 'bar',189 8,190 "rgb(214, 123, 25)",191 undefined192 );193 let testingMeanTrace = new PlotlyTrace(194 "mean_testing",195 undefined,196 'bar',197 8,198 "rgb(214, 123, 25)",199 undefined200 );201 let temp = {};202 let count = {};203 // training204 for (let [key, value] of Object.entries(trainingMetrics)) {205 // two loops used in python code... check for correctness206 temp[key] = parseFloat(value);207 count[key] = 1;208 }209 for (let [key, value] of Object.entries(temp)) {210 trainingMeanTrace.x.push(key);211 trainingMeanTrace.y.push(value / count[key]);212 }213 // clear temps214 temp = {};215 count = {};216 // testing217 for (let [key, value] of Object.entries(testingMetrics)) {218 // two loops used in python code... check for correctness219 temp[key] = parseFloat(value);220 count[key] = 1;221 }222 for (let [key, value] of Object.entries(temp)) {223 testingMeanTrace.x.push(key);224 testingMeanTrace.y.push(value / count[key]);225 }226 overviewPlotTraining.traces.push(trainingMeanTrace);227 overviewPlotTesting.traces.push(testingMeanTrace);228 // return overviewplot and best config plots229 return { overview: [overviewPlotTraining, overviewPlotTesting], bestConfigs: bestConfigPlots };230}231/**232 * Plotting function for all plots as seen in Outer_fold.py233 * @param {Object} file Object containing all needed information.234 * @param {Int} foldNo Fold number to be further inspected (1 based).235 * @returns An object with the following attributes: outerFold (copy of raw fold), errorPlots, bestConfigPlot, finalValueTrainingPlot, finalValueValidationPlot, configDicts (objects containing used config)236 */237function plotShowOuterFolds(file, foldNo) {238 // best config object always has just one fold239 let defaultFoldBestConfig = 0;240 let configDictList = [];241 let errorPlotList = [];242 let metricTrainingList = {};243 let metricValidationList = {};244 let outerFold = file.outer_folds[foldNo - 1];245 // save training metrics in list246 for (const [key, value] of Object.entries(247 outerFold.best_config.inner_folds[defaultFoldBestConfig].training.metrics248 )) {249 metricTrainingList[key] = value;250 }251 // save validation metrics in list252 for (const [key, value] of Object.entries(253 outerFold.best_config.inner_folds[defaultFoldBestConfig].validation.metrics254 )) {255 metricValidationList[key] = value;256 }257 // building traces from lists258 let metricTrainingTrace = new BestConfigTrace(259 "Training",260 Object.entries(metricTrainingList).map(([key, value]) => ({ key, value })),261 "",262 "bar"263 );264 let metricValidationTrace = new BestConfigTrace(265 "Validation",266 Object.entries(metricValidationList).map(([key, value]) => ({267 key,268 value269 })),270 "",271 "bar"272 );273 // building plot from traces274 let bestConfigPlot = new BestConfigPlot(275 "bestConfigOverview",276 "Best Configuration Overview",277 metricTrainingTrace,278 metricValidationTrace279 );280 // START building final values for training set (best config)281 let trueTrainingTrace = new PlotlyTrace("y_true");282 let predTrainingTrace = new PlotlyTrace("y_pred");283 // TRAINING basically a complex fori loop I guess284 for (const [index, value] of outerFold.best_config.inner_folds[285 defaultFoldBestConfig286 ].training.y_true.entries()) {287 trueTrainingTrace.x.push(index);288 trueTrainingTrace.y.push(value);289 }290 // PREDICTION291 for (const [index, value] of outerFold.best_config.inner_folds[292 defaultFoldBestConfig293 ].training.y_pred.entries()) {294 predTrainingTrace.x.push(index);295 predTrainingTrace.y.push(value);296 }297 // put it all together298 let finalValueTrainingPlot = new PlotlyPlot("True/Predict for training set", [299 trueTrainingTrace,300 predTrainingTrace301 ]);302 // END building final values for training set (best config)303 // START building final values for validation set (best config)304 let trueValidationTrace = new PlotlyTrace("y_true");305 let predValidationTrace = new PlotlyTrace("y_pred");306 // TRAINING307 for (const [index, value] of outerFold.best_config.inner_folds[308 defaultFoldBestConfig309 ].validation.y_true.entries()) {310 trueValidationTrace.x.push(index);311 trueValidationTrace.y.push(value);312 }313 // PREDICTION314 for (const [index, value] of outerFold.best_config.inner_folds[315 defaultFoldBestConfig316 ].validation.y_pred.entries()) {317 predValidationTrace.x.push(index);318 predValidationTrace.y.push(value);319 }320 // put it all together321 let finalValueValidationPlot = new PlotlyPlot(322 "True/Predict for validation set",323 [trueValidationTrace, predValidationTrace]324 );325 // END building final values for validation set (best config)326 // START building plot objects for each tested config327 outerFold.tested_config_list.forEach(config => {328 let configDict = {329 investigatorName: `config_${config.config_nr}`,330 investigatorID: config.config_nr331 };332 let errorPlotTrain = new PlotlyPlot(333 `Train Error Plot ${config.config_nr}`,334 [],335 false336 );337 let errorPlotTest = new PlotlyPlot(338 `Test Error Plot ${config.config_nr}`,339 [],340 false341 );342 config.inner_folds.forEach(innerFold => {343 let traceTrainingMetrics = new PlotlyTrace(344 `training_fold_${innerFold.fold_nr}`,345 undefined,346 undefined,347 undefined,348 "rgb(91, 91, 91)"349 );350 let traceTestMetrics = new PlotlyTrace(351 `test_fold_${innerFold.fold_nr}`,352 undefined,353 undefined,354 undefined,355 "rgb(91, 91, 91)"356 );357 for (const [key, value] of Object.entries(innerFold.training.metrics)) {358 traceTrainingMetrics.x.push(key);359 traceTrainingMetrics.y.push(value);360 }361 for (const [key, value] of Object.entries(innerFold.validation.metrics)) {362 traceTestMetrics.x.push(key);363 traceTestMetrics.y.push(value);364 }365 errorPlotTrain.traces.push(traceTrainingMetrics);366 errorPlotTest.traces.push(traceTestMetrics);367 });368 let traceTraining = new PlotlyTrace(369 `training_mean_${config.config_nr}`,370 undefined,371 undefined,372 8,373 undefined,374 true375 );376 let traceTest = new PlotlyTrace(377 `test_mean_${config.config_nr}`,378 undefined,379 undefined,380 8,381 undefined,382 true383 );384 config.metrics_train.forEach(train => {385 if (train.operation == "FoldOperations.MEAN") {386 traceTraining.x.push(train.metric_name);387 traceTraining.y.push(train.value);388 } else if (train.operation == "FoldOperations.STD") {389 traceTraining.error.push(train.value);390 }391 });392 config.metrics_test.forEach(test => {393 if (test.operation == "FoldOperations.MEAN") {394 traceTest.x.push(test.metric_name);395 traceTest.y.push(test.value);396 } else if (test.operation == "FoldOperations.STD") {397 traceTest.error.push(test.value);398 }399 });400 errorPlotTrain.traces.push(traceTraining);401 errorPlotTest.traces.push(traceTest);402 errorPlotList.push(errorPlotTrain, errorPlotTest);403 // convert config values to string for later display404 for (const [key, value] of Object.entries(config.config_dict)) {405 configDict[key] = String(value);406 }407 configDictList.push(configDict);408 });409 // END building plot objects for each tested config410 return {411 outerFold: outerFold,412 errorPlots: errorPlotList,413 bestConfigPlot: bestConfigPlot,414 finalValueTrainingPlot: finalValueTrainingPlot,415 finalValueValidationPlot: finalValueValidationPlot,416 configDicts: configDictList,417 allInclusive: [418 ...errorPlotList,419 bestConfigPlot,420 finalValueTrainingPlot,421 finalValueValidationPlot422 ]423 };424}425/**426 * Plotting function for all plots as seen in ajax.py::load_tested_config_for_inner_fold.427 * @param {Object} file Object containing all needed information.428 * @param {Int} foldNo Outer fold number to be further inspected (1 based).429 * @param {Int} innerFoldNo Inner fold number to be further inspected (1 based).430 * @param {Int} configIndex Index of config to be further inspected (0 based).431 * @returns An object with the following attributes:432 */433function plotShowTestedConfig(file, foldNo, innerFoldNo, configIndex) {434 let outerFoldNo = foldNo;435 let innerFold =436 file.outer_folds[outerFoldNo].tested_config_list[configIndex].inner_folds[437 innerFoldNo438 ];439 // Training plot440 let traceTrainingPrediction = new PlotlyTrace("Prediction", undefined, "");441 traceTrainingPrediction.x = [442 ...Array(innerFold.training.y_pred.length).keys()443 ].map(k => k + 1);444 traceTrainingPrediction.y = innerFold.training.y_pred;445 let traceTrainingTrue = new PlotlyTrace("True", undefined, "");446 traceTrainingTrue.x = [...Array(innerFold.training.y_true.length).keys()].map(447 k => k + 1448 );449 traceTrainingTrue.y = innerFold.training.y_true;450 // Validation plot451 let traceValidationPrediction = new PlotlyTrace("Prediction", undefined, "");452 traceValidationPrediction.x = [453 ...Array(innerFold.validation.y_pred.length).keys()454 ].map(k => k + 1);455 traceValidationPrediction.y = innerFold.validation.y_pred;456 let traceValidationTrue = new PlotlyTrace("True", undefined, "");457 traceValidationTrue.x = [458 ...Array(innerFold.validation.y_true.length).keys()459 ].map(k => k + 1);460 traceValidationTrue.y = innerFold.validation.y_true;461 return {462 training: new PlotlyPlot("True/Predict for training set", [463 traceTrainingPrediction,464 traceTrainingTrue465 ]),466 validation: new PlotlyPlot("True/Predict for validation set", [467 traceValidationPrediction,468 traceValidationTrue469 ])470 };471}472/**473 * Plotting function for all plots as seen in ajax.py::load_inner_fold_data_for_config.474 * @param {Object} file Object containing all needed information.475 * @param {Int} foldNo Outer fold number to be further inspected (1 based).476 * @param {Int} innerFoldNo Inner fold number to be further inspected (1 based).477 * @param {Int} configIndex Index of config to be further inspected (0 based).478 * @returns An object with the following structure: {folds: [{training, validation}, ...]}479 */480function plotShowInnerFoldConfig(file, foldNo, configIndex) {481 let outerFoldIndex = foldNo - 1;482 let foldPlots = [];483 file.outer_folds[outerFoldIndex].tested_config_list[484 configIndex485 ].inner_folds.forEach(innerFold => {486 // Training plot487 let traceTrainingPrediction = new PlotlyTrace("Prediction", undefined, "");488 traceTrainingPrediction.x = [489 ...Array(innerFold.training.y_pred.length).keys()490 ].map(k => k + 1);491 traceTrainingPrediction.y = innerFold.training.y_pred;492 let traceTrainingTrue = new PlotlyTrace("True", undefined, "");493 traceTrainingTrue.x = [494 ...Array(innerFold.training.y_true.length).keys()495 ].map(k => k + 1);496 traceTrainingTrue.y = innerFold.training.y_true;497 // Validation plot498 let traceValidationPrediction = new PlotlyTrace(499 "Prediction",500 undefined,501 ""502 );503 traceValidationPrediction.x = [504 ...Array(innerFold.validation.y_pred.length).keys()505 ].map(k => k + 1);506 traceValidationPrediction.y = innerFold.validation.y_pred;507 let traceValidationTrue = new PlotlyTrace("True", undefined, "");508 traceValidationTrue.x = [509 ...Array(innerFold.validation.y_true.length).keys()510 ].map(k => k + 1);511 traceValidationTrue.y = innerFold.validation.y_true;512 foldPlots.push({513 training: new PlotlyPlot("True/Predict for training set", [514 traceTrainingPrediction,515 traceTrainingTrue516 ]),517 validation: new PlotlyPlot("True/Predict for validation set", [518 traceValidationPrediction,519 traceValidationTrue520 ])521 });522 });523 return {folds: foldPlots}524}525/**526 * Function generates all data needed for tested config comparison.527 * Due to its abnormal parametrisation in comparison to the other plot* functions it is not accessed through the createPlot interface.528 * @param {Object} file Object containing all needed information.529 * @param {Int} foldNo Outer fold number to be further inspected (1 based).530 * @param {Array} toCompare Array of tested config indices to compare (0 based).531 * @returns An object with the following attributes: outerFold (Raw obj), plotTraining (PlotlyPlot), plotTest(PlotlyPlot), configDictList (Array)532 */533function plotFoldComparisonData(file, foldNo, toCompare) {534 let configDictList = [];535 let configList = [];536 let traceTrainingList = [];537 let traceTestList = [];538 let outerFold = file.outer_folds[foldNo - 1];539 outerFold.tested_config_list.forEach(config => {540 if (toCompare.includes(config.config_nr)) {541 let configDict = { configName: `config_${config.config_nr}` };542 configList.push(config);543 let traceTraining = new PlotlyTrace(544 `config_${config.config_nr}`,545 "",546 "bar"547 );548 let traceTest = new PlotlyTrace(`config_${config.config_nr}`, "", "bar");549 config.metrics_train.forEach(train => {550 if (train.operation == "FoldOperations.MEAN") {551 traceTraining.x.push(String(train.metric_name));552 traceTraining.y.push(train.value);553 }554 });555 config.metrics_test.forEach(test => {556 if (test.operation == "FoldOperations.MEAN") {557 traceTraining.x.push(String(test.metric_name));558 traceTraining.y.push(test.value);559 }560 });561 traceTrainingList.push(traceTraining);562 traceTestList.push(traceTest);563 configDict = { ...configDict, ...config.config_dict };564 configDictList.push(configDict);565 }566 });567 let plotTraining = new PlotlyPlot(568 "Train metrics of selected configurations",569 traceTrainingList570 );571 let plotTest = new PlotlyPlot(572 "Test metrics of selected configurations",573 traceTestList574 );575 return { outerFold, plotTraining, plotTest, configDictList };576}577const pSBC=(p,c0,c1,l)=>{578 let r,g,b,P,f,t,h,i=parseInt,m=Math.round,a=typeof(c1)=="string";579 if(typeof(p)!="number"||p<-1||p>1||typeof(c0)!="string"||(c0[0]!='r'&&c0[0]!='#')||(c1&&!a))return null;580 let pSBCr=(d)=>{581 let n=d.length,x={};582 if(n>9){583 [r,g,b,a]=d=d.split(","),n=d.length;584 if(n<3||n>4)return null;585 x.r=i(r[3]=="a"?r.slice(5):r.slice(4)),x.g=i(g),x.b=i(b),x.a=a?parseFloat(a):-1586 }else{587 if(n==8||n==6||n<4)return null;588 if(n<6)d="#"+d[1]+d[1]+d[2]+d[2]+d[3]+d[3]+(n>4?d[4]+d[4]:"");589 d=i(d.slice(1),16);590 if(n==9||n==5)x.r=d>>24&255,x.g=d>>16&255,x.b=d>>8&255,x.a=m((d&255)/0.255)/1000;591 else x.r=d>>16,x.g=d>>8&255,x.b=d&255,x.a=-1592 }return x};593 h=c0.length>9,h=a?c1.length>9?true:c1=="c"?!h:false:h,f=pSBCr(c0),P=p<0,t=c1&&c1!="c"?pSBCr(c1):P?{r:0,g:0,b:0,a:-1}:{r:255,g:255,b:255,a:-1},p=P?p*-1:p,P=1-p;594 if(!f||!t)return null;595 if(l)r=m(P*f.r+p*t.r),g=m(P*f.g+p*t.g),b=m(P*f.b+p*t.b);596 else r=m((P*f.r**2+p*t.r**2)**0.5),g=m((P*f.g**2+p*t.g**2)**0.5),b=m((P*f.b**2+p*t.b**2)**0.5);597 a=f.a,t=t.a,f=a>=0||t>=0,a=f?a<0?t:t<0?a:a*P+t*p:0;598 if(h)return"rgb"+(f?"a(":"(")+r+","+g+","+b+(f?","+m(a*1000)/1000:"")+")";599 else return"#"+(4294967296+r*16777216+g*65536+b*256+(f?m(a*255):0)).toString(16).slice(1,f?undefined:-2)600}601/**602 * Plots a confusion matrix if file.hyperpipe_info.estimation_type equals "classifier" and plots a graph otherwise603 * @param {Object} file Object containing all needed information604 * @returns Object containing objects 'training' and 'validation' with keys 'data' and 'layout'605 */606function plotBestConfigConfusion(file) {607 let plotTraining = {data: [], layout: {title: "Training", paper_bgcolor: "rgba(0, 0, 0, 0)", plot_bgcolor: "rgba(0, 0, 0, 0)"}};608 let plotValidation = {data: [], layout: {title: "Test", paper_bgcolor: "rgba(0, 0, 0, 0)", plot_bgcolor: "rgba(0, 0, 0, 0)"}};609 if (file.hyperpipe_info.estimation_type === "classifier") {610 let y_trueTraining = file.best_config.best_config_score.training.y_true;611 let y_predTraining = file.best_config.best_config_score.training.y_pred;612 let y_trueValidation = file.best_config.best_config_score.validation.y_true;613 let y_predValidation = file.best_config.best_config_score.validation.y_pred;614 let uniqueLabels = [...new Set(y_trueTraining)].map(value => `Label ${value}`)615 let uniqueLabelsReverse = [...new Set(y_trueTraining)].reverse().map(value => `Label ${value}`)616 let confusionMatrixTraining = ConfusionMatrix.fromLabels(y_trueTraining, y_predTraining);617 let confusionMatrixValidation = ConfusionMatrix.fromLabels(y_trueValidation, y_predValidation);618 // create z data for plot619 let flatten = (arr) => {620 return arr.reduce(function (flat, toFlatten) {621 return flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten);622 }, []);623 };624 let matrixTraining = confusionMatrixTraining.getMatrix().reverse();625 let matrixTrainingFlat = flatten(matrixTraining);626 let matrixValidation = confusionMatrixValidation.getMatrix().reverse();627 let matrixValidationFlat = flatten(matrixValidation);628 let zDataTraining = {z: matrixTraining, zmin: Math.min(matrixTrainingFlat), zmax: Math.max(matrixTrainingFlat)};629 let zDataValidation = {z: matrixValidation, zmin: Math.min(matrixValidationFlat), zmax: Math.max(matrixValidationFlat)};630 // PLOT CONFUSION MATRIX631 let colorscaleValuesTrain = [[0, '#ffffff'], [1, '#2388fe']]632 let colorscaleValuesTest = [[0, '#ffffff'], [1, '#231c44']]633 // let traceTraining = {type: "heatmap", x: uniqueLabels, y: uniqueLabelsReverse, ...zDataTraining, autocolorscale: false, colorScale: colourScale};634 // let traceValidation = {type: "heatmap", x: uniqueLabels, y: uniqueLabelsReverse, ...zDataValidation, autocolorscale: false, colorScale: colourScale};635 let traceTraining = {type: "heatmap", x: uniqueLabels, y: uniqueLabelsReverse, ...zDataTraining,636 colorscale: colorscaleValuesTrain};637 let traceValidation = {type: "heatmap", x: uniqueLabels, y: uniqueLabelsReverse, ...zDataValidation,638 colorscale: colorscaleValuesTest};639 plotTraining.data.push(traceTraining);640 plotValidation.data.push(traceValidation);641 // add styling642 plotTraining.layout.xaxis = {title: 'Predicted value'};643 plotTraining.layout.yaxis = {title: 'True value'};644 plotValidation.layout.xaxis = {title: 'Predicted value'};645 plotValidation.layout.yaxis = {title: 'True value'};646 } else {647 // TRUE / PRED GRAPH648 let range = (size, startAt = 0) => {649 return [...Array(size).keys()].map(i => i + startAt);650 }651 for (const [idx, fold] of file.outer_folds.entries()) {652 // Training653 let y_true = fold.best_config.best_config_score.training.y_true;654 let y_pred = fold.best_config.best_config_score.training.y_pred;655 let tmp_color = ColorList[idx];656 let traceTrueTraining = {name: "Fold "+ + idx, type: "scatter", mode: 'markers',657 marker: {color: tmp_color},658 x: y_pred, y: y_true};659 // let tracePredictionTraining = {name: "Predicted", type: "scatter", mode: 'markers',660 // marker: {color: tmp_color},661 // x: range(y_pred.length), y: y_pred};662 // Validation663 y_true = fold.best_config.best_config_score.validation.y_true;664 y_pred = fold.best_config.best_config_score.validation.y_pred;665 let traceTrueValidation = {name: "Fold " + idx, type: "scatter", mode: 'markers',666 x: y_pred, y: y_true};667 // let tracePredictionValidation = {name: "Predicted", type: "scatter", mode: 'markers',668 // x: range(y_pred.length), y: y_pred};669 plotTraining.data.push(traceTrueTraining);670 plotValidation.data.push(traceTrueValidation);671 plotTraining.layout.xaxis = {title: 'Predicted value'};672 plotTraining.layout.yaxis = {title: 'True value'};673 plotValidation.layout.xaxis = {title: 'Predicted value'};674 plotValidation.layout.yaxis = {title: 'True value'};675 }676 }677 return {training: plotTraining, validation: plotValidation}678}679/**680 * Plots the optimisation history681 * @param {Object} file Object containing all needed information682 */683function plotOptimizerHistory(file) {684 // determine best_config_metric and order685 let bestConfigMetric = file.hyperpipe_info.best_config_metric;686 let maximizeBestConfigMetric = file.hyperpipe_info.maximize_best_config_metric;687 let caption = maximizeBestConfigMetric ? "Max" : "Min";688 // utility range function689 let range = (size, startAt = 0) => [...Array(size).keys()].map(i => i + startAt);690 let traces = [];691 let maxLen = 0; // length of longest optimisation trace692 // create one current_metric_value trace and one $caption_metric_value trace for each fold - aggregate data693 for (const [idx, fold] of file.outer_folds.entries()) {694 let tmp_color = ColorList[idx];695 let tmp_color_lightened = pSBC(0.4, tmp_color);696 let data = fold.tested_config_list.map(conf =>697 conf.metrics_test.filter(op => op.operation === "mean" && op.metric_name === bestConfigMetric)[0].value);698 let currentBest = data[0]699 let bestData = data.map(value => {700 if (maximizeBestConfigMetric) {701 let v = Math.max(value, currentBest);702 currentBest = v;703 return v;704 } else {705 let v = Math.min(value, currentBest);706 currentBest = v;707 return v;708 }709 });710 if (data.length > maxLen)711 maxLen = data.length;712 let traceCurrentMetricValue = {name: `Fold ${fold.fold_nr}`,713 type: 'scatter',714 mode: "markers",715 marker: {color: tmp_color_lightened},716 x: range(data.length, 1), y: data};717 let traceBestMetricValue = {name: `Fold ${fold.fold_nr} Best`, mode: "lines",718 line: {shape: "hv", color: tmp_color},719 x: range(data.length, 1), y: bestData};720 traces.push(traceCurrentMetricValue, traceBestMetricValue);721 }722 return {723 data: traces,724 layout: {725 title: "",726 xaxis: {727 title: "No of Hyperparameter Configs Tested",728 tickvals: range(maxLen, 1)729 },730 yaxis: {title: bestConfigMetric},731 showlegend: true,732 paper_bgcolor: "rgba(0, 0, 0, 0)",733 plot_bgcolor: "rgba(0, 0, 0, 0)"734 }735 }...

Full Screen

Full Screen

SpanAttribute.service.ts

Source:SpanAttribute.service.ts Github

copy

Full Screen

1import {2 OtelReference,3 OtelReferenceModel,4} from 'components/TestSpecForm/hooks/useGetOTELSemanticConventionAttributesInfo';5import AttributesTags from 'constants/AttributesTags.json';6import {SemanticGroupNames} from 'constants/SemanticGroupNames.constants';7import {8 SectionNames,9 SelectorAttributesBlackList,10 SelectorAttributesWhiteList,11 SpanAttributeSections,12} from 'constants/Span.constants';13import {Attributes, TraceTestAttributes} from 'constants/SpanAttribute.constants';14import {isEmpty, remove} from 'lodash';15import {TSpanFlatAttribute} from 'types/Span.types';16import {isJson} from 'utils/Common';17const attributesTags: Record<string, OtelReferenceModel> = AttributesTags;18const flatAttributes = Object.values(Attributes);19const flatTraceTestAttributes = Object.values(TraceTestAttributes);20const filterAttributeList = (attributeList: TSpanFlatAttribute[], attrKeyList: string[]): TSpanFlatAttribute[] => {21 return attrKeyList.reduce<TSpanFlatAttribute[]>((list, key) => {22 const foundAttrList = attributeList.filter(attr => attr.key.indexOf(key) === 0);23 return foundAttrList.length ? list.concat(foundAttrList) : list;24 }, []);25};26const removeFromAttributeList = (attributeList: TSpanFlatAttribute[], attrKeyList: string[]): TSpanFlatAttribute[] =>27 remove(attributeList, attr => !attrKeyList.includes(attr.key));28const getCustomAttributeList = (attributeList: TSpanFlatAttribute[]) => {29 const traceTestList = filterAttributeList(attributeList, flatTraceTestAttributes);30 const filetedList = attributeList.filter(attr => {31 const foundAttr = flatAttributes.find(key => attr.key.indexOf(key) === 0);32 return !foundAttr;33 });34 return traceTestList.concat(filetedList);35};36const SpanAttributeService = () => ({37 getPseudoAttributeList: (count: number): TSpanFlatAttribute[] => [38 {key: TraceTestAttributes.TRACETEST_SELECTED_SPANS_COUNT, value: count.toString()},39 ],40 getSpanAttributeSectionsList(41 attributeList: TSpanFlatAttribute[],42 type: SemanticGroupNames43 ): {section: string; attributeList: TSpanFlatAttribute[]}[] {44 const sections = SpanAttributeSections[type] || {};45 const defaultSectionList = [46 {47 section: SectionNames.custom,48 attributeList: getCustomAttributeList(attributeList),49 },50 {51 section: SectionNames.all,52 attributeList,53 },54 ];55 const sectionList = Object.entries(sections).reduce<{section: string; attributeList: TSpanFlatAttribute[]}[]>(56 (list, [key, attrKeyList]) =>57 list.concat([{section: key, attributeList: filterAttributeList(attributeList, attrKeyList)}]),58 []59 );60 return sectionList.concat(defaultSectionList);61 },62 getFilteredSelectorAttributeList(63 attributeList: TSpanFlatAttribute[],64 currentSelectorList: string[]65 ): TSpanFlatAttribute[] {66 const duplicatedFiltered = removeFromAttributeList(attributeList, currentSelectorList);67 const whiteListFiltered = filterAttributeList(duplicatedFiltered, SelectorAttributesWhiteList);68 const blackListFiltered = removeFromAttributeList(whiteListFiltered, SelectorAttributesBlackList);69 const customList = getCustomAttributeList(attributeList);70 return blackListFiltered.concat(customList).filter(attr => !isJson(attr.value) && !isEmpty(attr));71 },72 referencePicker(reference: OtelReference, key: string): OtelReferenceModel {73 return reference[key] || attributesTags[key] || {description: '', tags: []};74 },75});...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var traceTest = require('./tracetest.js');2traceTest.traceTestList();3exports.traceTestList = function () {4 console.log("traceTestList method called");5};6new Error([message]);7var err = new Error("Error occurred");8console.log(err.stack);9 at Object. (/Users/savitha/Documents/Nodejs/stacktrace.js:2:13)10 at Module._compile (internal/modules/cjs/loader.js:1158:30)11 at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)12 at Module.load (internal/modules/cjs/loader.js:1002:32)13 at Function.Module._load (internal/modules/cjs/loader.js:901:14)14 at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)15new Error([message]);16var err = new Error("Error occurred");17console.log(err.stack);18 at Object. (/Users/savitha/Documents/Nodejs/stacktrace.js:2:13)19 at Module._compile (internal/modules/cjs/loader.js:1158:30)20 at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)21 at Module.load (internal/modules/cjs/loader.js:1002:32)22 at Function.Module._load (internal/modules/cjs/loader.js:901:14)23 at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:

Full Screen

Using AI Code Generation

copy

Full Screen

1var traceTest = require('./tracetest');2traceTest.traceTestList();3exports.traceTestList = function() {4 console.log("traceTestList method called");5}6var traceTest = require('./tracetest');7console.log(traceTest.traceTestList);8exports.traceTestList = {9}10{ name: 'traceTestList', id: 1 }11How to import a module in Node.js?12In Node.js, to import a module, you need to use require() method. It is used to import a module in Node.js. For example, if you want to import a module called tracetest.js, you need to use require(‘./tracetest’) method. You can import a module in two ways:13If you want to import a module using relative path, you need to use the following syntax:

Full Screen

Using AI Code Generation

copy

Full Screen

1var tracetest = require('./tracetest');2var traceTestList = tracetest.traceTestList;3traceTestList();4var traceTestList = function() {5 console.log("traceTestList method");6}7exports.traceTestList = traceTestList;

Full Screen

Using AI Code Generation

copy

Full Screen

1var traceTest = require("./tracetest.js");2var traceTestList = traceTest.traceTestList;3traceTestList("test1", "test2", "test3");4exports.traceTestList = function() {5 var args = Array.prototype.slice.call(arguments);6 args.forEach(function(arg) {7 console.log(arg);8 });9};

Full Screen

Using AI Code Generation

copy

Full Screen

1var traceTest = require('./traceTest');2var tracetest = new traceTest();3tracetest.traceTestList();4var traceTest = function () {5 var tracetest = this;6 tracetest.traceTestList = function () {7 console.log("traceTestList");8 }9}10module.exports = traceTest;

Full Screen

Using AI Code Generation

copy

Full Screen

1var traceTest = require('./traceTest');2traceTest.traceTestList();3var traceTestList = function(){4 console.log("traceTestList method");5};6exports.traceTestList = traceTestList;7var traceTest = require('./traceTest');8traceTest.traceTestList();9var traceTestList = function(){10 console.log("traceTestList method");11};12exports.traceTestList = traceTestList;13var traceTest = require('./traceTest');14traceTest.traceTestList();15var traceTestList = function(){16 console.log("traceTestList method");17};18exports.traceTestList = traceTestList;19var traceTest = require('./traceTest');20traceTest.traceTestList();21var traceTestList = function(){22 console.log("traceTestList method");23};24exports.traceTestList = traceTestList;25var traceTest = require('./traceTest');26traceTest.traceTestList();27var traceTestList = function(){28 console.log("traceTestList method");29};30exports.traceTestList = traceTestList;

Full Screen

Using AI Code Generation

copy

Full Screen

1var tracetest = require('./tracetest');2tracetest.traceTestList();3var tracetest = {};4tracetest.traceTestList = function(){5 console.log('Trace test list:');6 console.log(this.testList);7}8tracetest.testList = ['test1', 'test2', 'test3', 'test4', 'test5'];9module.exports = tracetest;

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tracetest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful