-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added overall accuracy cell #189
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0cc8183
Added overall accuracy cell
67b82ab
Added label for chart tab.
aa5d393
Merge branch 'develop' into NMO13/features/overall_accuracy_curve
5bbe471
Code improvements. Make x-axis stride dependent on epoch granularity
1a713f5
Remove unnecessary code
93dc287
Merge branch 'develop' into NMO13/features/overall_accuracy_curve
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import {IAppView} from './app'; | ||
import {App, IAppView} from './app'; | ||
import * as d3 from 'd3'; | ||
import * as events from 'phovea_core/src/event'; | ||
import {AppConstants} from './AppConstants'; | ||
|
@@ -14,7 +14,7 @@ import {ACell, LabelCell, MatrixCell, PanelCell} from './confusion_matrix_cell/C | |
import {zip} from './utils'; | ||
import * as confMeasures from './ConfusionMeasures'; | ||
import {Language} from './language'; | ||
import {SquareMatrix, max, Matrix} from './DataStructures'; | ||
import {SquareMatrix, max, Matrix, matrixSum} from './DataStructures'; | ||
import { | ||
DataStoreApplicationProperties, DataStoreSelectedRun, dataStoreTimelines, RenderMode | ||
} from './DataStore'; | ||
|
@@ -41,6 +41,7 @@ export class ConfusionMatrix implements IAppView { | |
private f1ScoreColumn: ChartColumn; | ||
private classSizeColumn: ChartColumn; | ||
private $cells = null; | ||
private $overallAccuracyCell: d3.Selection<any>; | ||
|
||
constructor(parent: Element) { | ||
this.$node = d3.select(parent) | ||
|
@@ -129,6 +130,9 @@ export class ConfusionMatrix implements IAppView { | |
|
||
const numBottomColumns = 1; // number of additional columns | ||
this.$node.style('--num-bottom-columns', numBottomColumns); | ||
|
||
this.$overallAccuracyCell = this.$node.append('div').classed('overall', true) | ||
.append('div').classed('cell', true); | ||
} | ||
|
||
private attachListeners() { | ||
|
@@ -347,6 +351,7 @@ export class ConfusionMatrix implements IAppView { | |
let dataPrecision = null; | ||
let dataRecall = null; | ||
let dataF1 = null; | ||
let dataOverallAccuracy = null; | ||
|
||
let fpfnRendererProto: IMatrixRendererChain = null; | ||
let confMatrixRendererProto: IMatrixRendererChain = null; | ||
|
@@ -362,6 +367,7 @@ export class ConfusionMatrix implements IAppView { | |
dataPrecision = datasets.map((x) => confMeasures.calcEvolution(x.multiEpochData.map((y) => y.confusionData), confMeasures.PPV)); | ||
dataRecall = datasets.map((x) => confMeasures.calcEvolution(x.multiEpochData.map((y) => y.confusionData), confMeasures.TPR)); | ||
dataF1 = datasets.map((x) => confMeasures.calcEvolution(x.multiEpochData.map((y) => y.confusionData), confMeasures.F1)); | ||
dataOverallAccuracy = datasets.map((x) => confMeasures.calcOverallAccuracy(x.multiEpochData.map((y) => y.confusionData))); | ||
singleEpochIndex = data[1].heatcell.indexInMultiSelection; | ||
|
||
confMatrixRendererProto = { | ||
|
@@ -408,6 +414,7 @@ export class ConfusionMatrix implements IAppView { | |
dataPrecision = datasets.map((x) => confMeasures.calcEvolution(x.multiEpochData.map((y) => y.confusionData), confMeasures.PPV)); | ||
dataRecall = datasets.map((x) => confMeasures.calcEvolution(x.multiEpochData.map((y) => y.confusionData), confMeasures.TPR)); | ||
dataF1 = datasets.map((x) => confMeasures.calcEvolution(x.multiEpochData.map((y) => y.confusionData), confMeasures.F1)); | ||
dataOverallAccuracy = datasets.map((x) => confMeasures.calcOverallAccuracy(x.multiEpochData.map((y) => y.confusionData))); | ||
singleEpochIndex = null; | ||
|
||
confMatrixRendererProto = { | ||
|
@@ -460,6 +467,7 @@ export class ConfusionMatrix implements IAppView { | |
this.renderPrecisionColumn(dataPrecision, precRendererProto, datasets[0].labels, singleEpochIndex, datasets.map((x) => x.datasetColor)); | ||
this.renderRecallColumn(dataRecall, precRendererProto, datasets[0].labels, singleEpochIndex, datasets.map((x) => x.datasetColor)); | ||
this.renderF1ScoreColumn(dataF1, precRendererProto, datasets[0].labels, singleEpochIndex, datasets.map((x) => x.datasetColor)); | ||
this.renderOverallAccuracyCell(dataOverallAccuracy, precRendererProto, datasets[0].labels, singleEpochIndex, datasets.map((x) => x.datasetColor)); | ||
} | ||
|
||
private renderConfMatrixCells() { | ||
|
@@ -489,6 +497,19 @@ export class ConfusionMatrix implements IAppView { | |
}); | ||
} | ||
|
||
renderOverallAccuracyCell(data: number[][], renderer: IMatrixRendererChain, labels: string[], singleEpochIndex: number[], colors: string[]) { | ||
const maxVal = Math.max(...data.map((x: number[]) => Math.max(...x))); | ||
|
||
const res = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrong code indentation |
||
linecell: data.map((x, i) => [{values: x, valuesInPercent: x, max: maxVal, classLabel: null, color: colors[i]}]), | ||
heatcell: {indexInMultiSelection: singleEpochIndex, counts: null, maxVal: 0, classLabels: null, colorValues: null} | ||
}; | ||
const cell = new PanelCell(res, AppConstants.CELL_OVERALL_ACCURACY_SCORE); | ||
cell.init(this.$overallAccuracyCell); | ||
applyRendererChain(renderer, cell, renderer.diagonal); | ||
cell.render(); | ||
} | ||
|
||
renderRecallColumn(data: Matrix<number[]>[], renderer: IMatrixRendererChain, labels: string[], singleEpochIndex: number[], colors: string[]) { | ||
const maxVal = Math.max(...data.map((x: Matrix<number[]>) => max(x, (d) => Math.max(...d)))); | ||
let transformedData = data.map((x) => x.to1DArray()); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,11 +95,35 @@ export function calcEvolution(matrices: NumberMatrix[], funct: (matrix: NumberMa | |
const res = calcForMultipleClasses(m, funct); | ||
matrix.values.map((c, i) => c[0].push(res[i])); | ||
} | ||
|
||
//const summedPercent = calcSummedPercent(matrices); | ||
//matrix[order - 1][0] = summedPercent; | ||
return matrix; | ||
} | ||
|
||
export function calcOverallAccuracy(matrices: NumberMatrix[]): number[] { | ||
const order = matrices[0].order(); | ||
const arr = []; | ||
if(matrices.length === 0) { | ||
return arr; | ||
} | ||
|
||
for(const m of matrices) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why don't you use return matrices.map((m) => calcSummedPercent1(m)); |
||
const res = calcSummedPercent1(m); | ||
arr.push(res); | ||
} | ||
return arr; | ||
} | ||
|
||
export function calcSummedPercent1(matrix: NumberMatrix) { | ||
let tpSum = 0; | ||
let classSizeSum = 0; | ||
for(let i = 0; i < matrix.order(); i++) { | ||
tpSum += TP(matrix, i); | ||
classSizeSum += ClassSize(matrix, i); | ||
} | ||
if(classSizeSum === 0) { | ||
return 0; | ||
} | ||
return tpSum / classSizeSum; | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternative to flatten the array first and use only one
Math.max
: