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

Fix/seed value is not used #198

Merged
merged 6 commits into from
Sep 12, 2023
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
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,36 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

Please see [here](https://github.com/hrntsm/Tunny/releases) for the data released for each version.

## [UNRELEASED] -yyyy-mm-dd

### Added

for new features.

- Added the seed value can be specified in BayesianOptimization(GP).

### Changed

for changes in existing functionality.

### Deprecated

for soon-to-be removed features.

### Removed

for now removed features.

### Fixed

for any bug fixes.

- The seed value of the sampler was not used.

### Security

in case of vulnerabilities.

## [v0.8.2] -2023-09-04

### Changed
Expand Down
1 change: 1 addition & 0 deletions Tunny/Settings/Sampler/BoTorch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace Tunny.Settings.Sampler
/// </summary>
public class BoTorch
{
public int? Seed { get; set; }
public int NStartupTrials { get; set; } = 10;
}
}
1 change: 1 addition & 0 deletions Tunny/Solver/Sampler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ internal static dynamic BoTorch(dynamic optuna, TunnySettings settings, bool has
{
BoTorch boTorch = settings.Optimize.Sampler.BoTorch;
return optuna.integration.BoTorchSampler(
seed: boTorch.Seed,
n_startup_trials: boTorch.NStartupTrials,
constraints_func: hasConstraints ? ConstraintFunc() : null
);
Expand Down
2 changes: 1 addition & 1 deletion Tunny/UI/OptimizationWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ private void GetUIValues()
_settings.Result.SelectVisualizeType = visualizeTypeComboBox.SelectedIndex;
_settings.Result.NumberOfClusters = (int)visualizeClusterNumUpDown.Value;
_settings.CheckPythonLibraries = checkPythonLibrariesCheckBox.Checked;
_settings.Optimize.Sampler = GetSamplerSettings();
_settings.Optimize.Sampler = GetSamplerSettings(_settings.Optimize.Sampler);
_settings.Optimize.GcAfterTrial = (GcAfterTrial)runGarbageCollectionComboBox.SelectedIndex;
}
}
Expand Down
141 changes: 64 additions & 77 deletions Tunny/UI/OptimizeWindowTab/SettingsTab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,101 +194,88 @@ private void SetQMCSettings(QuasiMonteCarlo qmc)
qmcWarnAsyncSeedingCheckBox.Checked = qmc.WarnAsynchronousSeeding;
}

private SamplerSettings GetSamplerSettings()
private SamplerSettings GetSamplerSettings(SamplerSettings sampler)
{
return new SamplerSettings
{
Tpe = GetTpeSettings(),
BoTorch = GetBoTorchSettings(),
NsgaII = GetNsga2Settings(),
NsgaIII = GetNsga3Settings(),
CmaEs = GetCmaEsSettings(),
QMC = GetQMCSettings()
};
sampler.Tpe = GetTpeSettings(sampler.Tpe);
sampler.BoTorch = GetBoTorchSettings(sampler.BoTorch);
sampler.NsgaII = GetNsga2Settings(sampler.NsgaII);
sampler.NsgaIII = GetNsga3Settings(sampler.NsgaIII);
sampler.CmaEs = GetCmaEsSettings(sampler.CmaEs);
sampler.QMC = GetQMCSettings(sampler.QMC);
return sampler;
}

private Tpe GetTpeSettings()
private Tpe GetTpeSettings(Tpe tpe)
{
return new Tpe
{
NStartupTrials = (int)tpeStartupNumUpDown.Value,
NEICandidates = (int)tpeEINumUpDown.Value,
PriorWeight = (double)tpePriorNumUpDown.Value,
ConsiderPrior = tpeConsiderPriorCheckBox.Checked,
Multivariate = tpeMultivariateCheckBox.Checked,
ConsiderEndpoints = tpeConsiderEndpointsCheckBox.Checked,
Group = tpeGroupCheckBox.Checked,
ConsiderMagicClip = tpeConsiderMagicClipCheckBox.Checked,
ConstantLiar = tpeConstantLiarCheckBox.Checked,
WarnIndependentSampling = tpeWarnIndependentSamplingCheckBox.Checked
};
tpe.NStartupTrials = (int)tpeStartupNumUpDown.Value;
tpe.NEICandidates = (int)tpeEINumUpDown.Value;
tpe.PriorWeight = (double)tpePriorNumUpDown.Value;
tpe.ConsiderPrior = tpeConsiderPriorCheckBox.Checked;
tpe.Multivariate = tpeMultivariateCheckBox.Checked;
tpe.ConsiderEndpoints = tpeConsiderEndpointsCheckBox.Checked;
tpe.Group = tpeGroupCheckBox.Checked;
tpe.ConsiderMagicClip = tpeConsiderMagicClipCheckBox.Checked;
tpe.ConstantLiar = tpeConstantLiarCheckBox.Checked;
tpe.WarnIndependentSampling = tpeWarnIndependentSamplingCheckBox.Checked;
return tpe;
}

private BoTorch GetBoTorchSettings()
private BoTorch GetBoTorchSettings(BoTorch boTorch)
{
return new BoTorch
{
NStartupTrials = (int)boTorchStartupNumUpDown.Value
};
boTorch.NStartupTrials = (int)boTorchStartupNumUpDown.Value;
return boTorch;
}

