From 8be7600ec88684275c5c17940ac70196a9111521 Mon Sep 17 00:00:00 2001 From: porink0424 Date: Fri, 16 Feb 2024 18:57:37 +0900 Subject: [PATCH 1/2] Drop inf & -inf from TrialValueNumber --- standalone_app/src/components/PlotHistory.tsx | 6 +++--- standalone_app/src/components/PlotImportance.tsx | 4 ++-- standalone_app/src/components/TrialTable.tsx | 10 ---------- standalone_app/src/sqlite3.ts | 6 +++--- standalone_app/src/types/index.d.ts | 2 +- 5 files changed, 9 insertions(+), 19 deletions(-) diff --git a/standalone_app/src/components/PlotHistory.tsx b/standalone_app/src/components/PlotHistory.tsx index 24f90034..b94c5ac8 100644 --- a/standalone_app/src/components/PlotHistory.tsx +++ b/standalone_app/src/components/PlotHistory.tsx @@ -178,8 +178,8 @@ const filterFunc = (trial: Trial, objectiveId: number): boolean => { } return ( trial.values.length > objectiveId && - trial.values[objectiveId] !== "inf" && - trial.values[objectiveId] !== "-inf" + trial.values[objectiveId] !== Infinity && + trial.values[objectiveId] !== -Infinity ) } @@ -244,7 +244,7 @@ const plotHistory = ( return null } const value = trial.values[objectiveId] - if (value === "inf" || value === "-inf") { + if (value === Infinity || value === -Infinity) { return null } return value diff --git a/standalone_app/src/components/PlotImportance.tsx b/standalone_app/src/components/PlotImportance.tsx index 8135be26..5b4baf02 100644 --- a/standalone_app/src/components/PlotImportance.tsx +++ b/standalone_app/src/components/PlotImportance.tsx @@ -80,8 +80,8 @@ const filterFunc = (trial: Trial, objectiveId: number): boolean => { } return ( trial.values.length > objectiveId && - trial.values[objectiveId] !== "inf" && - trial.values[objectiveId] !== "-inf" + trial.values[objectiveId] !== Infinity && + trial.values[objectiveId] !== -Infinity ) } diff --git a/standalone_app/src/components/TrialTable.tsx b/standalone_app/src/components/TrialTable.tsx index d8b4f163..41cabdd4 100644 --- a/standalone_app/src/components/TrialTable.tsx +++ b/standalone_app/src/components/TrialTable.tsx @@ -37,11 +37,6 @@ export const TrialTable: FC<{ } else if (secondVal === undefined) { return ascending ? 1 : -1 } - if (firstVal === "-inf" || secondVal === "inf") { - return 1 - } else if (secondVal === "-inf" || firstVal === "inf") { - return -1 - } return firstVal < secondVal ? 1 : -1 }, toCellValue: (i) => { @@ -69,11 +64,6 @@ export const TrialTable: FC<{ } else if (secondVal === undefined) { return ascending ? 1 : -1 } - if (firstVal === "-inf" || secondVal === "inf") { - return 1 - } else if (secondVal === "-inf" || firstVal === "inf") { - return -1 - } return firstVal < secondVal ? 1 : -1 }, toCellValue: (i) => { diff --git a/standalone_app/src/sqlite3.ts b/standalone_app/src/sqlite3.ts index a0bf018b..682bf803 100644 --- a/standalone_app/src/sqlite3.ts +++ b/standalone_app/src/sqlite3.ts @@ -389,11 +389,11 @@ const getTrialIntermediateValues = ( step: vals[0], value: vals[2] === "INF_NEG" - ? "-inf" + ? -Infinity : vals[2] === "INF_POS" - ? "+inf" + ? Infinity : vals[2] === "NAN" - ? "nan" + ? NaN : vals[1], }) }, diff --git a/standalone_app/src/types/index.d.ts b/standalone_app/src/types/index.d.ts index da00a7aa..e379a926 100644 --- a/standalone_app/src/types/index.d.ts +++ b/standalone_app/src/types/index.d.ts @@ -1,6 +1,6 @@ declare const IS_VSCODE: boolean -type TrialValueNumber = number | "inf" | "-inf" +type TrialValueNumber = number type TrialIntermediateValueNumber = number | "inf" | "-inf" | "nan" type TrialState = "Running" | "Complete" | "Pruned" | "Fail" | "Waiting" type TrialStateFinished = "Complete" | "Fail" | "Pruned" From b976fa1aedf1cacdb5482b78e31f7161163b55f6 Mon Sep 17 00:00:00 2001 From: keisuke-umezawa Date: Sun, 25 Feb 2024 20:55:57 +0900 Subject: [PATCH 2/2] Follow review comments --- standalone_app/src/components/PlotIntermediateValues.tsx | 5 ++++- standalone_app/src/sqlite3.ts | 4 ++-- standalone_app/src/types/index.d.ts | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/standalone_app/src/components/PlotIntermediateValues.tsx b/standalone_app/src/components/PlotIntermediateValues.tsx index 2c10cf74..fbf8cc2a 100644 --- a/standalone_app/src/components/PlotIntermediateValues.tsx +++ b/standalone_app/src/components/PlotIntermediateValues.tsx @@ -80,7 +80,10 @@ const plotIntermediateValue = ( ) const plotData: Partial[] = filteredTrials.map((trial) => { const values = trial.intermediate_values.filter( - (iv) => iv.value !== "inf" && iv.value !== "-inf" && iv.value !== "nan" + (iv) => + iv.value !== Infinity && + iv.value !== -Infinity && + !Number.isNaN(iv.value) ) return { x: values.map((iv) => iv.step), diff --git a/standalone_app/src/sqlite3.ts b/standalone_app/src/sqlite3.ts index 682bf803..0330750b 100644 --- a/standalone_app/src/sqlite3.ts +++ b/standalone_app/src/sqlite3.ts @@ -218,9 +218,9 @@ const getTrialValues = ( callback: (vals: any[]) => { values.push( vals[1] === "INF_NEG" - ? "-inf" + ? -Infinity : vals[1] === "INF_POS" - ? "+inf" + ? Infinity : vals[0] ) }, diff --git a/standalone_app/src/types/index.d.ts b/standalone_app/src/types/index.d.ts index e379a926..684858e9 100644 --- a/standalone_app/src/types/index.d.ts +++ b/standalone_app/src/types/index.d.ts @@ -1,7 +1,7 @@ declare const IS_VSCODE: boolean type TrialValueNumber = number -type TrialIntermediateValueNumber = number | "inf" | "-inf" | "nan" +type TrialIntermediateValueNumber = number type TrialState = "Running" | "Complete" | "Pruned" | "Fail" | "Waiting" type TrialStateFinished = "Complete" | "Fail" | "Pruned" type StudyDirection = "maximize" | "minimize" | "not_set"