Changeset 14894


Ignore:
Timestamp:
04/27/17 13:45:01 (2 years ago)
Author:
bwerth
Message:

#2780 worked on SAPBA; added IndividualStrategy

Location:
branches/SAPBA/HeuristicLab.Algorithms.SAPBA
Files:
1 added
3 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • branches/SAPBA/HeuristicLab.Algorithms.SAPBA

    • Property svn:global-ignores set to
      .vs
      obj
    • Property svn:ignore set to
      new 2.txt
  • branches/SAPBA/HeuristicLab.Algorithms.SAPBA/EgoUtilities.cs

    r14893 r14894  
    9393
    9494    public static IRegressionSolution BuildModel(CancellationToken cancellationToken, IEnumerable<Tuple<RealVector, double>> samples, IDataAnalysisAlgorithm<IRegressionProblem> regressionAlgorithm, IRandom random, bool removeDuplicates = true, IRegressionSolution oldSolution = null) {
    95       var dataset = EgoUtilities.GetDataSet(samples.ToList(), removeDuplicates);
     95      var dataset = GetDataSet(samples.ToList(), removeDuplicates);
    9696      var problemdata = new RegressionProblemData(dataset, dataset.VariableNames.Where(x => !x.Equals("output")), "output");
    9797      problemdata.TrainingPartition.Start = 0;
  • branches/SAPBA/HeuristicLab.Algorithms.SAPBA/HeuristicLab.Algorithms.SAPBA-3.4.csproj

    r14893 r14894  
    4242      <SpecificVersion>False</SpecificVersion>
    4343      <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Algorithms.EvolutionStrategy-3.3.dll</HintPath>
     44    </Reference>
     45    <Reference Include="HeuristicLab.Algorithms.GeneticAlgorithm-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     46      <SpecificVersion>False</SpecificVersion>
     47      <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Algorithms.GeneticAlgorithm-3.3.dll</HintPath>
    4448    </Reference>
    4549    <Reference Include="HeuristicLab.Analysis-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     
    120124  <ItemGroup>
    121125    <Compile Include="EgoUtilities.cs" />
     126    <Compile Include="Strategies\IndividualStrategy.cs" />
    122127    <Compile Include="Strategies\GenerationalStrategy.cs" />
    123128    <Compile Include="SurrogateAssistedPopulationBasedAlgorithm.cs" />
  • branches/SAPBA/HeuristicLab.Algorithms.SAPBA/Plugin.cs

    r14893 r14894  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
     24using System.Text;
    2225using HeuristicLab.PluginInfrastructure;
    2326
    2427namespace HeuristicLab.Algorithms.SAPBA {
    25   [Plugin("HeuristicLab.Algorithms.SAPBA", "3.4.5.14833")]
    26   [PluginFile("HeuristicLab.Algorithms.EGO-3.4.dll", PluginFileType.Assembly)]
     28  [Plugin("HeuristicLab.Algorithms.SAPBA", "3.4.5.14893")]
     29  [PluginFile("HeuristicLab.Algorithms.SAPBA-3.4.dll", PluginFileType.Assembly)]
    2730  [PluginFile("displayModelFrame.html", PluginFileType.Data)]
    2831  [PluginDependency("HeuristicLab.Algorithms.CMAEvolutionStrategy", "3.4")]
     
    3538  [PluginDependency("HeuristicLab.Data", "3.3")]
    3639  [PluginDependency("HeuristicLab.Encodings.RealVectorEncoding", "3.3")]
    37   [PluginDependency("HeuristicLab.Operators", "3.3")]
    38   [PluginDependency("HeuristicLab.Optimization", "3.3")]
    39   [PluginDependency("HeuristicLab.Parameters", "3.3")]
    40   [PluginDependency("HeuristicLab.Persistence", "3.3")]
     40  [PluginDependency("HeuristicLab.Operators","3.3")]
     41  [PluginDependency("HeuristicLab.Optimization","3.3")]
     42  [PluginDependency("HeuristicLab.Parameters","3.3")]
     43  [PluginDependency("HeuristicLab.Persistence","3.3")]
    4144  [PluginDependency("HeuristicLab.Problems.DataAnalysis", "3.4")]
    4245  [PluginDependency("HeuristicLab.Problems.Instances", "3.3")]
  • branches/SAPBA/HeuristicLab.Algorithms.SAPBA/Properties/AssemblyInfo.cs

    r14893 r14894  
    5353// by using the '*' as shown below:
    5454[assembly: AssemblyVersion("3.4.0.0")]
    55 [assembly: AssemblyFileVersion("3.4.0.14833")]
     55[assembly: AssemblyFileVersion("3.4.0.14893")]
  • branches/SAPBA/HeuristicLab.Algorithms.SAPBA/Strategies/GenerationalStrategy.cs

    r14893 r14894  
    3737      if (RegressionSolution != null && Generations < NoGenerations.Value) Generations++;
    3838      else {
    39         foreach (var indi in individuals) Evaluate(indi.RealVector(), random);
     39        foreach (var indi in individuals) EvaluateSample(indi.RealVector(), random);
    4040        BuildRegressionSolution(random);
    4141        Generations = 0;
  • branches/SAPBA/HeuristicLab.Algorithms.SAPBA/Strategies/StrategyBase.cs

    r14893 r14894  
    3838    #region Properties
    3939    [Storable]
    40     private SurrogateAssistedPopulationBasedAlgorithm Algorithm;
     40    protected SurrogateAssistedPopulationBasedAlgorithm Algorithm;
    4141    [Storable]
    4242    private List<Tuple<RealVector, double>> Samples;
     
    9292
    9393        if (!globalResults.ContainsKey(BestQualityResultName)) globalResults.Add(new Result(BestQualityResultName, new DoubleValue(0.0)));
    94         ((DoubleValue)globalResults[BestQualityResultName].Value).Value = qualities[bestIdx];
    95         if (!globalResults.ContainsKey(BestSolutionResultName)) globalResults.Add(new Result(BestQualityResultName, new RealVector()));
    96         globalResults[BestSolutionResultName].Value = individuals[bestIdx].RealVector();
     94        ((DoubleValue)globalResults[BestQualityResultName].Value).Value = Samples[bestIdx].Item2;
     95        if (!globalResults.ContainsKey(BestSolutionResultName)) globalResults.Add(new Result(BestSolutionResultName, new RealVector()));
     96        globalResults[BestSolutionResultName].Value = Samples[bestIdx].Item1;
    9797
    9898        DataTable table;
     
    135135    }
    136136    protected Tuple<RealVector, double> EvaluateSample(RealVector point, IRandom random) {
     137      Cancellation.ThrowIfCancellationRequested();
     138      if (Samples.Count >= Algorithm.MaximumEvaluations) { Algorithm.OptimizationAlgorithm.Stop(); return new Tuple<RealVector, double>(point, 0.0); }
    137139      var p = new Tuple<RealVector, double>(point, Algorithm.Problem.Evaluate(GetIndividual(point), random));
    138140      Samples.Add(p);
     
    140142    }
    141143    protected Tuple<RealVector, double> EstimateSample(RealVector point, IRandom random) {
     144      if (Samples.Count == Algorithm.InitialEvaluations && RegressionSolution == null) BuildRegressionSolution(random);
    142145      return Samples.Count < Algorithm.InitialEvaluations ? EvaluateSample(point, random) : new Tuple<RealVector, double>(point, RegressionSolution.Model.GetEstimation(point));
    143146    }
  • branches/SAPBA/HeuristicLab.Algorithms.SAPBA/SurrogateAssistedPopulationBasedAlgorithm.cs

    r14893 r14894  
    4444    public override bool SupportsPause => true;
    4545    public override Type ProblemType => typeof(SingleObjectiveBasicProblem<IEncoding>);
    46     public new SingleObjectiveBasicProblem<IEncoding> Problem {
     46    public new SingleObjectiveBasicProblem<IEncoding> Problem
     47    {
    4748      get { return (SingleObjectiveBasicProblem<IEncoding>)base.Problem; }
    4849      set { base.Problem = value; }
     
    5152
    5253    #region ParameterNames
    53     private const string GenerationSizeParameterName = "GenerationSize";
    5454    private const string InitialEvaluationsParameterName = "Initial Evaluations";
    5555    private const string MaximalDataSetSizeParameterName = "Maximal Dataset Size";
     
    5757    private const string MaximumRuntimeParameterName = "Maximum Runtime";
    5858    private const string OptimizationAlgorithmParameterName = "Optimization Algorithm";
    59     private const string OptimizationRestartsParameterName = "Optimization Restarts";
    6059    private const string RemoveDuplicatesParamterName = "RemoveDuplicates";
    6160    private const string RegressionAlgorithmParameterName = "RegressionAlgorithm";
     
    6665
    6766    #region ParameterProperties
    68     public IFixedValueParameter<IntValue> GenerationSizeParemeter => Parameters[GenerationSizeParameterName] as IFixedValueParameter<IntValue>;
    6967    public IFixedValueParameter<IntValue> InitialEvaluationsParameter => Parameters[InitialEvaluationsParameterName] as IFixedValueParameter<IntValue>;
    7068    public IFixedValueParameter<IntValue> MaximalDataSetSizeParameter => Parameters[MaximalDataSetSizeParameterName] as IFixedValueParameter<IntValue>;
     
    7270    public IFixedValueParameter<IntValue> MaximumRuntimeParameter => Parameters[MaximumRuntimeParameterName] as IFixedValueParameter<IntValue>;
    7371    public IValueParameter<Algorithm> OptimizationAlgorithmParameter => Parameters[OptimizationAlgorithmParameterName] as IValueParameter<Algorithm>;
    74     public IFixedValueParameter<IntValue> OptimizationRestartsParemeter => Parameters[OptimizationRestartsParameterName] as IFixedValueParameter<IntValue>;
    7572    public IValueParameter<IDataAnalysisAlgorithm<IRegressionProblem>> RegressionAlgorithmParameter => Parameters[RegressionAlgorithmParameterName] as IValueParameter<IDataAnalysisAlgorithm<IRegressionProblem>>;
    7673    public IFixedValueParameter<BoolValue> RemoveDuplicatesParameter => Parameters[RemoveDuplicatesParamterName] as IFixedValueParameter<BoolValue>;
     
    8178
    8279    #region Properties
    83     public int GenerationSize => GenerationSizeParemeter.Value.Value;
    8480    public int InitialEvaluations => InitialEvaluationsParameter.Value.Value;
    8581    public int MaximalDatasetSize => MaximalDataSetSizeParameter.Value.Value;
     
    8783    public int MaximumRuntime => MaximumRuntimeParameter.Value.Value;
    8884    public Algorithm OptimizationAlgorithm => OptimizationAlgorithmParameter.Value;
    89     public int OptimizationRestarts => OptimizationRestartsParemeter.Value.Value;
    9085    public IDataAnalysisAlgorithm<IRegressionProblem> RegressionAlgorithm => RegressionAlgorithmParameter.Value;
    9186    public bool RemoveDuplicates => RemoveDuplicatesParameter.Value.Value;
     
    121116    public override IDeepCloneable Clone(Cloner cloner) { return new SurrogateAssistedPopulationBasedAlgorithm(this, cloner); }
    122117    public SurrogateAssistedPopulationBasedAlgorithm() {
    123       var cmaes = new CMAEvolutionStrategy.CMAEvolutionStrategy {
    124         MaximumGenerations = 300,
    125         PopulationSize = 50
     118      surrogateProblem = new SurrogateProblem();
     119      var geneticAlgorithm = new GeneticAlgorithm.GeneticAlgorithm {
     120        PopulationSize = { Value = 50 },
     121        Problem = surrogateProblem
    126122      };
    127123      var model = new GaussianProcessRegression {
     
    130126      model.CovarianceFunctionParameter.Value = new CovarianceRationalQuadraticIso();
    131127
    132       cmaes.Problem = new SurrogateProblem();
    133128      Parameters.Add(new FixedValueParameter<IntValue>(MaximumEvaluationsParameterName, "", new IntValue(int.MaxValue)));
    134129      Parameters.Add(new FixedValueParameter<IntValue>(InitialEvaluationsParameterName, "", new IntValue(10)));
     
    137132      Parameters.Add(new FixedValueParameter<BoolValue>(SetSeedRandomlyParameterName, "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
    138133      Parameters.Add(new ValueParameter<IDataAnalysisAlgorithm<IRegressionProblem>>(RegressionAlgorithmParameterName, "The model used to approximate the problem", model));
    139       Parameters.Add(new ValueParameter<Algorithm>(OptimizationAlgorithmParameterName, "The algorithm used to solve the expected improvement subproblem", cmaes));
    140       Parameters.Add(new FixedValueParameter<IntValue>(OptimizationRestartsParameterName, "Number of restarts of the SubAlgortihm to avoid local optima", new IntValue(1)));
    141       Parameters.Add(new FixedValueParameter<IntValue>(GenerationSizeParameterName, "Number points that are sampled every iteration (stadard EGO: 1)", new IntValue(1)));
     134      Parameters.Add(new ValueParameter<Algorithm>(OptimizationAlgorithmParameterName, "The algorithm used to solve the expected improvement subproblem", geneticAlgorithm));
    142135      Parameters.Add(new FixedValueParameter<IntValue>(MaximalDataSetSizeParameterName, "The maximum number of sample points used to generate the model. Set 0 or less to use always all samples ", new IntValue(-1)));
    143136      Parameters.Add(new FixedValueParameter<BoolValue>(RemoveDuplicatesParamterName, "Wether duplicate samples should be replaced by a single sample with an averaged quality. This GREATLY decreases the chance of ill conditioned models (unbuildable models) but is not theoretically sound as the model ignores the increasing certainty in this region"));
    144       var strategies = new ItemSet<ISurrogateStrategy> { new GenerationalStrategy() };
    145       Parameters.Add(new ConstrainedValueParameter<ISurrogateStrategy>(StrategyParameterName, "The surrogate strategy that dictates how the optimization alg is assisted", strategies));
     137      var strategies = new ItemSet<ISurrogateStrategy> { new GenerationalStrategy(), new IndividualStrategy() };
     138      Parameters.Add(new ConstrainedValueParameter<ISurrogateStrategy>(StrategyParameterName, "The surrogate strategy that dictates how the optimization alg is assisted", strategies, strategies.First()));
    146139      RegisterEventhandlers();
    147140    }
Note: See TracChangeset for help on using the changeset viewer.