mirror of
https://github.com/wassname/optuna-dashboard.git
synced 2026-09-24 13:41:07 +08:00
Add simple pareto front plot
This commit is contained in:
@@ -34,11 +34,17 @@ const convertTrialResponse = (res: TrialResponse): Trial => {
|
||||
}
|
||||
}
|
||||
|
||||
const convertTrialResponseList = (res: TrialResponse[]): Trial[] => {
|
||||
return res.map((trial): Trial => convertTrialResponse(trial))
|
||||
}
|
||||
|
||||
|
||||
interface StudyDetailResponse {
|
||||
name: string
|
||||
datetime_start: string
|
||||
directions: StudyDirection[]
|
||||
best_trial?: TrialResponse
|
||||
best_trials?: TrialResponse[]
|
||||
trials: TrialResponse[]
|
||||
}
|
||||
|
||||
@@ -58,6 +64,9 @@ export const getStudyDetailAPI = (studyId: number): Promise<StudyDetail> => {
|
||||
best_trial: res.data.best_trial
|
||||
? convertTrialResponse(res.data.best_trial)
|
||||
: undefined,
|
||||
best_trials: res.data.best_trials
|
||||
? convertTrialResponseList(res.data.best_trials)
|
||||
: undefined,
|
||||
trials: trials,
|
||||
}
|
||||
})
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
import * as plotly from "plotly.js-dist"
|
||||
import React, { FC, useEffect } from "react"
|
||||
|
||||
const plotDomId = "graph-pareto-front"
|
||||
|
||||
export const GraphParetoFront: FC<{
|
||||
study: StudyDetail | null
|
||||
}> = ({ study = null }) => {
|
||||
|
||||
useEffect(() => {
|
||||
if (study != null) {
|
||||
plotParetoFront(study)
|
||||
}
|
||||
}, [study])
|
||||
|
||||
return <div id={plotDomId} />
|
||||
}
|
||||
|
||||
const plotParetoFront = (study: StudyDetail) => {
|
||||
if (document.getElementById(plotDomId) === null) {
|
||||
return
|
||||
}
|
||||
|
||||
if (study.directions.length != 2) {
|
||||
return
|
||||
}
|
||||
|
||||
const layout: Partial<plotly.Layout> = {
|
||||
title: "Pareto-front plot",
|
||||
margin: {
|
||||
l: 50,
|
||||
r: 50,
|
||||
b: 0,
|
||||
},
|
||||
}
|
||||
|
||||
const trials: Trial[] = (study !== null) && study.best_trials ? study.best_trials : []
|
||||
console.log(study.best_trials)
|
||||
console.log('length', trials.length)
|
||||
if (trials.length === 0) {
|
||||
plotly.react(plotDomId, [], layout)
|
||||
return
|
||||
}
|
||||
|
||||
const pointColors = Array(trials.length).fill("blue")
|
||||
|
||||
const plotData: Partial<plotly.PlotData>[] = [
|
||||
{
|
||||
type: "scatter",
|
||||
x: trials.map((t: Trial): number => t.values![0]),
|
||||
y: trials.map((t: Trial): number => t.values![1]),
|
||||
mode: "markers",
|
||||
marker: {
|
||||
color: pointColors,
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
plotly.react(plotDomId, plotData, layout)
|
||||
}
|
||||
@@ -23,6 +23,7 @@ import { GraphParallelCoordinate } from "./GraphParallelCoordinate"
|
||||
import { GraphIntermediateValues } from "./GraphIntermediateValues"
|
||||
import { GraphSlice } from "./GraphSlice"
|
||||
import { GraphHistory } from "./GraphHistory"
|
||||
import { GraphParetoFront } from "./GraphParetoFront"
|
||||
import { actionCreator } from "../action"
|
||||
import { studyDetailsState } from "../state"
|
||||
|
||||
@@ -203,6 +204,13 @@ export const StudyDetail: FC = () => {
|
||||
</CardContent>
|
||||
</Card>
|
||||
) : null}
|
||||
{studyDetail !== null && !isSingleObjectiveStudy(studyDetail) ? (
|
||||
<Card className={classes.card}>
|
||||
<CardContent>
|
||||
<GraphParetoFront study={studyDetail} />
|
||||
</CardContent>
|
||||
</Card>
|
||||
) : null}
|
||||
<Card className={classes.card}>
|
||||
<TrialTable studyDetail={studyDetail} />
|
||||
</Card>
|
||||
|
||||
+1
@@ -54,6 +54,7 @@ declare interface StudyDetail {
|
||||
directions: StudyDirection[]
|
||||
datetime_start: Date
|
||||
best_trial?: Trial
|
||||
best_trials?: Trial[]
|
||||
trials: Trial[]
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user