From 8ebed9b99ce65889bc596ded7c0fed101eeb3732 Mon Sep 17 00:00:00 2001 From: Contramundum Date: Thu, 14 Dec 2023 13:47:03 +0900 Subject: [PATCH] fix pareto-front --- .../ts/components/GraphParetoFront.tsx | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/optuna_dashboard/ts/components/GraphParetoFront.tsx b/optuna_dashboard/ts/components/GraphParetoFront.tsx index 88eea2e7..155c03b8 100644 --- a/optuna_dashboard/ts/components/GraphParetoFront.tsx +++ b/optuna_dashboard/ts/components/GraphParetoFront.tsx @@ -181,20 +181,38 @@ const getIsDominatedTrialND = (normalizedValues: number[][]) => { } const getIsDominatedTrial2D = (normalizedValues: number[][]) => { + if (normalizedValues.length === 0) { + return [] + } // Fast pareto front algorithm (O(N log N) complexity). const sorted = normalizedValues .map((values, i) => [values[0], values[1], i]) - .sort() + .sort((a, b) => + a[0] > b[0] + ? 1 + : a[0] < b[0] + ? -1 + : a[1] > b[1] + ? 1 + : a[1] < b[1] + ? -1 + : 0 + ) + let maxValue0 = sorted[0][0] let minValue1 = sorted[0][1] - const dominatedTrials: boolean[] = new Array(normalizedValues.length).fill( - true - ) + const dominatedTrials: boolean[] = new Array(normalizedValues.length).fill( + false + ) sorted.forEach((values) => { - if (values[1] <= minValue1) { - dominatedTrials[values[2]] = false + if ( + values[1] > minValue1 || + (values[1] >= minValue1 && values[0] > maxValue0) + ) { + dominatedTrials[values[2]] = true minValue1 = values[1] } + maxValue0 = values[0] }) return dominatedTrials }