Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/support grid sampler #23

Merged
merged 2 commits into from
May 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ Please see [here](https://github.com/hrntsm/Tunny/releases) for the data release

- Restore progressbar
- Support Galapagos genepool input
- Reflect button
- Result reflect button
- This feature reflecting multi objective optimization result to slider & genepool to use input model number.
- if input multi model number, the first one is reflect and popup notification about this.
- Support grid sampler

### Changed

Expand Down
23 changes: 22 additions & 1 deletion Tunny/Solver/OptunaAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ public void Solve()
case "NSGA-II":
sampler = optuna.samplers.NSGAIISampler();
break;
case "Grid":
var searchSpace = new Dictionary<string, List<double>>();
for (int i = 0; i < n; i++)
{
var numSpace = new List<double>();
for (int j = 0; j < nTrials; j++)
{
numSpace.Add(Lb[i] + (Ub[i] - Lb[i]) * j / (nTrials - 1));
}
searchSpace.Add(VarNickName[i], numSpace);
}
nTrials = (int)Math.Pow(nTrials, n);
sampler = optuna.samplers.GridSampler(searchSpace);
break;
default:
sampler = optuna.samplers.TPESampler();
break;
Expand Down Expand Up @@ -116,7 +130,14 @@ public void Solve()
}
}
trial.set_user_attr("geometry", result.ModelDraco);
study.tell(trial, result.ObjectiveValues.ToArray());
try
{
study.tell(trial, result.ObjectiveValues.ToArray());
}
catch
{
break;
}
}

if (nObjective == 1)
Expand Down
3 changes: 2 additions & 1 deletion Tunny/UI/OptimizationWindow.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions Tunny/UI/OptimizationWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,15 @@ private void OptimizeRunButton_Click(object sender, EventArgs e)
optimizeRunButton.Enabled = true;
return;
}
else if (objectiveValues.Count > 1 && (samplerComboBox.Text == "CMA-ES" || samplerComboBox.Text == "Random"))
else if (objectiveValues.Count > 1
&& (samplerComboBox.Text == "CMA-ES" || samplerComboBox.Text == "Random" || samplerComboBox.Text == "Grid"))
{
MessageBox.Show("This sampler does not support multiple objectives optimization.", "Tunny", MessageBoxButtons.OK, MessageBoxIcon.Error);
TunnyMessageBox.Show(
"CMA-ES, Random and Grid samplers only support single objective optimization.",
"Tunny",
MessageBoxButtons.OK,
MessageBoxIcon.Error
);
ghCanvas.EnableUI();
optimizeRunButton.Enabled = true;
return;
Expand Down