Skip to content

Commit

Permalink
Merge pull request #689 from eukaryo/rank-plot-plus-constraint
Browse files Browse the repository at this point in the history
Support constrained optimization for rank plot
  • Loading branch information
keisuke-umezawa authored Nov 9, 2023
2 parents bdeb664 + 9182fba commit 14c57ad
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions optuna_dashboard/ts/components/GraphRank.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ interface RankPlotInfo {
yvalues: (string | number)[]
zvalues: number[]
colors: number[]
is_feasible: boolean[]
hovertext: string[]
}

Expand Down Expand Up @@ -156,6 +157,7 @@ const getRankPlotInfo = (
const xValues: (string | number)[] = []
const yValues: (string | number)[] = []
const zValues: number[] = []
const isFeasible: boolean[] = []
const hovertext: string[] = []
filteredTrials.forEach((trial) => {
const xValue =
Expand All @@ -168,9 +170,11 @@ const getRankPlotInfo = (
return
}
const zValue = Number(trial.values[objectiveId])
const feasibility = trial.constraints.every((c) => c <= 0)
xValues.push(xValue)
yValues.push(yValue)
zValues.push(zValue)
isFeasible.push(feasibility)
hovertext.push(makeHovertext(trial))
})

Expand All @@ -183,6 +187,7 @@ const getRankPlotInfo = (
yvalues: yValues,
zvalues: zValues,
colors,
is_feasible: isFeasible,
hovertext,
}
}
Expand Down Expand Up @@ -362,10 +367,12 @@ const plotRank = (rankPlotInfo: RankPlotInfo | null, mode: string) => {
const plotData: Partial<plotly.PlotData>[] = [
{
type: "scatter",
x: xValues,
y: yValues,
x: xValues.filter((_, i) => rankPlotInfo.is_feasible[i]),
y: yValues.filter((_, i) => rankPlotInfo.is_feasible[i]),
marker: {
color: rankPlotInfo.colors,
color: rankPlotInfo.colors.filter(
(_, i) => rankPlotInfo.is_feasible[i]
),
colorscale: "Portland",
colorbar: {
title: "Rank",
Expand All @@ -379,7 +386,28 @@ const plotRank = (rankPlotInfo: RankPlotInfo | null, mode: string) => {
mode: "markers",
showlegend: false,
hovertemplate: "%{hovertext}<extra></extra>",
hovertext: rankPlotInfo.hovertext,
hovertext: rankPlotInfo.hovertext.filter(
(_, i) => rankPlotInfo.is_feasible[i]
),
},
{
type: "scatter",
x: xValues.filter((_, i) => !rankPlotInfo.is_feasible[i]),
y: yValues.filter((_, i) => !rankPlotInfo.is_feasible[i]),
marker: {
color: "#cccccc",
size: 10,
line: {
color: "Grey",
width: 0.5,
},
},
mode: "markers",
showlegend: false,
hovertemplate: "%{hovertext}<extra></extra>",
hovertext: rankPlotInfo.hovertext.filter(
(_, i) => !rankPlotInfo.is_feasible[i]
),
},
]
plotly.react(plotDomId, plotData, layout)
Expand Down

0 comments on commit 14c57ad

Please sign in to comment.