-
Notifications
You must be signed in to change notification settings - Fork 360
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into gaugup/UpdateRaiUtils
- Loading branch information
Showing
19 changed files
with
233 additions
and
26 deletions.
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
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
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
export interface ILabeledStatistic { | ||
key: string; | ||
label: string; | ||
stat: number; | ||
} | ||
|
||
export const TotalCohortSamples = "samples"; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
import { localization } from "@responsible-ai/localization"; | ||
|
||
import { | ||
ILabeledStatistic, | ||
TotalCohortSamples | ||
} from "../Interfaces/IStatistic"; | ||
|
||
import { JointDataset } from "./JointDataset"; | ||
|
||
export enum MultilabelMetrics { | ||
ExactMatchRatio = "exactMatchRatio", | ||
HammingScore = "hammingScore" | ||
} | ||
|
||
export const generateMultilabelStats: ( | ||
jointDataset: JointDataset, | ||
selectionIndexes: number[][] | ||
) => ILabeledStatistic[][] = ( | ||
jointDataset: JointDataset, | ||
selectionIndexes: number[][] | ||
): ILabeledStatistic[][] => { | ||
const numLabels = jointDataset.numLabels; | ||
return selectionIndexes.map((selectionArray) => { | ||
const matchingLabels = []; | ||
let hammingScore = 0; | ||
const count = selectionArray.length; | ||
for (let i = 0; i < numLabels; i++) { | ||
const trueYs = jointDataset.unwrap(JointDataset.TrueYLabel + i); | ||
const predYs = jointDataset.unwrap(JointDataset.PredictedYLabel + i); | ||
|
||
const trueYSubset = selectionArray.map((i) => trueYs[i]); | ||
const predYSubset = selectionArray.map((i) => predYs[i]); | ||
matchingLabels.push( | ||
trueYSubset.filter((trueY, index) => trueY === predYSubset[index]) | ||
.length | ||
); | ||
const sumLogicalOr = trueYSubset | ||
.map((trueY, index) => trueY | predYSubset[index]) | ||
.reduce((prev, curr) => prev + curr, 0); | ||
const sumLogicalAnd = trueYSubset | ||
.map((trueY, index) => trueY & predYSubset[index]) | ||
.reduce((prev, curr) => prev + curr, 0); | ||
if (sumLogicalOr !== 0) { | ||
hammingScore += sumLogicalAnd / sumLogicalOr; | ||
} | ||
} | ||
hammingScore = hammingScore / numLabels; | ||
const sum = matchingLabels.reduce((prev, curr) => prev + curr, 0); | ||
const exactMatchRatio = sum / (numLabels * selectionArray.length); | ||
|
||
return [ | ||
{ | ||
key: TotalCohortSamples, | ||
label: localization.Interpret.Statistics.samples, | ||
stat: count | ||
}, | ||
{ | ||
key: MultilabelMetrics.ExactMatchRatio, | ||
label: localization.Interpret.Statistics.exactMatchRatio, | ||
stat: exactMatchRatio | ||
}, | ||
{ | ||
key: MultilabelMetrics.HammingScore, | ||
label: localization.Interpret.Statistics.hammingScore, | ||
stat: hammingScore | ||
} | ||
]; | ||
}); | ||
}; |
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
43 changes: 43 additions & 0 deletions
43
.../error-analysis/src/lib/ErrorAnalysisDashboard/Controls/TreeViewRenderer/TreeViewPath.tsx
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
import React from "react"; | ||
|
||
export interface ITreeViewLink { | ||
d: string; | ||
id: string; | ||
key: string; | ||
style: React.CSSProperties | undefined; | ||
} | ||
|
||
export interface ITreeViewPathProps { | ||
link: ITreeViewLink; | ||
onMouseOver: (linkId: string) => void; | ||
onMouseOut: () => void; | ||
} | ||
|
||
export class TreeViewPath extends React.Component<ITreeViewPathProps> { | ||
public render(): React.ReactNode { | ||
const { link } = this.props; | ||
|
||
return ( | ||
<path | ||
key={link.key} | ||
id={link.id} | ||
d={link.d} | ||
pointerEvents="all" | ||
style={link.style} | ||
onMouseOver={this.onMouseOver} | ||
onMouseOut={this.onMouseOut} | ||
/> | ||
); | ||
} | ||
|
||
private onMouseOver = (): void => { | ||
this.props.onMouseOver(this.props.link.id); | ||
}; | ||
|
||
private onMouseOut = (): void => { | ||
this.props.onMouseOut(); | ||
}; | ||
} |
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
Oops, something went wrong.