Changeset 12892 for branches/HeuristicLab.EvolutionTracking
- Timestamp:
- 08/23/15 13:21:12 (9 years ago)
- Location:
- branches/HeuristicLab.EvolutionTracking
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Analyzers/GenealogyAnalyzer.cs
r12891 r12892 22 22 using System.Collections.Generic; 23 23 using System.Linq; 24 using HeuristicLab.Analysis;25 24 using HeuristicLab.Common; 26 25 using HeuristicLab.Core; … … 34 33 [StorableClass] 35 34 [Item("GenealogyAnalyzer", "An analyzer which performs the necessary instrumentation to record the evolution of a genetic algorithm.")] 36 public class GenealogyAnalyzer<T> : SingleSuccessorOperator, IAnalyzer35 public abstract class GenealogyAnalyzer<T> : SingleSuccessorOperator, IAnalyzer 37 36 where T : class, IItem { 38 37 #region parameter names … … 146 145 #endregion properties 147 146 148 p ublicGenealogyAnalyzer() {147 protected GenealogyAnalyzer() { 149 148 #region add parameters 150 149 // the instrumented operators … … 166 165 Parameters.Add(new ValueParameter<IManipulatorOperator<T>>(AfterManipulatorOperatorParameterName)); 167 166 #endregion add parameters 168 }169 170 public override IDeepCloneable Clone(Cloner cloner) {171 return new GenealogyAnalyzer<T>(this, cloner);172 167 } 173 168 … … 246 241 } 247 242 243 protected abstract void EvaluateIntermediateChildren(); 244 248 245 public override IOperation Apply() { 249 246 IGenealogyGraph<T> genealogyGraph; … … 273 270 int index = 0; 274 271 T elite = null; 275 272 // identify previous elite individual 276 273 for (int i = 0; i < population.Length; ++i) { 277 274 if (genealogyGraph.GetByContent(population[i]).Rank.Equals(generation - 1)) { … … 281 278 } 282 279 } 283 280 // add current elite and connect with previous 284 281 #region add elite in the graph and connect it with the previous elite 285 282 if (elite != null) { … … 303 300 vertex.Quality = qualities[i].Value; 304 301 } 302 // update qualities for intermediate vertices 303 EvaluateIntermediateChildren(); 304 305 305 // remove extra graph nodes (added by the instrumented operators in the case of offspring selection) 306 306 var pop = new HashSet<T>(population); -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisGenealogyAnalyzer.cs
r11227 r12892 1 using HeuristicLab.Core; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 22 using System.Linq; 23 using HeuristicLab.Common; 24 using HeuristicLab.Core; 25 using HeuristicLab.Data; 2 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 3 27 using HeuristicLab.EvolutionTracking; 28 using HeuristicLab.Optimization; 29 using HeuristicLab.Parameters; 4 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 5 31 6 32 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 7 [Item("SymbolicDataAnalysisGenealogyAnalyzer", " ")]33 [Item("SymbolicDataAnalysisGenealogyAnalyzer", "Genealogy analyzer for symbolic data analysis problems")] 8 34 [StorableClass] 9 35 public class SymbolicDataAnalysisGenealogyAnalyzer : GenealogyAnalyzer<ISymbolicExpressionTree> { 10 public SymbolicDataAnalysisGenealogyAnalyzer() { } 36 private const string EvaluatorParameterName = "Evaluator"; 37 private const string ProblemDataParameterName = "ProblemData"; 38 private const string InterpreterParameterName = "SymbolicExpressionTreeInterpreter"; 39 private const string EstimationLimitsParameterName = "EstimationLimits"; 40 private const string ApplyLinearScalingParameterName = "ApplyLinearScaling"; 41 42 #region parameters 43 public ILookupParameter<ISingleObjectiveEvaluator> EvaluatorParameter { 44 get { 45 return (ILookupParameter<ISingleObjectiveEvaluator>)Parameters[EvaluatorParameterName]; 46 } 47 } 48 49 public ILookupParameter<IDataAnalysisProblemData> ProblemDataParameter { 50 get { 51 return (ILookupParameter<IDataAnalysisProblemData>)Parameters[ProblemDataParameterName]; 52 } 53 } 54 55 public ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> InterpreterParameter { 56 get { 57 return (ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>)Parameters[InterpreterParameterName]; 58 } 59 } 60 61 public ILookupParameter<DoubleLimit> EstimationLimitsParameter { 62 get { return (ILookupParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; } 63 } 64 65 public ILookupParameter<BoolValue> ApplyLinearScalingParameter { 66 get { return (ILookupParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; } 67 } 68 #endregion 69 70 public SymbolicDataAnalysisGenealogyAnalyzer() { 71 Parameters.Add(new LookupParameter<ISingleObjectiveEvaluator>(EvaluatorParameterName)); 72 Parameters.Add(new LookupParameter<IDataAnalysisProblemData>(ProblemDataParameterName)); 73 Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(InterpreterParameterName)); 74 Parameters.Add(new LookupParameter<DoubleLimit>(EstimationLimitsParameterName)); 75 Parameters.Add(new LookupParameter<BoolValue>(ApplyLinearScalingParameterName)); 76 } 77 78 public SymbolicDataAnalysisGenealogyAnalyzer(SymbolicDataAnalysisGenealogyAnalyzer original, Cloner cloner) 79 : base(original, cloner) { 80 } 81 82 public override IDeepCloneable Clone(Cloner cloner) { 83 return new SymbolicDataAnalysisGenealogyAnalyzer(this, cloner); 84 } 11 85 12 86 [StorableConstructor] 13 protected SymbolicDataAnalysisGenealogyAnalyzer(bool deserializing) : base(deserializing) { } 87 protected SymbolicDataAnalysisGenealogyAnalyzer(bool deserializing) : base(deserializing) { 88 } 89 90 protected override void EvaluateIntermediateChildren() { 91 var results = ResultsParameter.ActualValue; 92 var graph = (IGenealogyGraph<ISymbolicExpressionTree>)results["PopulationGraph"].Value; 93 var population = PopulationParameter.ActualValue; 94 var generation = GenerationsParameter.ActualValue.Value; 95 var problemData = ProblemDataParameter.ActualValue; 96 97 var vertices = population.Select(graph.GetByContent).Where(x => x.InDegree == 1).Select(x => x.Parents.First()); 98 var intermediateVertices = vertices.Where(x => x.Rank.IsAlmost(generation - 0.5)); 99 100 var classificationProblemData = problemData as IClassificationProblemData; 101 var regressionProblemData = problemData as IRegressionProblemData; 102 if (classificationProblemData != null) { 103 var evaluator = (ISymbolicDataAnalysisSingleObjectiveEvaluator<IClassificationProblemData>)EvaluatorParameter.ActualValue; 104 foreach (var v in intermediateVertices) { 105 var child = v.Data; 106 v.Quality = evaluator.Evaluate(this.ExecutionContext, child, classificationProblemData, classificationProblemData.TrainingIndices); 107 } 108 } else if (regressionProblemData != null) { 109 var evaluator = (ISymbolicDataAnalysisSingleObjectiveEvaluator<IRegressionProblemData>)EvaluatorParameter.ActualValue; 110 foreach (var v in intermediateVertices) { 111 var child = v.Data; 112 v.Quality = evaluator.Evaluate(this.ExecutionContext, child, regressionProblemData, problemData.TrainingIndices); 113 } 114 } 115 } 14 116 } 15 117 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj
r12225 r12892 183 183 <Compile Include="Analyzers\BuildingBlockAnalyzers\SymbolicDataAnalysisPoly10Analyzer.cs" /> 184 184 <Compile Include="Analyzers\SymbolicDataAnalysisBottomUpDiversityAnalyzer.cs" /> 185 <Compile Include="Analyzers\SymbolicDataAnalysisGeneticOperatorImprovementAnalyzer.cs" /> 185 186 <Compile Include="Analyzers\SymbolicDataAnalysisSingleObjectivePruningAnalyzer.cs" /> 186 187 <Compile Include="Analyzers\SymbolicDataAnalysisGenealogyAnalyzer.cs" /> -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisSingleObjectiveProblem.cs
r12155 r12892 25 25 using HeuristicLab.Core; 26 26 using HeuristicLab.Data; 27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;28 using HeuristicLab.EvolutionTracking;29 27 using HeuristicLab.Optimization; 30 28 using HeuristicLab.Parameters; … … 34 32 [StorableClass] 35 33 public abstract class SymbolicDataAnalysisSingleObjectiveProblem<T, U, V> : SymbolicDataAnalysisProblem<T, U, V>, ISymbolicDataAnalysisSingleObjectiveProblem 36 where T : class, IDataAnalysisProblemData34 where T : class, IDataAnalysisProblemData 37 35 where U : class, ISymbolicDataAnalysisSingleObjectiveEvaluator<T> 38 36 where V : class, ISymbolicDataAnalysisSolutionCreator { … … 118 116 } 119 117 120 foreach (var op in Operators.OfType< GenealogyAnalyzer<ISymbolicExpressionTree>>()) {118 foreach (var op in Operators.OfType<SymbolicDataAnalysisGenealogyAnalyzer>()) { 121 119 op.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName; 122 120 op.PopulationParameter.ActualName = Evaluator.SymbolicExpressionTreeParameter.ActualName; -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.TravelingSalesman/3.3/Analyzers/TSPGenealogyAnalyzer.cs
r11864 r12892 1 using HeuristicLab.Core; 1 using HeuristicLab.Common; 2 using HeuristicLab.Core; 2 3 using HeuristicLab.Encodings.PermutationEncoding; 3 4 using HeuristicLab.EvolutionTracking; … … 12 13 [StorableConstructor] 13 14 protected TSPGenealogyAnalyzer(bool deserializing) : base(deserializing) { } 15 16 public TSPGenealogyAnalyzer(TSPGenealogyAnalyzer original, Cloner cloner) : base(original, cloner) { 17 } 18 19 public override IDeepCloneable Clone(Cloner cloner) { 20 return new TSPGenealogyAnalyzer(this, cloner); 21 } 22 23 protected override void EvaluateIntermediateChildren() { 24 throw new System.NotImplementedException(); 25 } 14 26 } 15 27 }
Note: See TracChangeset
for help on using the changeset viewer.