private NSGAII GetNsga2Settings()
private NSGAII GetNsga2Settings(NSGAII nsgaII)
{
return new NSGAII
{
MutationProb = nsga2MutationProbCheckBox.Checked
? (double?)nsga2MutationProbUpDown.Value : null,
CrossoverProb = (double)nsga2CrossoverProbUpDown.Value,
SwappingProb = (double)nsga2SwappingProbUpDown.Value,
PopulationSize = (int)nsga2PopulationSizeUpDown.Value,
Crossover = nsga2CrossoverCheckBox.Checked
? nsga2CrossoverComboBox.Text : string.Empty,
};
nsgaII.MutationProb = nsga2MutationProbCheckBox.Checked
? (double?)nsga2MutationProbUpDown.Value : null;
nsgaII.CrossoverProb = (double)nsga2CrossoverProbUpDown.Value;
nsgaII.SwappingProb = (double)nsga2SwappingProbUpDown.Value;
nsgaII.PopulationSize = (int)nsga2PopulationSizeUpDown.Value;
nsgaII.Crossover = nsga2CrossoverCheckBox.Checked
? nsga2CrossoverComboBox.Text : string.Empty;
return nsgaII;
}

private NSGAIII GetNsga3Settings()
private NSGAIII GetNsga3Settings(NSGAIII nsgaIII)
{
return new NSGAIII
{
MutationProb = nsga3MutationProbCheckBox.Checked
? (double?)nsga3MutationProbUpDown.Value : null,
CrossoverProb = (double)nsga3CrossoverProbUpDown.Value,
SwappingProb = (double)nsga3SwappingProbUpDown.Value,
PopulationSize = (int)nsga3PopulationSizeUpDown.Value,
Crossover = nsga3CrossoverCheckBox.Checked
? nsga3CrossoverComboBox.Text : string.Empty,
};
nsgaIII.MutationProb = nsga3MutationProbCheckBox.Checked
? (double?)nsga3MutationProbUpDown.Value : null;
nsgaIII.CrossoverProb = (double)nsga3CrossoverProbUpDown.Value;
nsgaIII.SwappingProb = (double)nsga3SwappingProbUpDown.Value;
nsgaIII.PopulationSize = (int)nsga3PopulationSizeUpDown.Value;
nsgaIII.Crossover = nsga3CrossoverCheckBox.Checked
? nsga3CrossoverComboBox.Text : string.Empty;
return nsgaIII;
}
private CmaEs GetCmaEsSettings()

private CmaEs GetCmaEsSettings(CmaEs cmaEs)
{
return new CmaEs
{
NStartupTrials = (int)cmaEsStartupNumUpDown.Value,
Sigma0 = cmaEsSigmaCheckBox.Checked
? (double?)cmaEsSigmaNumUpDown.Value : null,
WarnIndependentSampling = cmaEsWarnIndependentSamplingCheckBox.Checked,
ConsiderPrunedTrials = cmaEsConsiderPruneTrialsCheckBox.Checked,
UseSeparableCma = cmaEsUseSaparableCmaCheckBox.Checked,
RestartStrategy = cmaEsRestartCheckBox.Checked
? "ipop" : string.Empty,
IncPopsize = (int)cmaEsIncPopSizeUpDown.Value,
PopulationSize = cmaEsRestartCheckBox.Checked
? (int?)cmaEsPopulationSizeUpDown.Value : null,
UseWarmStart = cmaEsWarmStartCmaEsCheckBox.Checked,
WarmStartStudyName = cmaEsWarmStartComboBox.Text,
WithMargin = cmaEsWithMarginCheckBox.Checked,
};
cmaEs.NStartupTrials = (int)cmaEsStartupNumUpDown.Value;
cmaEs.Sigma0 = cmaEsSigmaCheckBox.Checked
? (double?)cmaEsSigmaNumUpDown.Value : null;
cmaEs.WarnIndependentSampling = cmaEsWarnIndependentSamplingCheckBox.Checked;
cmaEs.ConsiderPrunedTrials = cmaEsConsiderPruneTrialsCheckBox.Checked;
cmaEs.UseSeparableCma = cmaEsUseSaparableCmaCheckBox.Checked;
cmaEs.RestartStrategy = cmaEsRestartCheckBox.Checked
? "ipop" : string.Empty;
cmaEs.IncPopsize = (int)cmaEsIncPopSizeUpDown.Value;
cmaEs.PopulationSize = cmaEsRestartCheckBox.Checked
? (int?)cmaEsPopulationSizeUpDown.Value : null;
cmaEs.UseWarmStart = cmaEsWarmStartCmaEsCheckBox.Checked;
cmaEs.WarmStartStudyName = cmaEsWarmStartComboBox.Text;
cmaEs.WithMargin = cmaEsWithMarginCheckBox.Checked;
return cmaEs;
}

private QuasiMonteCarlo GetQMCSettings()
private QuasiMonteCarlo GetQMCSettings(QuasiMonteCarlo qmc)
{
return new QuasiMonteCarlo
{
QmcType = qmcTypeComboBox.SelectedIndex == 0 ? "sobol" : "halton",
Scramble = qmcScrambleCheckBox.Checked,
WarnIndependentSampling = qmcWarnIndependentSamplingCheckBox.Checked,
WarnAsynchronousSeeding = qmcWarnAsyncSeedingCheckBox.Checked
};
qmc.QmcType = qmcTypeComboBox.SelectedIndex == 0 ? "sobol" : "halton";
qmc.Scramble = qmcScrambleCheckBox.Checked;
qmc.WarnIndependentSampling = qmcWarnIndependentSamplingCheckBox.Checked;
qmc.WarnAsynchronousSeeding = qmcWarnAsyncSeedingCheckBox.Checked;
return qmc;
}

private void RunGarbageCollectionComboBox_SelectedIndexChanged(object sender, EventArgs e)
Expand Down
Loading