Changeset 12075 for branches/SymbolicExpressionTreeDiversityAnalyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression
- Timestamp:
- 02/25/15 17:53:25 (10 years ago)
- Location:
- branches/SymbolicExpressionTreeDiversityAnalyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/SymbolicExpressionTreeDiversityAnalyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression
- Property svn:mergeinfo changed (with no actual effect on merging)
-
branches/SymbolicExpressionTreeDiversityAnalyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionPhenotypicDiversityAnalyzer.cs
r12049 r12075 20 20 #endregion 21 21 22 using System.Collections.Generic; 22 23 using System.Linq; 23 24 using HeuristicLab.Analysis; … … 26 27 using HeuristicLab.Data; 27 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 29 using HeuristicLab.Optimization; 28 30 using HeuristicLab.Parameters; 29 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 32 34 [Item("SymbolicRegressionPhenotypicDiversityAnalyzer", "An analyzer which calculates diversity based on the phenotypic distance between trees")] 33 35 [StorableClass] 34 public class SymbolicRegressionPhenotypicDiversityAnalyzer : SingleObjectivePopulationDiversityAnalyzer {36 public class SymbolicRegressionPhenotypicDiversityAnalyzer : PopulationSimilarityAnalyzer { 35 37 #region parameter names 36 38 private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree"; … … 59 61 #endregion 60 62 61 public SymbolicRegressionPhenotypicDiversityAnalyzer( ) {62 SimilarityCalculator = new SymbolicExpressionTreePhenotypicSimilarityCalculator { SolutionVariableName = "SymbolicExpressionTree", QualityVariableName = "Quality" };63 public SymbolicRegressionPhenotypicDiversityAnalyzer(IEnumerable<ISingleObjectiveSolutionSimilarityCalculator> validSimilarityCalculators) 64 : base(validSimilarityCalculators) { 63 65 #region add parameters 64 66 Parameters.Add(new ScopeTreeLookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression trees.")); … … 68 70 Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The upper and lower limit that should be used as cut off value for the output values of symbolic data analysis trees.")); 69 71 #endregion 72 73 UpdateCounterParameter.ActualName = "PhenotypicDiversityAnalyzerUpdateCounter"; 70 74 } 71 75 … … 84 88 85 89 public override IOperation Apply() { 86 var trees = SymbolicExpressionTreeParameter.ActualValue; 87 var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue; 88 var ds = ProblemDataParameter.ActualValue.Dataset; 89 var rows = ProblemDataParameter.ActualValue.TrainingIndices; 90 int updateInterval = UpdateIntervalParameter.Value.Value; 91 IntValue updateCounter = UpdateCounterParameter.ActualValue; 90 92 91 var evaluatedValues = new ItemArray<DoubleArray>(trees.Select(t => new DoubleArray(interpreter.GetSymbolicExpressionTreeValues(t, ds, rows).ToArray()))); 92 EvaluatedValuesParameter.ActualValue = evaluatedValues; 93 if (updateCounter == null) { 94 updateCounter = new IntValue(updateInterval); 95 UpdateCounterParameter.ActualValue = updateCounter; 96 } 93 97 98 if (updateCounter.Value == updateInterval) { 99 var trees = SymbolicExpressionTreeParameter.ActualValue; 100 var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue; 101 var ds = ProblemDataParameter.ActualValue.Dataset; 102 var rows = ProblemDataParameter.ActualValue.TrainingIndices; 103 104 var evaluatedValues = new ItemArray<DoubleArray>(trees.Select(t => new DoubleArray(interpreter.GetSymbolicExpressionTreeValues(t, ds, rows).ToArray()))); 105 EvaluatedValuesParameter.ActualValue = evaluatedValues; 106 } 94 107 return base.Apply(); 95 108 } -
branches/SymbolicExpressionTreeDiversityAnalyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveProblem.cs
r12068 r12075 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Core; 25 using HeuristicLab.Optimization; 25 26 using HeuristicLab.Parameters; 26 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 111 112 Operators.Add(new SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer()); 112 113 Operators.Add(new SymbolicRegressionSolutionsAnalyzer()); 113 Operators.Add(new SymbolicRegressionPhenotypicDiversityAnalyzer());114 114 Operators.Add(new SymbolicExpressionTreePhenotypicSimilarityCalculator()); 115 Operators.Add(new SymbolicRegressionPhenotypicDiversityAnalyzer(Operators.OfType<SymbolicExpressionTreePhenotypicSimilarityCalculator>()) { DiversityResultName = "Phenotypic Diversity" }); 115 116 ParameterizeOperators(); 116 117 } … … 143 144 } 144 145 145 foreach (var op in Operators.OfType< SymbolicExpressionTreePhenotypicSimilarityCalculator>()) {146 foreach (var op in Operators.OfType<ISingleObjectiveSolutionSimilarityCalculator>()) { 146 147 op.SolutionVariableName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName; 147 op.ProblemData = ProblemData; 148 op.Interpreter = SymbolicExpressionTreeInterpreter; 149 } 148 op.QualityVariableName = Evaluator.QualityParameter.ActualName; 150 149 151 foreach (var op in Operators.OfType<SymbolicRegressionPhenotypicDiversityAnalyzer>()) { 152 var sim = Operators.OfType<SymbolicExpressionTreePhenotypicSimilarityCalculator>().FirstOrDefault(); 153 if (sim != null) 154 op.SimilarityCalculator = sim; 150 if (op is SymbolicExpressionTreePhenotypicSimilarityCalculator) { 151 var phenotypicSimilarityCalculator = (SymbolicExpressionTreePhenotypicSimilarityCalculator)op; 152 phenotypicSimilarityCalculator.ProblemData = ProblemData; 153 phenotypicSimilarityCalculator.Interpreter = SymbolicExpressionTreeInterpreter; 154 } 155 155 } 156 156 }
Note: See TracChangeset
for help on using the changeset viewer.