Skip to content

Commit

Permalink
Merge pull request optuna#988 from porink0424/fix/categorical-choice-…
Browse files Browse the repository at this point in the history
…type

Fix a contour plot visualization issue with categorical parameters
  • Loading branch information
c-bata authored Nov 6, 2024
2 parents b6bcbcf + ecf4730 commit 3c2c555
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 33 deletions.
2 changes: 1 addition & 1 deletion optuna_dashboard/ts/graphUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const getAxisInfoForCategoricalParams = (
)

const indices = distribution.choices
.map((c) => c?.toString() ?? "null")
.map((c) => c?.value ?? "null")
.sort((a, b) =>
a.toLowerCase() < b.toLowerCase()
? -1
Expand Down
2 changes: 1 addition & 1 deletion tslib/react/src/components/PlotTimeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Card, CardContent, Grid, Typography, useTheme } from "@mui/material"
import * as Optuna from "@optuna/types"
import * as plotly from "plotly.js-dist-min"
import { FC, useEffect } from "react"
import { makeHovertext } from "../utils/graphUtil"
import { makeHovertext } from "../utils/graph"
import { plotlyDarkTemplate } from "./PlotlyDarkMode"

const plotDomId = "graph-timeline"
Expand Down
15 changes: 6 additions & 9 deletions tslib/react/src/utils/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ export const makeHovertext = (trial: Optuna.Trial): string => {
{
number: trial.number,
values: trial.values,
params: trial.params
.map((p) => [p.name, p.param_external_value])
.reduce(
(obj, [key, value]) => {
obj[key as string] = value
return obj
},
{} as Record<string, Optuna.CategoricalChoiceType>
),
params: trial.params.reduce<{
[key: string]: string
}>((obj, p) => {
obj[p.name] = p.param_external_value
return obj
}, {}),
},
undefined,
" "
Expand Down
18 changes: 0 additions & 18 deletions tslib/react/src/utils/graphUtil.ts

This file was deleted.

4 changes: 2 additions & 2 deletions tslib/storage/src/sqlite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,14 +330,14 @@ const getTrialParams = (
const paramInternalValueToExternalValue = (
distribution: Optuna.Distribution,
internalValue: number
): Optuna.CategoricalChoiceType => {
) => {
if (distribution.type === "FloatDistribution") {
return internalValue.toString()
}
if (distribution.type === "IntDistribution") {
return internalValue.toString()
}
return distribution.choices[internalValue]
return distribution.choices[internalValue].value
}

const parseDistributionJSON = (t: string): Optuna.Distribution => {
Expand Down
7 changes: 5 additions & 2 deletions tslib/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ export type IntDistribution = {
log: boolean
}

export type CategoricalChoiceType = null | boolean | number | string
export type CategoricalChoiceType = {
pytype: string
value: string
}

export type CategoricalDistribution = {
type: "CategoricalDistribution"
Expand Down Expand Up @@ -80,7 +83,7 @@ export type Trial = {
export type TrialParam = {
name: string
param_internal_value: number
param_external_value: CategoricalChoiceType
param_external_value: string
param_external_type: string
distribution: Distribution
}
Expand Down

0 comments on commit 3c2c555

Please sign in to comment.