Refactor GraphEdf

This commit is contained in:
c-bata
2023-01-07 13:12:33 +09:00
parent 234649d5d9
commit eb09dc906a
4 changed files with 19 additions and 17 deletions
+9 -10
View File
@@ -1,5 +1,5 @@
import * as plotly from "plotly.js-dist-min"
import React, { FC, useEffect, useState } from "react"
import React, { FC, useEffect } from "react"
import {
Grid,
FormControl,
@@ -16,23 +16,22 @@ import { Target, useFilteredTrials, useObjectiveTargets } from "../trialFilter"
const plotDomId = "graph-edf"
export const Edf: FC<{
export const GraphEdf: FC<{
study: StudyDetail | null
}> = ({ study = null }) => {
const theme = useTheme()
const [objectiveId, setObjectiveId] = useState<number>(0)
const targets = useObjectiveTargets(study)
const trials = useFilteredTrials(study, [targets[objectiveId]], false, false)
const [targets, selected, setTarget] = useObjectiveTargets(study)
const trials = useFilteredTrials(study, [selected], false, false)
const handleObjectiveChange = (event: SelectChangeEvent<number>) => {
setObjectiveId(event.target.value as number)
setTarget(event.target.value as number)
}
useEffect(() => {
if (study != null) {
plotEdf(trials, targets[objectiveId], theme.palette.mode)
plotEdf(trials, selected, theme.palette.mode)
}
}, [trials, targets, objectiveId, theme.palette.mode])
}, [trials, selected, theme.palette.mode])
return (
<Grid container direction="row">
<Grid
@@ -47,8 +46,8 @@ export const Edf: FC<{
</Typography>
{study !== null && study.directions.length !== 1 ? (
<FormControl component="fieldset">
<FormLabel component="legend">Objective ID:</FormLabel>
<Select value={objectiveId} onChange={handleObjectiveChange}>
<FormLabel component="legend">Objective:</FormLabel>
<Select value={selected.getObjectiveId() || 0} onChange={handleObjectiveChange}>
{targets.map((target, i) => (
<MenuItem value={i} key={i}>
{target.toLabel(study?.objective_names)}
@@ -18,7 +18,7 @@ import Brightness7Icon from "@mui/icons-material/Brightness7"
import { GraphParallelCoordinate } from "./GraphParallelCoordinate"
import { GraphHyperparameterImportances } from "./GraphHyperparameterImportances"
import { Edf } from "./GraphEdf"
import { GraphEdf } from "./GraphEdf"
import { Contour } from "./GraphContour"
import { GraphIntermediateValues } from "./GraphIntermediateValues"
import { GraphSlice } from "./GraphSlice"
@@ -200,7 +200,7 @@ export const StudyDetail: FC<{
{graphVisibility.edf ? (
<Card sx={{ margin: theme.spacing(2) }}>
<CardContent>
<Edf study={studyDetail} />
<GraphEdf study={studyDetail} />
</CardContent>
</Card>
) : null}
@@ -32,7 +32,7 @@ import { GraphSlice } from "./GraphSlice"
import { GraphParetoFront } from "./GraphParetoFront"
import { DataGrid, DataGridColumn } from "./DataGrid"
import { GraphIntermediateValues } from "./GraphIntermediateValues"
import { Edf } from "./GraphEdf"
import { GraphEdf } from "./GraphEdf"
import { TrialList } from "./TrialList"
import { BestTrialsCard } from "./BestTrialsCard"
@@ -175,7 +175,7 @@ export const StudyDetailBeta: FC<{
</Typography>
<Card sx={{ margin: theme.spacing(2) }}>
<CardContent>
<Edf study={studyDetail} />
<GraphEdf study={studyDetail} />
</CardContent>
</Card>
</Box>
+6 -3
View File
@@ -1,4 +1,4 @@
import { useMemo } from "react"
import {useMemo, useState} from "react"
import { mergeUnionSearchSpace } from "./searchSpace"
type TargetKind = "objective" | "user_attr" | "params"
@@ -113,14 +113,17 @@ export const useFilteredTrials = (
})
}, [study?.trials, targets, filterComplete, filterPruned])
export const useObjectiveTargets = (study: StudyDetail | null): Target[] =>
useMemo<Target[]>(() => {
export const useObjectiveTargets = (study: StudyDetail | null): [Target[], Target, (index: number) => void] => {
const [targetIndex, setTargetIndex] = useState<number>(0)
const targetList = useMemo<Target[]>(() => {
if (study !== null) {
return study.directions.map((v, i) => new Target("objective", i))
} else {
return [new Target("objective", 0)]
}
}, [study?.directions])
return [targetList, targetList[targetIndex], setTargetIndex]
}
export const useParamTargets = (
study: StudyDetail | null