Skip to content

Commit

Permalink
Merge branch 'main' into add_upload_study_artifact_api
Browse files Browse the repository at this point in the history
  • Loading branch information
gen740 committed Nov 10, 2023
2 parents 7dbef50 + 14c57ad commit dd91693
Show file tree
Hide file tree
Showing 13 changed files with 565 additions and 83 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
python-version: '3.11'
architecture: x64
- name: Install dependencies
run: |
Expand Down
4 changes: 2 additions & 2 deletions docs/tutorials/preferential-optimization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ What is Preferential Optimization?
----------------------------------

Preferential optimization is a method for optimizing hyperparameters, focusing of human preferences, by determining which trial is superior when comparing a pair.
It differs from `human-in-the-loop optimization utilizing objective form widgets <tutorial-hitl-objective-form-widgets>`_,
It differs from :ref:`human-in-the-loop optimization utilizing objective form widgets <tutorial-hitl-objective-form-widgets>`,
which relies on absolute evaluations, as it significantly reduces fluctuations in evaluators' criteria, thus ensuring more consistent results.

In this tutorial, we'll interactively optimize RGB values to generate a color resembling a "sunset hue",
aligining with the problem setting in `this tutorial <tutorial-hitl-objective-form-widgets>`_.
aligining with the problem setting in :ref:`this tutorial <tutorial-hitl-objective-form-widgets>`.
Familiarity with the tutorial ob objective form widgets may enhance your understanding.

How to Run Preferential Optimization
Expand Down
18 changes: 9 additions & 9 deletions optuna_dashboard/preferential/samplers/gp.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ def _orthants_MVN_Gibbs_sampling(cov_inv: Tensor, cycles: int, initial_sample: T


def _one_side_trunc_norm_sampling(lower: Tensor) -> Tensor:
if lower > 4.0:
r = torch.clamp_min(torch.rand(torch.Size(()), dtype=torch.float64), min=1e-300)
return (lower * lower - 2 * r.log()).sqrt()
else:
SQRT2 = math.sqrt(2)
r = torch.rand(torch.Size(()), dtype=torch.float64) * torch.erfc(lower / SQRT2)
while 1 - r == 1:
r = torch.rand(torch.Size(()), dtype=torch.float64) * torch.erfc(lower / SQRT2)
return torch.erfinv(1 - r) * SQRT2
r = torch.rand(torch.Size(()), dtype=torch.float64)
ret = -torch.special.ndtri(torch.exp(torch.special.log_ndtr(-lower) + r.log()))

# If sampled random number is very small, `ret` becomes inf.
while torch.isinf(ret):
r = torch.rand(torch.Size(()), dtype=torch.float64)
ret = -torch.special.ndtri(torch.exp(torch.special.log_ndtr(-lower) + r.log()))

return ret


_orthants_MVN_Gibbs_sampling_jit = torch.jit.script(_orthants_MVN_Gibbs_sampling)
Expand Down
7 changes: 5 additions & 2 deletions optuna_dashboard/ts/components/DataGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ interface DataGridColumn<T> {
field: keyof T
label: string
sortable?: boolean
less?: (a: T, b: T) => number
less?: (a: T, b: T, ascending: boolean) => number
filterable?: boolean
toCellValue?: (rowIndex: number) => string | React.ReactNode
padding?: "normal" | "checkbox" | "none"
Expand Down Expand Up @@ -358,7 +358,10 @@ function stableSort<T>(
const stabilizedThis = array.map((el, index) => [el, index] as [T, number])
stabilizedThis.sort((a, b) => {
if (less) {
const result = order == "asc" ? -less(a[0], b[0]) : less(a[0], b[0])
const ascending = order == "asc"
const result = ascending
? -less(a[0], b[0], ascending)
: less(a[0], b[0], ascending)
if (result !== 0) return result
} else {
const result = comparator(a[0], b[0])
Expand Down
16 changes: 14 additions & 2 deletions optuna_dashboard/ts/components/GraphContour.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,16 @@ const plotContour = (
const xValues: plotly.Datum[] = []
const yValues: plotly.Datum[] = []
const zValues: plotly.Datum[][] = new Array(yIndices.length)
const feasibleXY = new Set<number>()
for (let j = 0; j < yIndices.length; j++) {
zValues[j] = new Array(xIndices.length).fill(null)
}

filteredTrials.forEach((trial, i) => {
if (xAxis.values[i] && yAxis.values[i] && trial.values) {
if (trial.constraints.every((c) => c <= 0)) {
feasibleXY.add(xValues.length)
}
const xValue = xAxis.values[i] as string | number
const yValue = yAxis.values[i] as string | number
xValues.push(xValue)
Expand Down Expand Up @@ -234,12 +238,20 @@ const plotContour = (
},
{
type: "scatter",
x: xValues,
y: yValues,
x: xValues.filter((_, i) => feasibleXY.has(i)),
y: yValues.filter((_, i) => feasibleXY.has(i)),
marker: { line: { width: 2.0, color: "Grey" }, color: "black" },
mode: "markers",
showlegend: false,
},
{
type: "scatter",
x: xValues.filter((_, i) => !feasibleXY.has(i)),
y: yValues.filter((_, i) => !feasibleXY.has(i)),
marker: { line: { width: 2.0, color: "Grey" }, color: "#cccccc" },
mode: "markers",
showlegend: false,
},
]
plotly.react(plotDomId, plotData, layout)
return
Expand Down
13 changes: 9 additions & 4 deletions optuna_dashboard/ts/components/GraphIntermediateValues.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,21 @@ const plotIntermediateValue = (
const values = trial.intermediate_values.filter(
(iv) => iv.value !== "inf" && iv.value !== "-inf" && iv.value !== "nan"
)
const isFeasible = trial.constraints.every((c) => c <= 0)
return {
x: values.map((iv) => iv.step),
y: values.map((iv) => iv.value),
marker: { maxdisplayed: 10 },
mode: "lines+markers",
type: "scatter",
name:
trial.state !== "Running"
? `trial #${trial.number}`
: `trial #${trial.number} (running)`,
name: `trial #${trial.number} ${
trial.state === "Running"
? "(running)"
: !isFeasible
? "(infeasible)"
: ""
}`,
...(!isFeasible && { line: { color: "#CCCCCC" } }),
}
})
plotly.react(plotDomId, plotData, layout)
Expand Down
Loading

0 comments on commit dd91693

Please sign in to comment.