Skip to content
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

[Large counterfactuals & explanations] Do not call local counterfactuals/explanations on unselecting the point #1957

Merged
merged 6 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libs/counterfactuals/src/lib/CounterfactualChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export interface ICounterfactualChartProps {
) => void;
telemetryHook?: (message: ITelemetryEvent) => void;
togglePanel: () => void;
toggleSelectionOfPoint: (index?: number) => void;
toggleSelectionOfPoint: (index?: number) => number[];
}

export interface ICounterfactualChartState {
Expand Down
7 changes: 4 additions & 3 deletions libs/counterfactuals/src/lib/CounterfactualChartLegend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export interface ICounterfactualChartLegendProps {
telemetryHook?: (message: ITelemetryEvent) => void;
toggleCustomActivation: (index: number) => void;
togglePanel: () => void;
toggleSelectionOfPoint: (index?: number) => void;
toggleSelectionOfPoint: (index?: number) => number[];
setIsRevertButtonClicked: (status: boolean) => void;
}

Expand Down Expand Up @@ -154,10 +154,11 @@ export class CounterfactualChartLegend extends React.PureComponent<ICounterfactu
if (typeof item?.key === "string") {
const index = Number.parseInt(item.key);
this.props.setTemporaryPointToCopyOfDatasetPoint(index, item.data.index);
this.props.toggleSelectionOfPoint(index);
const newSelections = this.props.toggleSelectionOfPoint(index);
if (
ifEnableLargeData(this.context.dataset) &&
this.props.setCounterfactualData
this.props.setCounterfactualData &&
newSelections.length > 0
) {
this.props.setCounterfactualData(item.data.index);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ export class CounterfactualChartWithLegend extends React.PureComponent<
);
}

private toggleSelectionOfPoint = (index?: number): void => {
private toggleSelectionOfPoint = (index?: number): number[] => {
if (index === undefined) {
return;
return [];
}
const indexOf = this.props.selectedPointsIndexes.indexOf(index);
let newSelections = [...this.props.selectedPointsIndexes];
Expand All @@ -181,6 +181,7 @@ export class CounterfactualChartWithLegend extends React.PureComponent<
pointIsActive
});
this.props.onSelectedPointsIndexesUpdated(newSelections);
return newSelections;
};

private toggleCustomActivation = (index: number): void => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,10 @@ export class LargeCounterfactualChart extends React.PureComponent<
const absoluteIndex = data.customData[JointDataset.AbsoluteIndexLabel];
index &&
this.props.setTemporaryPointToCopyOfDatasetPoint(index, absoluteIndex);
this.props.setCounterfactualData(absoluteIndex);
this.props.toggleSelectionOfPoint(index);
const newSelections = this.props.toggleSelectionOfPoint(index);
if (newSelections.length > 0) {
this.props.setCounterfactualData(absoluteIndex);
}
this.props.telemetryHook?.({
level: TelemetryLevels.ButtonClick,
type: TelemetryEventName.CounterfactualNewDatapointSelectedFromChart
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export class LargeIndividualFeatureImportanceView extends React.Component<
);
};

private toggleSelectionOfPoint = (index?: number): void => {
private toggleSelectionOfPoint = (index?: number): number[] | undefined => {
const newSelections = getNewSelections(
this.state.selectedPointsIndexes,
index
Expand All @@ -259,6 +259,7 @@ export class LargeIndividualFeatureImportanceView extends React.Component<
selectedPointsIndexes: newSelections
});
}
return newSelections;
vinuthakaranth marked this conversation as resolved.
Show resolved Hide resolved
};

private setLocalExplanationsData = async (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,15 @@ export function getNewSelections(
export async function selectPointFromChartLargeData(
data: IScatterPoint,
setLocalExplanationsData: (absoluteIndex: number) => Promise<void>,
toggleSelectionOfPoint: (index?: number) => void,
toggleSelectionOfPoint: (index?: number) => number[] | undefined,
telemetryHook?: ((message: ITelemetryEvent) => void) | undefined
): Promise<void> {
const index = data.customData[JointDataset.IndexLabel];
const absoluteIndex = data.customData[JointDataset.AbsoluteIndexLabel];
if (absoluteIndex) {
const newSelections = toggleSelectionOfPoint(index);
if (absoluteIndex && newSelections && newSelections?.length > 0) {
setLocalExplanationsData(absoluteIndex);
}
toggleSelectionOfPoint(index);
telemetryHook?.({
level: TelemetryLevels.ButtonClick,
type: TelemetryEventName.FeatureImportancesNewDatapointSelectedFromChart
Expand Down