Skip to content

Commit

Permalink
feat: add metric column to learning curve table (#1785)
Browse files Browse the repository at this point in the history
  • Loading branch information
hkang1 committed Jan 15, 2021
1 parent 1e2dc78 commit 9307710
Showing 1 changed file with 23 additions and 3 deletions.
Expand Up @@ -2,6 +2,7 @@ import { Alert, Select } from 'antd';
import { SelectValue } from 'antd/es/select';
import React, { useCallback, useEffect, useMemo, useState } from 'react';

import BadgeTag from 'components/BadgeTag';
import HumanReadableFloat from 'components/HumanReadableFloat';
import LearningCurveChart from 'components/LearningCurveChart';
import Link from 'components/Link';
Expand All @@ -19,7 +20,7 @@ import { detApi } from 'services/apiConfig';
import { consumeStream } from 'services/utils';
import { ExperimentBase, MetricName, metricTypeParamMap, RunState } from 'types';
import { glasbeyColor } from 'utils/color';
import { alphanumericSorter, hpSorter } from 'utils/data';
import { alphanumericSorter, hpSorter, numericSorter } from 'utils/data';
import { terminalRunStates } from 'utils/types';

import css from './LearningCurve.module.scss';
Expand All @@ -38,6 +39,7 @@ type HParams = Record<string, boolean | number | string>;
interface TrialHParams {
hparams: HParams;
id: number;
metric: number | null;
url: string;
}

Expand Down Expand Up @@ -79,6 +81,22 @@ const LearningCurve: React.FC<Props> = ({
const idSorter = (a: TrialHParams, b: TrialHParams): number => alphanumericSorter(a.id, b.id);
const idColumn = { key: 'id', render: idRenderer, sorter: idSorter, title: 'Trial ID' };

const metricRenderer = (_: string, record: TrialHParams) => {
return record.metric ? <HumanReadableFloat num={record.metric} /> : null;
};
const metricSorter = (recordA: TrialHParams, recordB: TrialHParams): number => {
return numericSorter(recordA.metric || undefined, recordB.metric || undefined);
};
const metricColumn = {
dataIndex: 'metric',
key: 'metric',
render: metricRenderer,
sorter: metricSorter,
title: <BadgeTag
label={selectedMetric.name}
tooltip={selectedMetric.type}>{selectedMetric.type.substr(0, 1).toUpperCase()}</BadgeTag>,
};

const hpRenderer = (key: string) => {
return (_: string, record: TrialHParams) => {
const value = record.hparams[key];
Expand All @@ -103,8 +121,8 @@ const LearningCurve: React.FC<Props> = ({
title: key,
}));

return [ idColumn, ...hpColumns ];
}, [ experiment.config.hyperparameters, trialIds ]);
return [ idColumn, metricColumn, ...hpColumns ];
}, [ experiment.config.hyperparameters, selectedMetric, trialIds ]);

const resetData = useCallback(() => {
setChartData([]);
Expand Down Expand Up @@ -191,6 +209,7 @@ const LearningCurve: React.FC<Props> = ({
trialHpMap[id] = {
hparams: trial.hparams,
id,
metric: null,
url: `/experiments/${experiment.id}/trials/${id}`,
};
}
Expand All @@ -201,6 +220,7 @@ const LearningCurve: React.FC<Props> = ({
trial.data.forEach(datapoint => {
batchesMap[datapoint.batches] = datapoint.batches;
metricsMap[id][datapoint.batches] = datapoint.value;
trialHpMap[id].metric = datapoint.value;
});
});

Expand Down

0 comments on commit 9307710

Please sign in to comment.