- Timestamp:
- 07/10/17 15:31:35 (7 years ago)
- 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 60 60 } 61 61 } 62 //find min63 62 return pointsums.Select((value, index) => new { value, index }).OrderBy(x => x.value).First().index; 64 63 } 65 66 67 64 } 68 65 } -
branches/MOCMAEvolutionStrategy/HeuristicLab.Algorithms.MOCMAEvolutionStrategy/3.3/Indicators/HypervolumeIndicator.cs
r15045 r15176 55 55 var point = front[idx]; 56 56 front.RemoveAt(idx); 57 var contribution = -Hypervolume.Calculate(front , refPoint, maximization);57 var contribution = -Hypervolume.Calculate(front.ToArray(), refPoint, maximization); 58 58 front.Insert(idx, point); 59 59 return contribution; -
branches/MOCMAEvolutionStrategy/HeuristicLab.Algorithms.MOCMAEvolutionStrategy/3.3/Indicators/MinimalDistanceIndicator.cs
r15045 r15176 84 84 } 85 85 86 #region helpers86 #region Helpers 87 87 private static double[,] CalcDistances(IReadOnlyList<double[]> extracted) { 88 88 var res = new double[extracted.Count, extracted.Count]; … … 97 97 } 98 98 #endregion 99 100 99 } 101 100 } -
branches/MOCMAEvolutionStrategy/HeuristicLab.Algorithms.MOCMAEvolutionStrategy/3.3/Individual.cs
r15089 r15176 32 32 public class Individual : IDeepCloneable { 33 33 34 public enum OffspringSuccess {35 Success, NoSuccess36 }37 38 34 #region Properties 39 35 [Storable] … … 54 50 private double[,] lowerCholesky; 55 51 56 57 52 //Phenotype 58 53 [Storable] … … 70 65 protected Individual(bool deserializing) { } 71 66 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>80 67 public Individual(RealVector mean, double pSucc, double sigma, RealVector pc, double[,] c, MOCMAEvolutionStrategy strategy) { 81 68 Mean = mean; … … 147 134 if (stepNormSqr > 1 && 1 < strategy.CovarianceMatrixUnlearningRate * (2 * stepNormSqr - 1)) rate = 1 / (2 * stepNormSqr - 1); 148 135 CholeskyUpdate(lastStep, 1 + rate, -rate); 149 150 136 } else RoundUpdate(); 151 152 137 } 153 138 … … 159 144 UpdateEvolutionPath(1 - strategy.EvolutionPathLearningRate, evolutionpathUpdateWeight); 160 145 CholeskyUpdate(evolutionPath, 1 - strategy.CovarianceMatrixLearningRate, strategy.CovarianceMatrixLearningRate); 161 } else { 162 RoundUpdate(); 163 } 146 } else RoundUpdate(); 164 147 } 165 148 … … 172 155 } 173 156 174 #region helpers157 #region Helpers 175 158 private void CholeskyDecomposition(double[,] c) { 176 159 if (!alglib.spdmatrixcholesky(ref c, c.GetLength(0), false)) … … 192 175 var gamma = dj * betaPrime + swj2; 193 176 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 valid177 if (x1 < 0.0) return; 195 178 var nLjj = Math.Sqrt(x1); 196 179 lowerCholesky[j, j] = nLjj; … … 202 185 for (var i = j + 1; i < n; i++) lowerCholesky[i, j] *= nLjj / ljj; 203 186 for (var i = j + 1; i < n; i++) lowerCholesky[i, j] += nLjj * beta * wj / gamma * temp[i]; 204 205 187 } 206 207 188 } 208 189 … … 213 194 } 214 195 #endregion 215 216 196 } 217 218 197 } -
branches/MOCMAEvolutionStrategy/HeuristicLab.Algorithms.MOCMAEvolutionStrategy/3.3/MOCMAEvolutionStrategy.cs
r15089 r15176 42 42 [System.Runtime.InteropServices.Guid("5AC20A69-BBBF-4153-B57D-3EAF92DC505E")] 43 43 public class MOCMAEvolutionStrategy : BasicAlgorithm { 44 public override Type ProblemType 45 { 44 public override Type ProblemType { 46 45 get { return typeof(MultiObjectiveBasicProblem<RealVectorEncoding>); } 47 46 } 48 public new MultiObjectiveBasicProblem<RealVectorEncoding> Problem 49 { 47 public new MultiObjectiveBasicProblem<RealVectorEncoding> Problem { 50 48 get { return (MultiObjectiveBasicProblem<RealVectorEncoding>)base.Problem; } 51 49 set { base.Problem = value; } 52 50 } 53 public override bool SupportsPause 54 { 51 public override bool SupportsPause { 55 52 get { return true; } 56 53 } 57 54 58 #region storable fields55 #region Storable fields 59 56 [Storable] 60 57 private IRandom random = new MersenneTwister(); … … 106 103 107 104 #region ParameterProperties 108 public IFixedValueParameter<IntValue> MaximumRuntimeParameter 109 { 105 public IFixedValueParameter<IntValue> MaximumRuntimeParameter { 110 106 get { return (IFixedValueParameter<IntValue>)Parameters[MaximumRuntimeName]; } 111 107 } 112 public IFixedValueParameter<IntValue> SeedParameter 113 { 108 public IFixedValueParameter<IntValue> SeedParameter { 114 109 get { return (IFixedValueParameter<IntValue>)Parameters[SeedName]; } 115 110 } 116 public FixedValueParameter<BoolValue> SetSeedRandomlyParameter 117 { 111 public FixedValueParameter<BoolValue> SetSeedRandomlyParameter { 118 112 get { return (FixedValueParameter<BoolValue>)Parameters[SetSeedRandomlyName]; } 119 113 } 120 public IFixedValueParameter<IntValue> PopulationSizeParameter 121 { 114 public IFixedValueParameter<IntValue> PopulationSizeParameter { 122 115 get { return (IFixedValueParameter<IntValue>)Parameters[PopulationSizeName]; } 123 116 } 124 public IFixedValueParameter<IntValue> MaximumGenerationsParameter 125 { 117 public IFixedValueParameter<IntValue> MaximumGenerationsParameter { 126 118 get { return (IFixedValueParameter<IntValue>)Parameters[MaximumGenerationsName]; } 127 119 } 128 public IFixedValueParameter<IntValue> MaximumEvaluatedSolutionsParameter 129 { 120 public IFixedValueParameter<IntValue> MaximumEvaluatedSolutionsParameter { 130 121 get { return (IFixedValueParameter<IntValue>)Parameters[MaximumEvaluatedSolutionsName]; } 131 122 } 132 public IValueParameter<DoubleArray> InitialSigmaParameter 133 { 123 public IValueParameter<DoubleArray> InitialSigmaParameter { 134 124 get { return (IValueParameter<DoubleArray>)Parameters[InitialSigmaName]; } 135 125 } 136 public IConstrainedValueParameter<IIndicator> IndicatorParameter 137 { 126 public IConstrainedValueParameter<IIndicator> IndicatorParameter { 138 127 get { return (IConstrainedValueParameter<IIndicator>)Parameters[IndicatorName]; } 139 128 } … … 141 130 142 131 #region Properties 143 public int MaximumRuntime 144 { 132 public int MaximumRuntime { 145 133 get { return MaximumRuntimeParameter.Value.Value; } 146 134 set { MaximumRuntimeParameter.Value.Value = value; } 147 135 } 148 public int Seed 149 { 136 public int Seed { 150 137 get { return SeedParameter.Value.Value; } 151 138 set { SeedParameter.Value.Value = value; } 152 139 } 153 public bool SetSeedRandomly 154 { 140 public bool SetSeedRandomly { 155 141 get { return SetSeedRandomlyParameter.Value.Value; } 156 142 set { SetSeedRandomlyParameter.Value.Value = value; } 157 143 } 158 public int PopulationSize 159 { 144 public int PopulationSize { 160 145 get { return PopulationSizeParameter.Value.Value; } 161 146 set { PopulationSizeParameter.Value.Value = value; } 162 147 } 163 public int MaximumGenerations 164 { 148 public int MaximumGenerations { 165 149 get { return MaximumGenerationsParameter.Value.Value; } 166 150 set { MaximumGenerationsParameter.Value.Value = value; } 167 151 } 168 public int MaximumEvaluatedSolutions 169 { 152 public int MaximumEvaluatedSolutions { 170 153 get { return MaximumEvaluatedSolutionsParameter.Value.Value; } 171 154 set { MaximumEvaluatedSolutionsParameter.Value.Value = value; } 172 155 } 173 public DoubleArray InitialSigma 174 { 156 public DoubleArray InitialSigma { 175 157 get { return InitialSigmaParameter.Value; } 176 158 set { InitialSigmaParameter.Value = value; } 177 159 } 178 public IIndicator Indicator 179 { 160 public IIndicator Indicator { 180 161 get { return IndicatorParameter.Value; } 181 162 set { IndicatorParameter.Value = value; } … … 192 173 193 174 #region ResultsProperties 194 private int ResultsEvaluations 195 { 175 private int ResultsEvaluations { 196 176 get { return ((IntValue)Results[EvaluationsResultName].Value).Value; } 197 177 set { ((IntValue)Results[EvaluationsResultName].Value).Value = value; } 198 178 } 199 private int ResultsIterations 200 { 179 private int ResultsIterations { 201 180 get { return ((IntValue)Results[IterationsResultName].Value).Value; } 202 181 set { ((IntValue)Results[IterationsResultName].Value).Value = value; } 203 182 } 204 183 #region Datatable 205 private DataTable ResultsQualities 206 { 184 private DataTable ResultsQualities { 207 185 get { return (DataTable)Results[TimetableResultName].Value; } 208 186 } 209 private DataRow ResultsBestHypervolumeDataLine 210 { 187 private DataRow ResultsBestHypervolumeDataLine { 211 188 get { return ResultsQualities.Rows[BestHypervolumeResultName]; } 212 189 } 213 private DataRow ResultsHypervolumeDataLine 214 { 190 private DataRow ResultsHypervolumeDataLine { 215 191 get { return ResultsQualities.Rows[HypervolumeResultName]; } 216 192 } 217 private DataRow ResultsGenerationalDistanceDataLine 218 { 193 private DataRow ResultsGenerationalDistanceDataLine { 219 194 get { return ResultsQualities.Rows[GenerationalDistanceResultName]; } 220 195 } 221 private DataRow ResultsInvertedGenerationalDistanceDataLine 222 { 196 private DataRow ResultsInvertedGenerationalDistanceDataLine { 223 197 get { return ResultsQualities.Rows[InvertedGenerationalDistanceResultName]; } 224 198 } 225 private DataRow ResultsCrowdingDataLine 226 { 199 private DataRow ResultsCrowdingDataLine { 227 200 get { return ResultsQualities.Rows[CrowdingResultName]; } 228 201 } 229 private DataRow ResultsSpacingDataLine 230 { 202 private DataRow ResultsSpacingDataLine { 231 203 get { return ResultsQualities.Rows[SpacingResultName]; } 232 204 } 233 private DataRow ResultsHypervolumeDifferenceDataLine 234 { 205 private DataRow ResultsHypervolumeDifferenceDataLine { 235 206 get { return ResultsQualities.Rows[DifferenceToBestKnownHypervolumeResultName]; } 236 207 } 237 208 #endregion 238 209 //QualityIndicators 239 private double ResultsHypervolume 240 { 210 private double ResultsHypervolume { 241 211 get { return ((DoubleValue)Results[HypervolumeResultName].Value).Value; } 242 212 set { ((DoubleValue)Results[HypervolumeResultName].Value).Value = value; } 243 213 } 244 private double ResultsGenerationalDistance 245 { 214 private double ResultsGenerationalDistance { 246 215 get { return ((DoubleValue)Results[GenerationalDistanceResultName].Value).Value; } 247 216 set { ((DoubleValue)Results[GenerationalDistanceResultName].Value).Value = value; } 248 217 } 249 private double ResultsInvertedGenerationalDistance 250 { 218 private double ResultsInvertedGenerationalDistance { 251 219 get { return ((DoubleValue)Results[InvertedGenerationalDistanceResultName].Value).Value; } 252 220 set { ((DoubleValue)Results[InvertedGenerationalDistanceResultName].Value).Value = value; } 253 221 } 254 private double ResultsCrowding 255 { 222 private double ResultsCrowding { 256 223 get { return ((DoubleValue)Results[CrowdingResultName].Value).Value; } 257 224 set { ((DoubleValue)Results[CrowdingResultName].Value).Value = value; } 258 225 } 259 private double ResultsSpacing 260 { 226 private double ResultsSpacing { 261 227 get { return ((DoubleValue)Results[SpacingResultName].Value).Value; } 262 228 set { ((DoubleValue)Results[SpacingResultName].Value).Value = value; } 263 229 } 264 private double ResultsBestHypervolume 265 { 230 private double ResultsBestHypervolume { 266 231 get { return ((DoubleValue)Results[BestHypervolumeResultName].Value).Value; } 267 232 set { ((DoubleValue)Results[BestHypervolumeResultName].Value).Value = value; } 268 233 } 269 private double ResultsBestKnownHypervolume 270 { 234 private double ResultsBestKnownHypervolume { 271 235 get { return ((DoubleValue)Results[BestKnownHypervolumeResultName].Value).Value; } 272 236 set { ((DoubleValue)Results[BestKnownHypervolumeResultName].Value).Value = value; } 273 237 } 274 private double ResultsDifferenceBestKnownHypervolume 275 { 238 private double ResultsDifferenceBestKnownHypervolume { 276 239 get { return ((DoubleValue)Results[DifferenceToBestKnownHypervolumeResultName].Value).Value; } 277 240 set { ((DoubleValue)Results[DifferenceToBestKnownHypervolumeResultName].Value).Value = value; } … … 279 242 } 280 243 //Solutions 281 private DoubleMatrix ResultsSolutions 282 { 244 private DoubleMatrix ResultsSolutions { 283 245 get { return (DoubleMatrix)Results[CurrentFrontResultName].Value; } 284 246 set { Results[CurrentFrontResultName].Value = value; } 285 247 } 286 private ScatterPlotContent ResultsScatterPlot 287 { 248 private ScatterPlotContent ResultsScatterPlot { 288 249 get { return (ScatterPlotContent)Results[ScatterPlotResultName].Value; } 289 250 set { Results[ScatterPlotResultName].Value = value; } … … 401 362 ResultsDifferenceBestKnownHypervolume = ResultsBestKnownHypervolume; 402 363 } 403 //TODO? move FrontScatterPlotContent partially? to MultiobjectiveTestProblem?404 364 ResultsScatterPlot = new ScatterPlotContent(new double[0][], new double[0][], problem.BestKnownFront.ToJaggedArray(), problem.Objectives); 405 365 } … … 413 373 ResultsIterations++; 414 374 cancellationToken.ThrowIfCancellationRequested(); 415 } 416 finally { 375 } finally { 417 376 Analyze(); 418 377 } 419 378 } 420 421 422 379 } 423 380 private void Iterate() { … … 483 440 int[] ranks; 484 441 var fronts = DominationCalculator<Individual>.CalculateAllParetoFronts(parents.ToArray(), parents.Select(i => i.PenalizedFitness).ToArray(), Problem.Maximization, out ranks); 485 // NonDominatedSort(parents, individual => individual.PenalizedFitness);486 442 487 443 //deselect the highest rank fronts until we would end up with less or equal mu elements … … 508 464 foreach (var p in parents.Skip(solutions.Length).Where(i => i.Selected)) 509 465 p.UpdateAsOffspring(); 510 511 466 for (var i = 0; i < solutions.Length; i++) 512 467 if (parents[i].Selected) 513 468 parents[i].UpdateAsParent(parents[i + solutions.Length].Selected); 514 515 469 solutions = parents.Where(p => p.Selected).ToArray(); 516 470 } 517 471 518 472 private void Analyze() { 519 //TODO? move FrontScatterPlotContent partially to MultiobjectiveTestProblem520 473 ResultsScatterPlot = new ScatterPlotContent(solutions.Select(x => x.Fitness).ToArray(), solutions.Select(x => x.Mean.ToArray()).ToArray(), ResultsScatterPlot.ParetoFront, ResultsScatterPlot.Objectives); 521 522 474 ResultsSolutions = solutions.Select(x => x.Mean.ToArray()).ToMatrix(); 523 475 … … 550 502 random); 551 503 } 552 553 504 } 554 505 }
Note: See TracChangeset
for help on using the changeset viewer.