Free cookie consent management tool by TermsFeed Policy Generator

Changeset 14833


Ignore:
Timestamp:
04/07/17 09:34:44 (8 years ago)
Author:
bwerth
Message:

#2745 added LatinHyperCubeDesign as possible InitialSamplingPlan

Location:
branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO
Files:
5 added
3 edited

Legend:

Unmodified
Added
Removed
  • branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/EfficientGlobalOptimizationAlgorithm.cs

    r14818 r14833  
    6969    private const string InitialSamplesParameterName = "InitialSamplesFile";
    7070    private const string BaselineVectorParameterName = "BaselineVector";
     71    private const string InitialSamplingPlanParamterName = "InitialSamplingPlan";
    7172    #endregion
    7273
     
    101102    public IFixedValueParameter<IntValue> MaximalDataSetSizeParameter => Parameters[MaximalDataSetSizeParameterName] as IFixedValueParameter<IntValue>;
    102103    public IFixedValueParameter<BoolValue> RemoveDuplicatesParameter => Parameters[RemoveDuplicatesParamterName] as IFixedValueParameter<BoolValue>;
    103 
    104104    public IFixedValueParameter<FileValue> InitialSamplesParameter => Parameters[InitialSamplesParameterName] as IFixedValueParameter<FileValue>;
    105 
    106105    public IValueParameter<RealVector> BaselineVectorParameter => Parameters[BaselineVectorParameterName] as IValueParameter<RealVector>;
     106    public IConstrainedValueParameter<IInitialSampling> InitialSamplingPlanParameter => Parameters[InitialSamplingPlanParamterName] as IConstrainedValueParameter<IInitialSampling>;
    107107    #endregion
    108108
     
    126126    private bool RemoveDuplicates => RemoveDuplicatesParameter.Value.Value;
    127127    private RealVector BaselineVector => BaselineVectorParameter.Value;
     128    private IInitialSampling InitialSamplingPlan => InitialSamplingPlanParameter.Value;
    128129    #endregion
    129130
     
    198199      Parameters.Add(new FixedValueParameter<IntValue>(MaximumEvaluationsParameterName, "", new IntValue(int.MaxValue)));
    199200      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)));
    201202      Parameters.Add(new FixedValueParameter<IntValue>(SeedParameterName, "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
    202203      Parameters.Add(new FixedValueParameter<BoolValue>(SetSeedRandomlyParameterName, "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
     
    206207      Parameters.Add(new FixedValueParameter<IntValue>(GenerationSizeParameterName, "Number points that are sampled every iteration (stadard EGO: 1)", new IntValue(1)));
    207208      Parameters.Add(new ConstrainedValueParameter<IInfillCriterion>(InfillCriterionParameterName, "Decision what value should decide the next sample"));
     209      InfillCriterionParameter.ValidValues.Add(new ExpectedImprovement());
    208210      InfillCriterionParameter.ValidValues.Add(new AugmentedExpectedImprovement());
    209       InfillCriterionParameter.ValidValues.Add(new ExpectedImprovement());
    210211      InfillCriterionParameter.ValidValues.Add(new ExpectedQuality());
    211212      var eqi = new ExpectedQuantileImprovement();
     
    219220      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()));
    220221      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
    221225      SetInfillProblem();
    222226      RegisterEventhandlers();
     
    237241      if (SetSeedRandomly) SeedParameter.Value.Value = new System.Random().Next();
    238242      Random.Reset(Seed);
    239       Samples = InitialSamples == null ? new List<Tuple<RealVector, double>>() : InitialSamples.ToList();
     243      Samples = InitialSamples?.ToList() ?? new List<Tuple<RealVector, double>>();
    240244
    241245      //results
     
    250254      table.Rows.Add(new DataRow(CurrentQualitiesRowResultName));
    251255      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) {
    255263      //initial samples
    256264      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);
    258266        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          }
    261274        }
    262275      }
    263 
    264       Analyze();
    265     }
    266 
    267     protected override void Run(CancellationToken cancellationToken) {
     276      //adaptive samples
    268277      for (ResultsIterations = 0; ResultsEvaluations < MaximumEvaluations; ResultsIterations++) {
    269278        try {
     
    484493      ResultsQualitiesWorst.Values.Add(Samples[Problem.Maximization ? min : max].Item2);
    485494      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      }
    486510    }
    487511    private Individual GetIndividual(RealVector r) {
  • branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/EgoUtilities.cs

    r14818 r14833  
    2525using System.Threading;
    2626using HeuristicLab.Common;
    27 using HeuristicLab.Core;
    2827using HeuristicLab.Data;
    2928using HeuristicLab.Encodings.RealVectorEncoding;
     
    7675      if (ex != null) throw ex;
    7776      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;
    9377    }
    9478
  • branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/HeuristicLab.Algorithms.EGO-3.4.csproj

    r14818 r14833  
    3838      <SpecificVersion>False</SpecificVersion>
    3939      <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>
    4044    </Reference>
    4145    <Reference Include="HeuristicLab.Analysis-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     
    125129    <Compile Include="InfillCriteria\InfillCriterionBase.cs" />
    126130    <Compile Include="InfillCriteria\ExpectedImprovement.cs" />
     131    <Compile Include="Interfaces\IInitialSampling.cs" />
    127132    <Compile Include="Interfaces\ISurrogateAlgorithm.cs" />
    128133    <Compile Include="Interfaces\IInfillCriterion.cs" />
     
    130135    <Compile Include="Problems\InfillProblem.cs" />
    131136    <Compile Include="Properties\AssemblyInfo.cs" />
     137    <Compile Include="SamplingMethods\LatinHyperCubeDesign.cs" />
     138    <Compile Include="SamplingMethods\UniformRandomSampling.cs" />
    132139  </ItemGroup>
    133140  <ItemGroup>
     
    135142    <None Include="Properties\AssemblyInfo.cs.frame" />
    136143  </ItemGroup>
    137   <ItemGroup />
     144  <ItemGroup>
     145    <WCFMetadata Include="Service References\" />
     146  </ItemGroup>
    138147  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
    139148  <PropertyGroup>
Note: See TracChangeset for help on using the changeset viewer.