Changeset 15176


Ignore:
Timestamp:
07/10/17 15:31:35 (3 months ago)
Author:
bwerth
Message:

#2592 formatting & removed unreferenced enum

Location:
branches/MOCMAEvolutionStrategy/HeuristicLab.Algorithms.MOCMAEvolutionStrategy/3.3
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/MOCMAEvolutionStrategy/HeuristicLab.Algorithms.MOCMAEvolutionStrategy/3.3/Indicators/CrowdingIndicator.cs

    r15045 r15176  
    6060        }
    6161      }
    62       //find min
    6362      return pointsums.Select((value, index) => new { value, index }).OrderBy(x => x.value).First().index;
    6463    }
    65 
    66 
    6764  }
    6865}
  • branches/MOCMAEvolutionStrategy/HeuristicLab.Algorithms.MOCMAEvolutionStrategy/3.3/Indicators/HypervolumeIndicator.cs

    r15045 r15176  
    5555      var point = front[idx];
    5656      front.RemoveAt(idx);
    57       var contribution = -Hypervolume.Calculate(front, refPoint, maximization);
     57      var contribution = -Hypervolume.Calculate(front.ToArray(), refPoint, maximization);
    5858      front.Insert(idx, point);
    5959      return contribution;
  • branches/MOCMAEvolutionStrategy/HeuristicLab.Algorithms.MOCMAEvolutionStrategy/3.3/Indicators/MinimalDistanceIndicator.cs

    r15045 r15176  
    8484    }
    8585
    86     #region helpers
     86    #region Helpers
    8787    private static double[,] CalcDistances(IReadOnlyList<double[]> extracted) {
    8888      var res = new double[extracted.Count, extracted.Count];
     
    9797    }
    9898    #endregion
    99 
    10099  }
    101100}
  • branches/MOCMAEvolutionStrategy/HeuristicLab.Algorithms.MOCMAEvolutionStrategy/3.3/Individual.cs

    r15089 r15176  
    3232  public class Individual : IDeepCloneable {
    3333
    34     public enum OffspringSuccess {
    35       Success, NoSuccess
    36     }
    37 
    3834    #region Properties
    3935    [Storable]
     
    5450    private double[,] lowerCholesky;
    5551
    56 
    5752    //Phenotype
    5853    [Storable]
     
    7065    protected Individual(bool deserializing) { }
    7166
    72     /// <summary>
    73     ///
    74     /// </summary>
    75     /// <param name="mean">has to be 0-vector with correct lenght</param>
    76     /// <param name="pSucc">has to be ptargetsucc</param>
    77     /// <param name="sigma">initialSigma</param>
    78     /// <param name="pc">has to be 0-vector with correct lenght</param>
    79     /// <param name="c">has to be a symmetric positive definit Covariance matrix</param>
    8067    public Individual(RealVector mean, double pSucc, double sigma, RealVector pc, double[,] c, MOCMAEvolutionStrategy strategy) {
    8168      Mean = mean;
     
    147134        if (stepNormSqr > 1 && 1 < strategy.CovarianceMatrixUnlearningRate * (2 * stepNormSqr - 1)) rate = 1 / (2 * stepNormSqr - 1);
    148135        CholeskyUpdate(lastStep, 1 + rate, -rate);
    149 
    150136      } else RoundUpdate();
    151 
    152137    }
    153138
     
    159144        UpdateEvolutionPath(1 - strategy.EvolutionPathLearningRate, evolutionpathUpdateWeight);
    160145        CholeskyUpdate(evolutionPath, 1 - strategy.CovarianceMatrixLearningRate, strategy.CovarianceMatrixLearningRate);
    161       } else {
    162         RoundUpdate();
    163       }
     146      } else RoundUpdate();
    164147    }
    165148
     
    172155    }
    173156
    174     #region helpers
     157    #region Helpers
    175158    private void CholeskyDecomposition(double[,] c) {
    176159      if (!alglib.spdmatrixcholesky(ref c, c.GetLength(0), false))
     
    192175        var gamma = dj * betaPrime + swj2;
    193176        var x1 = dj + swj2 / betaPrime;
    194         if (x1 < 0.0) return;//throw new ArgumentException("Update makes Covariancematrix indefinite");//TODO check wether ignoring this update is valid
     177        if (x1 < 0.0) return;
    195178        var nLjj = Math.Sqrt(x1);
    196179        lowerCholesky[j, j] = nLjj;
     
    202185        for (var i = j + 1; i < n; i++) lowerCholesky[i, j] *= nLjj / ljj;
    203186        for (var i = j + 1; i < n; i++) lowerCholesky[i, j] += nLjj * beta * wj / gamma * temp[i];
    204 
    205187      }
    206 
    207188    }
    208189
     
    213194    }
    214195    #endregion
    215 
    216196  }
    217 
    218197}
  • branches/MOCMAEvolutionStrategy/HeuristicLab.Algorithms.MOCMAEvolutionStrategy/3.3/MOCMAEvolutionStrategy.cs

    r15089 r15176  
    4242  [System.Runtime.InteropServices.Guid("5AC20A69-BBBF-4153-B57D-3EAF92DC505E")]
    4343  public class MOCMAEvolutionStrategy : BasicAlgorithm {
    44     public override Type ProblemType
    45     {
     44    public override Type ProblemType {
    4645      get { return typeof(MultiObjectiveBasicProblem<RealVectorEncoding>); }
    4746    }
    48     public new MultiObjectiveBasicProblem<RealVectorEncoding> Problem
    49     {
     47    public new MultiObjectiveBasicProblem<RealVectorEncoding> Problem {
    5048      get { return (MultiObjectiveBasicProblem<RealVectorEncoding>)base.Problem; }
    5149      set { base.Problem = value; }
    5250    }
    53     public override bool SupportsPause
    54     {
     51    public override bool SupportsPause {
    5552      get { return true; }
    5653    }
    5754
    58     #region storable fields
     55    #region Storable fields
    5956    [Storable]
    6057    private IRandom random = new MersenneTwister();
     
    106103
    107104    #region ParameterProperties
    108     public IFixedValueParameter<IntValue> MaximumRuntimeParameter
    109     {
     105    public IFixedValueParameter<IntValue> MaximumRuntimeParameter {
    110106      get { return (IFixedValueParameter<IntValue>)Parameters[MaximumRuntimeName]; }
    111107    }
    112     public IFixedValueParameter<IntValue> SeedParameter
    113     {
     108    public IFixedValueParameter<IntValue> SeedParameter {
    114109      get { return (IFixedValueParameter<IntValue>)Parameters[SeedName]; }
    115110    }
    116     public FixedValueParameter<BoolValue> SetSeedRandomlyParameter
    117     {
     111    public FixedValueParameter<BoolValue> SetSeedRandomlyParameter {
    118112      get { return (FixedValueParameter<BoolValue>)Parameters[SetSeedRandomlyName]; }
    119113    }
    120     public IFixedValueParameter<IntValue> PopulationSizeParameter
    121     {
     114    public IFixedValueParameter<IntValue> PopulationSizeParameter {
    122115      get { return (IFixedValueParameter<IntValue>)Parameters[PopulationSizeName]; }
    123116    }
    124     public IFixedValueParameter<IntValue> MaximumGenerationsParameter
    125     {
     117    public IFixedValueParameter<IntValue> MaximumGenerationsParameter {
    126118      get { return (IFixedValueParameter<IntValue>)Parameters[MaximumGenerationsName]; }
    127119    }
    128     public IFixedValueParameter<IntValue> MaximumEvaluatedSolutionsParameter
    129     {
     120    public IFixedValueParameter<IntValue> MaximumEvaluatedSolutionsParameter {
    130121      get { return (IFixedValueParameter<IntValue>)Parameters[MaximumEvaluatedSolutionsName]; }
    131122    }
    132     public IValueParameter<DoubleArray> InitialSigmaParameter
    133     {
     123    public IValueParameter<DoubleArray> InitialSigmaParameter {
    134124      get { return (IValueParameter<DoubleArray>)Parameters[InitialSigmaName]; }
    135125    }
    136     public IConstrainedValueParameter<IIndicator> IndicatorParameter
    137     {
     126    public IConstrainedValueParameter<IIndicator> IndicatorParameter {
    138127      get { return (IConstrainedValueParameter<IIndicator>)Parameters[IndicatorName]; }
    139128    }
     
    141130
    142131    #region Properties
    143     public int MaximumRuntime
    144     {
     132    public int MaximumRuntime {
    145133      get { return MaximumRuntimeParameter.Value.Value; }
    146134      set { MaximumRuntimeParameter.Value.Value = value; }
    147135    }
    148     public int Seed
    149     {
     136    public int Seed {
    150137      get { return SeedParameter.Value.Value; }
    151138      set { SeedParameter.Value.Value = value; }
    152139    }
    153     public bool SetSeedRandomly
    154     {
     140    public bool SetSeedRandomly {
    155141      get { return SetSeedRandomlyParameter.Value.Value; }
    156142      set { SetSeedRandomlyParameter.Value.Value = value; }
    157143    }
    158     public int PopulationSize
    159     {
     144    public int PopulationSize {
    160145      get { return PopulationSizeParameter.Value.Value; }
    161146      set { PopulationSizeParameter.Value.Value = value; }
    162147    }
    163     public int MaximumGenerations
    164     {
     148    public int MaximumGenerations {
    165149      get { return MaximumGenerationsParameter.Value.Value; }
    166150      set { MaximumGenerationsParameter.Value.Value = value; }
    167151    }
    168     public int MaximumEvaluatedSolutions
    169     {
     152    public int MaximumEvaluatedSolutions {
    170153      get { return MaximumEvaluatedSolutionsParameter.Value.Value; }
    171154      set { MaximumEvaluatedSolutionsParameter.Value.Value = value; }
    172155    }
    173     public DoubleArray InitialSigma
    174     {
     156    public DoubleArray InitialSigma {
    175157      get { return InitialSigmaParameter.Value; }
    176158      set { InitialSigmaParameter.Value = value; }
    177159    }
    178     public IIndicator Indicator
    179     {
     160    public IIndicator Indicator {
    180161      get { return IndicatorParameter.Value; }
    181162      set { IndicatorParameter.Value = value; }
     
    192173
    193174    #region ResultsProperties
    194     private int ResultsEvaluations
    195     {
     175    private int ResultsEvaluations {
    196176      get { return ((IntValue)Results[EvaluationsResultName].Value).Value; }
    197177      set { ((IntValue)Results[EvaluationsResultName].Value).Value = value; }
    198178    }
    199     private int ResultsIterations
    200     {
     179    private int ResultsIterations {
    201180      get { return ((IntValue)Results[IterationsResultName].Value).Value; }
    202181      set { ((IntValue)Results[IterationsResultName].Value).Value = value; }
    203182    }
    204183    #region Datatable
    205     private DataTable ResultsQualities
    206     {
     184    private DataTable ResultsQualities {
    207185      get { return (DataTable)Results[TimetableResultName].Value; }
    208186    }
    209     private DataRow ResultsBestHypervolumeDataLine
    210     {
     187    private DataRow ResultsBestHypervolumeDataLine {
    211188      get { return ResultsQualities.Rows[BestHypervolumeResultName]; }
    212189    }
    213     private DataRow ResultsHypervolumeDataLine
    214     {
     190    private DataRow ResultsHypervolumeDataLine {
    215191      get { return ResultsQualities.Rows[HypervolumeResultName]; }
    216192    }
    217     private DataRow ResultsGenerationalDistanceDataLine
    218     {
     193    private DataRow ResultsGenerationalDistanceDataLine {
    219194      get { return ResultsQualities.Rows[GenerationalDistanceResultName]; }
    220195    }
    221     private DataRow ResultsInvertedGenerationalDistanceDataLine
    222     {
     196    private DataRow ResultsInvertedGenerationalDistanceDataLine {
    223197      get { return ResultsQualities.Rows[InvertedGenerationalDistanceResultName]; }
    224198    }
    225     private DataRow ResultsCrowdingDataLine
    226     {
     199    private DataRow ResultsCrowdingDataLine {
    227200      get { return ResultsQualities.Rows[CrowdingResultName]; }
    228201    }
    229     private DataRow ResultsSpacingDataLine
    230     {
     202    private DataRow ResultsSpacingDataLine {
    231203      get { return ResultsQualities.Rows[SpacingResultName]; }
    232204    }
    233     private DataRow ResultsHypervolumeDifferenceDataLine
    234     {
     205    private DataRow ResultsHypervolumeDifferenceDataLine {
    235206      get { return ResultsQualities.Rows[DifferenceToBestKnownHypervolumeResultName]; }
    236207    }
    237208    #endregion
    238209    //QualityIndicators
    239     private double ResultsHypervolume
    240     {
     210    private double ResultsHypervolume {
    241211      get { return ((DoubleValue)Results[HypervolumeResultName].Value).Value; }
    242212      set { ((DoubleValue)Results[HypervolumeResultName].Value).Value = value; }
    243213    }
    244     private double ResultsGenerationalDistance
    245     {
     214    private double ResultsGenerationalDistance {
    246215      get { return ((DoubleValue)Results[GenerationalDistanceResultName].Value).Value; }
    247216      set { ((DoubleValue)Results[GenerationalDistanceResultName].Value).Value = value; }
    248217    }
    249     private double ResultsInvertedGenerationalDistance
    250     {
     218    private double ResultsInvertedGenerationalDistance {
    251219      get { return ((DoubleValue)Results[InvertedGenerationalDistanceResultName].Value).Value; }
    252220      set { ((DoubleValue)Results[InvertedGenerationalDistanceResultName].Value).Value = value; }
    253221    }
    254     private double ResultsCrowding
    255     {
     222    private double ResultsCrowding {
    256223      get { return ((DoubleValue)Results[CrowdingResultName].Value).Value; }
    257224      set { ((DoubleValue)Results[CrowdingResultName].Value).Value = value; }
    258225    }
    259     private double ResultsSpacing
    260     {
     226    private double ResultsSpacing {
    261227      get { return ((DoubleValue)Results[SpacingResultName].Value).Value; }
    262228      set { ((DoubleValue)Results[SpacingResultName].Value).Value = value; }
    263229    }
    264     private double ResultsBestHypervolume
    265     {
     230    private double ResultsBestHypervolume {
    266231      get { return ((DoubleValue)Results[BestHypervolumeResultName].Value).Value; }
    267232      set { ((DoubleValue)Results[BestHypervolumeResultName].Value).Value = value; }
    268233    }
    269     private double ResultsBestKnownHypervolume
    270     {
     234    private double ResultsBestKnownHypervolume {
    271235      get { return ((DoubleValue)Results[BestKnownHypervolumeResultName].Value).Value; }
    272236      set { ((DoubleValue)Results[BestKnownHypervolumeResultName].Value).Value = value; }
    273237    }
    274     private double ResultsDifferenceBestKnownHypervolume
    275     {
     238    private double ResultsDifferenceBestKnownHypervolume {
    276239      get { return ((DoubleValue)Results[DifferenceToBestKnownHypervolumeResultName].Value).Value; }
    277240      set { ((DoubleValue)Results[DifferenceToBestKnownHypervolumeResultName].Value).Value = value; }
     
    279242    }
    280243    //Solutions
    281     private DoubleMatrix ResultsSolutions
    282     {
     244    private DoubleMatrix ResultsSolutions {
    283245      get { return (DoubleMatrix)Results[CurrentFrontResultName].Value; }
    284246      set { Results[CurrentFrontResultName].Value = value; }
    285247    }
    286     private ScatterPlotContent ResultsScatterPlot
    287     {
     248    private ScatterPlotContent ResultsScatterPlot {
    288249      get { return (ScatterPlotContent)Results[ScatterPlotResultName].Value; }
    289250      set { Results[ScatterPlotResultName].Value = value; }
     
    401362        ResultsDifferenceBestKnownHypervolume = ResultsBestKnownHypervolume;
    402363      }
    403       //TODO? move FrontScatterPlotContent partially? to MultiobjectiveTestProblem?
    404364      ResultsScatterPlot = new ScatterPlotContent(new double[0][], new double[0][], problem.BestKnownFront.ToJaggedArray(), problem.Objectives);
    405365    }
     
    413373          ResultsIterations++;
    414374          cancellationToken.ThrowIfCancellationRequested();
    415         }
    416         finally {
     375        } finally {
    417376          Analyze();
    418377        }
    419378      }
    420 
    421 
    422379    }
    423380    private void Iterate() {
     
    483440      int[] ranks;
    484441      var fronts = DominationCalculator<Individual>.CalculateAllParetoFronts(parents.ToArray(), parents.Select(i => i.PenalizedFitness).ToArray(), Problem.Maximization, out ranks);
    485       // NonDominatedSort(parents, individual => individual.PenalizedFitness);
    486442
    487443      //deselect the highest rank fronts until we would end up with less or equal mu elements
     
    508464      foreach (var p in parents.Skip(solutions.Length).Where(i => i.Selected))
    509465        p.UpdateAsOffspring();
    510 
    511466      for (var i = 0; i < solutions.Length; i++)
    512467        if (parents[i].Selected)
    513468          parents[i].UpdateAsParent(parents[i + solutions.Length].Selected);
    514 
    515469      solutions = parents.Where(p => p.Selected).ToArray();
    516470    }
    517471
    518472    private void Analyze() {
    519       //TODO? move FrontScatterPlotContent partially to MultiobjectiveTestProblem
    520473      ResultsScatterPlot = new ScatterPlotContent(solutions.Select(x => x.Fitness).ToArray(), solutions.Select(x => x.Mean.ToArray()).ToArray(), ResultsScatterPlot.ParetoFront, ResultsScatterPlot.Objectives);
    521 
    522474      ResultsSolutions = solutions.Select(x => x.Mean.ToArray()).ToMatrix();
    523475
     
    550502        random);
    551503    }
    552 
    553504  }
    554505}
Note: See TracChangeset for help on using the changeset viewer.