Changeset 14833
- Timestamp:
- 04/07/17 09:34:44 (8 years ago)
- Location:
- branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO
- Files:
-
- 5 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/EfficientGlobalOptimizationAlgorithm.cs
r14818 r14833 69 69 private const string InitialSamplesParameterName = "InitialSamplesFile"; 70 70 private const string BaselineVectorParameterName = "BaselineVector"; 71 private const string InitialSamplingPlanParamterName = "InitialSamplingPlan"; 71 72 #endregion 72 73 … … 101 102 public IFixedValueParameter<IntValue> MaximalDataSetSizeParameter => Parameters[MaximalDataSetSizeParameterName] as IFixedValueParameter<IntValue>; 102 103 public IFixedValueParameter<BoolValue> RemoveDuplicatesParameter => Parameters[RemoveDuplicatesParamterName] as IFixedValueParameter<BoolValue>; 103 104 104 public IFixedValueParameter<FileValue> InitialSamplesParameter => Parameters[InitialSamplesParameterName] as IFixedValueParameter<FileValue>; 105 106 105 public IValueParameter<RealVector> BaselineVectorParameter => Parameters[BaselineVectorParameterName] as IValueParameter<RealVector>; 106 public IConstrainedValueParameter<IInitialSampling> InitialSamplingPlanParameter => Parameters[InitialSamplingPlanParamterName] as IConstrainedValueParameter<IInitialSampling>; 107 107 #endregion 108 108 … … 126 126 private bool RemoveDuplicates => RemoveDuplicatesParameter.Value.Value; 127 127 private RealVector BaselineVector => BaselineVectorParameter.Value; 128 private IInitialSampling InitialSamplingPlan => InitialSamplingPlanParameter.Value; 128 129 #endregion 129 130 … … 198 199 Parameters.Add(new FixedValueParameter<IntValue>(MaximumEvaluationsParameterName, "", new IntValue(int.MaxValue))); 199 200 Parameters.Add(new FixedValueParameter<IntValue>(InitialEvaluationsParameterName, "", new IntValue(10))); 200 Parameters.Add(new FixedValueParameter<IntValue>(MaximumRuntimeParameterName, "The maximum runtime in seconds after which the algorithm stops. Use -1 to specify no limit for the runtime", new IntValue( 3600)));201 Parameters.Add(new FixedValueParameter<IntValue>(MaximumRuntimeParameterName, "The maximum runtime in seconds after which the algorithm stops. Use -1 to specify no limit for the runtime", new IntValue(-1))); 201 202 Parameters.Add(new FixedValueParameter<IntValue>(SeedParameterName, "The random seed used to initialize the new pseudo random number generator.", new IntValue(0))); 202 203 Parameters.Add(new FixedValueParameter<BoolValue>(SetSeedRandomlyParameterName, "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true))); … … 206 207 Parameters.Add(new FixedValueParameter<IntValue>(GenerationSizeParameterName, "Number points that are sampled every iteration (stadard EGO: 1)", new IntValue(1))); 207 208 Parameters.Add(new ConstrainedValueParameter<IInfillCriterion>(InfillCriterionParameterName, "Decision what value should decide the next sample")); 209 InfillCriterionParameter.ValidValues.Add(new ExpectedImprovement()); 208 210 InfillCriterionParameter.ValidValues.Add(new AugmentedExpectedImprovement()); 209 InfillCriterionParameter.ValidValues.Add(new ExpectedImprovement());210 211 InfillCriterionParameter.ValidValues.Add(new ExpectedQuality()); 211 212 var eqi = new ExpectedQuantileImprovement(); … … 219 220 Parameters.Add(new FixedValueParameter<FileValue>(InitialSamplesParameterName, "The file specifying some initial samples used to jump start the algorithm. These samples are not counted as evaluations. If InitialEvaluations is more than the samples specified in the file, the rest is uniformly random generated and evaluated.", new FileValue())); 220 221 Parameters.Add(new ValueParameter<RealVector>(BaselineVectorParameterName, "A vector used to create a baseline, this vector is evaluated once and is not part of the modeling process (has no influence on algorithm performance)")); 222 var intialSamplingPlans = new ItemSet<IInitialSampling> { new UniformRandomSampling(), new LatinHyperCubeDesign() }; 223 Parameters.Add(new ConstrainedValueParameter<IInitialSampling>(InitialSamplingPlanParamterName, intialSamplingPlans, intialSamplingPlans.First())); 224 221 225 SetInfillProblem(); 222 226 RegisterEventhandlers(); … … 237 241 if (SetSeedRandomly) SeedParameter.Value.Value = new System.Random().Next(); 238 242 Random.Reset(Seed); 239 Samples = InitialSamples == null ? new List<Tuple<RealVector, double>>() : InitialSamples.ToList();243 Samples = InitialSamples?.ToList() ?? new List<Tuple<RealVector, double>>(); 240 244 241 245 //results … … 250 254 table.Rows.Add(new DataRow(CurrentQualitiesRowResultName)); 251 255 Results.Add(new Result(QualitiesChartResultName, table)); 252 if (BaselineVector != null && BaselineVector.Length == enc.Length) 253 Results.Add(new Result("BaselineValue", new DoubleValue(Evaluate(BaselineVector).Item2))); 254 256 if (BaselineVector != null && BaselineVector.Length == enc.Length) Results.Add(new Result("BaselineValue", new DoubleValue(Evaluate(BaselineVector).Item2))); 257 258 259 260 } 261 262 protected override void Run(CancellationToken cancellationToken) { 255 263 //initial samples 256 264 if (Samples.Count < InitialEvaluations) { 257 var points = EgoUtilities.GetUniformRandomDesign(InitialEvaluations - Samples.Count, enc.Length, enc.Bounds, Random);265 var points = InitialSamplingPlan.GetSamples(InitialEvaluations - Samples.Count, Samples.Select(x => x.Item1).ToArray(), (RealVectorEncoding)Problem.Encoding, Random); 258 266 foreach (var t in points) { 259 Samples.Add(Evaluate(t)); 260 cancellationToken.ThrowIfCancellationRequested(); 267 try { 268 Samples.Add(Evaluate(t)); 269 cancellationToken.ThrowIfCancellationRequested(); 270 } 271 finally { 272 Analyze(); 273 } 261 274 } 262 275 } 263 264 Analyze(); 265 } 266 267 protected override void Run(CancellationToken cancellationToken) { 276 //adaptive samples 268 277 for (ResultsIterations = 0; ResultsEvaluations < MaximumEvaluations; ResultsIterations++) { 269 278 try { … … 484 493 ResultsQualitiesWorst.Values.Add(Samples[Problem.Maximization ? min : max].Item2); 485 494 Problem.Analyze(Samples.Select(x => GetIndividual(x.Item1)).ToArray(), Samples.Select(x => x.Item2).ToArray(), Results, Random); 495 496 if (Samples.Count != 0 && Samples[0].Item1.Length == 2) { 497 var plotname = "DEBUG:Sample Distribution"; 498 var rowInit = "Initial Samples"; 499 var rowAll = "All Samples"; 500 if (!Results.ContainsKey(plotname)) Results.Add(new Result(plotname, new ScatterPlot())); 501 var plot = Results[plotname].Value as ScatterPlot; 502 if (!plot.Rows.ContainsKey(rowInit) && InitialSamples != null && InitialSamples.Count > 0) 503 plot.Rows.Add(new ScatterPlotDataRow(rowInit, "samples from inital file (already evaulated)", InitialSamples.Select(x => new Point2D<double>(x.Item1[0], x.Item1[1])))); 504 if (!plot.Rows.ContainsKey(rowAll)) plot.Rows.Add(new ScatterPlotDataRow(rowAll, "All samples", new Point2D<double>[0])); 505 else { plot.Rows[rowAll].Points.Clear(); } 506 plot.Rows[rowAll].Points.AddRange(Samples.Select(x => new Point2D<double>(x.Item1[0], x.Item1[1]))); 507 508 509 } 486 510 } 487 511 private Individual GetIndividual(RealVector r) { -
branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/EgoUtilities.cs
r14818 r14833 25 25 using System.Threading; 26 26 using HeuristicLab.Common; 27 using HeuristicLab.Core;28 27 using HeuristicLab.Data; 29 28 using HeuristicLab.Encodings.RealVectorEncoding; … … 76 75 if (ex != null) throw ex; 77 76 return alg.Results; 78 }79 public static RealVector[] GetUniformRandomDesign(int points, int dim, DoubleMatrix bounds, IRandom random) {80 var res = new RealVector[points];81 for (var i = 0; i < points; i++) {82 var r = new RealVector(dim);83 res[i] = r;84 for (var j = 0; j < dim; j++) {85 var b = j % bounds.Rows;86 r[j] = UniformRandom(bounds[b, 0], bounds[b, 1], random);87 }88 }89 return res;90 }91 public static double UniformRandom(double min, double max, IRandom rand) {92 return rand.NextDouble() * (max - min) + min;93 77 } 94 78 -
branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/HeuristicLab.Algorithms.EGO-3.4.csproj
r14818 r14833 38 38 <SpecificVersion>False</SpecificVersion> 39 39 <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Algorithms.DataAnalysis-3.4.dll</HintPath> 40 </Reference> 41 <Reference Include="HeuristicLab.Algorithms.EvolutionStrategy-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 42 <SpecificVersion>False</SpecificVersion> 43 <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Algorithms.EvolutionStrategy-3.3.dll</HintPath> 40 44 </Reference> 41 45 <Reference Include="HeuristicLab.Analysis-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> … … 125 129 <Compile Include="InfillCriteria\InfillCriterionBase.cs" /> 126 130 <Compile Include="InfillCriteria\ExpectedImprovement.cs" /> 131 <Compile Include="Interfaces\IInitialSampling.cs" /> 127 132 <Compile Include="Interfaces\ISurrogateAlgorithm.cs" /> 128 133 <Compile Include="Interfaces\IInfillCriterion.cs" /> … … 130 135 <Compile Include="Problems\InfillProblem.cs" /> 131 136 <Compile Include="Properties\AssemblyInfo.cs" /> 137 <Compile Include="SamplingMethods\LatinHyperCubeDesign.cs" /> 138 <Compile Include="SamplingMethods\UniformRandomSampling.cs" /> 132 139 </ItemGroup> 133 140 <ItemGroup> … … 135 142 <None Include="Properties\AssemblyInfo.cs.frame" /> 136 143 </ItemGroup> 137 <ItemGroup /> 144 <ItemGroup> 145 <WCFMetadata Include="Service References\" /> 146 </ItemGroup> 138 147 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> 139 148 <PropertyGroup>
Note: See TracChangeset
for help on using the changeset viewer.