Skip to content

Commit 66a11b2

Browse files
authored
Data Table: Use smoothed values in table (#6042)
* Motivation for features / changes When users have smoothing enabled the raw values on the scalar chart are faded and hidden in the background while the smoothed lines are highlighted and in the foreground. However, while in range selection mode the data table only showed values based on the real values. This was confusing for users. This changes the data table to use the smoothed and highlighted values on the chart in the data table. * Technical description of changes We simply changed the calculations to use the "y" property on the ScalarCardPoint object instead of the "value" property.
1 parent e48f279 commit 66a11b2

File tree

2 files changed

+76
-15
lines changed

2 files changed

+76
-15
lines changed

tensorboard/webapp/metrics/views/card_renderer/scalar_card_data_table.ts

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,13 @@ export class ScalarCardDataTable {
5555
getMinValueInRange(
5656
points: ScalarCardPoint[],
5757
startPointIndex: number,
58-
endPointIndex: number
58+
endPointIndex: number,
59+
smoothed: boolean = false
5960
): number {
60-
let minValue = points[startPointIndex].value;
61+
let minValue = this.maybeSmoothedValue(points[startPointIndex], smoothed);
6162
for (let i = startPointIndex; i <= endPointIndex; i++) {
62-
if (minValue > points[i].value) {
63-
minValue = points[i].value;
63+
if (minValue > this.maybeSmoothedValue(points[i], smoothed)) {
64+
minValue = this.maybeSmoothedValue(points[i], smoothed);
6465
}
6566
}
6667
return minValue;
@@ -69,17 +70,22 @@ export class ScalarCardDataTable {
6970
getMaxValueInRange(
7071
points: ScalarCardPoint[],
7172
startPointIndex: number,
72-
endPointIndex: number
73+
endPointIndex: number,
74+
smoothed: boolean = false
7375
): number {
74-
let maxValue = points[startPointIndex].value;
76+
let maxValue = this.maybeSmoothedValue(points[startPointIndex], smoothed);
7577
for (let i = startPointIndex; i <= endPointIndex; i++) {
76-
if (maxValue < points[i].value) {
77-
maxValue = points[i].value;
78+
if (maxValue < this.maybeSmoothedValue(points[i], smoothed)) {
79+
maxValue = this.maybeSmoothedValue(points[i], smoothed);
7880
}
7981
}
8082
return maxValue;
8183
}
8284

85+
maybeSmoothedValue(point: ScalarCardPoint, smoothed: boolean) {
86+
return smoothed ? point.y : point.value;
87+
}
88+
8389
getTimeSelectionTableData(): SelectedStepRunData[] {
8490
if (this.stepOrLinkedTimeSelection === null) {
8591
return [];
@@ -135,7 +141,7 @@ export class ScalarCardDataTable {
135141
continue;
136142
}
137143
selectedStepData.VALUE_CHANGE =
138-
closestEndPoint.value - closestStartPoint.value;
144+
closestEndPoint.y - closestStartPoint.y;
139145
continue;
140146
case ColumnHeaders.START_STEP:
141147
selectedStepData.START_STEP = closestStartPoint.step;
@@ -147,13 +153,13 @@ export class ScalarCardDataTable {
147153
selectedStepData.END_STEP = closestEndPoint.step;
148154
continue;
149155
case ColumnHeaders.START_VALUE:
150-
selectedStepData.START_VALUE = closestStartPoint.value;
156+
selectedStepData.START_VALUE = closestStartPoint.y;
151157
continue;
152158
case ColumnHeaders.END_VALUE:
153159
if (!closestEndPoint) {
154160
continue;
155161
}
156-
selectedStepData.END_VALUE = closestEndPoint.value;
162+
selectedStepData.END_VALUE = closestEndPoint.y;
157163
continue;
158164
case ColumnHeaders.MIN_VALUE:
159165
if (!closestEndPointIndex) {
@@ -162,7 +168,8 @@ export class ScalarCardDataTable {
162168
selectedStepData.MIN_VALUE = this.getMinValueInRange(
163169
datum.points,
164170
closestStartPointIndex,
165-
closestEndPointIndex
171+
closestEndPointIndex,
172+
true
166173
);
167174
continue;
168175
case ColumnHeaders.MAX_VALUE:
@@ -172,16 +179,16 @@ export class ScalarCardDataTable {
172179
selectedStepData.MAX_VALUE = this.getMaxValueInRange(
173180
datum.points,
174181
closestStartPointIndex,
175-
closestEndPointIndex
182+
closestEndPointIndex,
183+
true
176184
);
177185
continue;
178186
case ColumnHeaders.PERCENTAGE_CHANGE:
179187
if (!closestEndPoint) {
180188
continue;
181189
}
182190
selectedStepData.PERCENTAGE_CHANGE =
183-
(closestEndPoint.value - closestStartPoint.value) /
184-
closestStartPoint.value;
191+
(closestEndPoint.y - closestStartPoint.y) / closestStartPoint.y;
185192
continue;
186193
default:
187194
continue;

tensorboard/webapp/metrics/views/card_renderer/scalar_card_test.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2688,6 +2688,60 @@ describe('scalar card', () => {
26882688
]);
26892689
}));
26902690

2691+
it('builds range selected step data object with smoothed values', fakeAsync(() => {
2692+
const runToSeries = {
2693+
run1: [
2694+
{wallTime: 1, value: 10, step: 1},
2695+
{wallTime: 2, value: 8, step: 2},
2696+
{wallTime: 3, value: 3, step: 3},
2697+
{wallTime: 4, value: 25, step: 4},
2698+
],
2699+
};
2700+
provideMockCardRunToSeriesData(
2701+
selectSpy,
2702+
PluginType.SCALARS,
2703+
'card1',
2704+
null /* metadataOverride */,
2705+
runToSeries
2706+
);
2707+
store.overrideSelector(
2708+
selectors.getCurrentRouteRunSelection,
2709+
new Map([['run1', true]])
2710+
);
2711+
2712+
store.overrideSelector(selectors.getMetricsScalarSmoothing, 0.3);
2713+
2714+
store.overrideSelector(getMetricsLinkedTimeSelection, {
2715+
start: {step: 2},
2716+
end: {step: 4},
2717+
});
2718+
2719+
const fixture = createComponent('card1');
2720+
const scalarCardDataTable = fixture.debugElement.query(
2721+
By.directive(ScalarCardDataTable)
2722+
);
2723+
fixture.detectChanges();
2724+
2725+
const data =
2726+
scalarCardDataTable.componentInstance.getTimeSelectionTableData();
2727+
2728+
expect(data).toEqual([
2729+
{
2730+
id: '["smoothed","run1"]',
2731+
COLOR: '#fff',
2732+
RUN: 'run1',
2733+
VALUE_CHANGE: 10.515172900494004,
2734+
START_STEP: 2,
2735+
END_STEP: 4,
2736+
START_VALUE: 8.46153846153846,
2737+
END_VALUE: 18.976711362032464,
2738+
MIN_VALUE: 4.532374100719424,
2739+
MAX_VALUE: 18.976711362032464,
2740+
PERCENTAGE_CHANGE: 1.2427022518765645,
2741+
},
2742+
]);
2743+
}));
2744+
26912745
it('selects closest points to time selection', fakeAsync(() => {
26922746
const runToSeries = {
26932747
run1: [

0 commit comments

Comments
 (0)