Changeset 12988 for branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SchemaDiversification
- Timestamp:
- 10/09/15 00:16:03 (9 years ago)
- Location:
- branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SchemaDiversification
- Files:
-
- 3 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SchemaDiversification/DiversificationStatisticsOperator.cs
r12966 r12988 20 20 #endregion 21 21 22 using System.Linq;22 using HeuristicLab.Analysis; 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Core; 25 using HeuristicLab.Data; 25 26 using HeuristicLab.Operators; 27 using HeuristicLab.Optimization; 28 using HeuristicLab.Parameters; 26 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 30 … … 29 32 [Item("SchemaCleanupOperator", "Operator which removes the schemas from the global scope after they have been evaluated.")] 30 33 [StorableClass] 31 public class SchemaCleanupOperator : SingleSuccessorOperator { 32 public SchemaCleanupOperator() { } 34 public class DiversificationStatisticsOperator : SingleSuccessorOperator { 35 private const string NumberOfChangedTreesParameterName = "NumberOfChangedTrees"; 36 private const string NumberOfSchemasParameterName = "NumberOfSchemas"; 37 private const string AverageSchemaLengthParameterName = "AverageSchemaLength"; 38 private const string ResultCollectionParameterName = "Results"; 33 39 34 protected SchemaCleanupOperator(SchemaCleanupOperator original, Cloner cloner) : base(original, cloner) { } 40 public ILookupParameter<IntValue> NumberOfChangedTreesParameter { 41 get { return (ILookupParameter<IntValue>)Parameters[NumberOfChangedTreesParameterName]; } 42 } 43 public ILookupParameter<IntValue> NumberOfSchemasParameter { 44 get { return (ILookupParameter<IntValue>)Parameters[NumberOfSchemasParameterName]; } 45 } 46 public ILookupParameter<DoubleValue> AverageSchemaLengthParameter { 47 get { return (ILookupParameter<DoubleValue>)Parameters[AverageSchemaLengthParameterName]; } 48 } 49 public ILookupParameter<ResultCollection> ResultCollectionParameter { 50 get { return (ILookupParameter<ResultCollection>)Parameters[ResultCollectionParameterName]; } 51 } 35 52 36 public override IDeepCloneable Clone(Cloner cloner) { return new SchemaCleanupOperator(this, cloner); } 53 public DiversificationStatisticsOperator() { 54 Parameters.Add(new LookupParameter<IntValue>(NumberOfChangedTreesParameterName)); 55 Parameters.Add(new LookupParameter<IntValue>(NumberOfSchemasParameterName)); 56 Parameters.Add(new LookupParameter<DoubleValue>(AverageSchemaLengthParameterName)); 57 Parameters.Add(new LookupParameter<ResultCollection>(ResultCollectionParameterName)); 58 } 59 60 protected DiversificationStatisticsOperator(DiversificationStatisticsOperator original, Cloner cloner) : base(original, cloner) { } 61 62 public override IDeepCloneable Clone(Cloner cloner) { return new DiversificationStatisticsOperator(this, cloner); } 37 63 38 64 [StorableConstructor] 39 protected SchemaCleanupOperator(bool deserializing) : base(deserializing) { }65 protected DiversificationStatisticsOperator(bool deserializing) : base(deserializing) { } 40 66 41 67 public override IOperation Apply() { 42 foreach (var scope in ExecutionContext.Scope.SubScopes.Where(x => x.Name.Equals("Schema"))) { 43 foreach (var subscope in scope.SubScopes) { subscope.Variables.Clear(); } 44 scope.SubScopes.Clear(); 45 scope.Variables.Clear(); 68 69 var results = ResultCollectionParameter.ActualValue; 70 DataTable table; 71 if (!results.ContainsKey("NumberOfChangedTrees")) { 72 table = new DataTable(); 73 results.Add(new Result("NumberOfChangedTrees", table)); 74 var row = new DataRow("Changed trees"); 75 table.Rows.Add(row); 46 76 } 47 ExecutionContext.Scope.SubScopes.RemoveAll(x => x.Name.Equals("Schema")); 77 if (!results.ContainsKey("AverageSchemaLength")) { 78 table = new DataTable(); 79 results.Add(new Result("AverageSchemaLength", table)); 80 var row = new DataRow("Average schema length"); 81 table.Rows.Add(row); 82 } 83 if (!results.ContainsKey("NumberOfSchemas")) { 84 table = new DataTable(); 85 results.Add(new Result("NumberOfSchemas", table)); 86 var row = new DataRow("Number of schemas"); 87 table.Rows.Add(row); 88 } 89 ((DataTable)results["NumberOfChangedTrees"].Value).Rows["Changed trees"].Values.Add(NumberOfChangedTreesParameter.ActualValue.Value); 90 ((DataTable)results["AverageSchemaLength"].Value).Rows["Average schema length"].Values.Add(AverageSchemaLengthParameter.ActualValue.Value); 91 ((DataTable)results["NumberOfSchemas"].Value).Rows["Number of schemas"].Values.Add(NumberOfSchemasParameter.ActualValue.Value); 92 48 93 return base.Apply(); 49 94 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SchemaDiversification/SchemaCreator.cs
r12979 r12988 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using System.Linq; 24 using HeuristicLab.Analysis;25 25 using HeuristicLab.Common; 26 26 using HeuristicLab.Core; … … 28 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 29 29 using HeuristicLab.EvolutionTracking; 30 using HeuristicLab.Operators;31 using HeuristicLab.Optimization.Operators;32 30 using HeuristicLab.Parameters; 33 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 44 42 private const string ExecuteInParallelParameterName = "ExecuteInParallel"; 45 43 private const string MaxDegreeOfParalellismParameterName = "MaxDegreeOfParallelism"; 44 private const string PercentageOfPopulationParameterName = "PercentageOfPopulationToDiversify"; 45 private const string ScaleEstimatedValuesParameterName = "ScaleEstimatedValues"; 46 private const string ExclusiveMatchingParameterName = "ExclusiveMatching"; 47 private const string NumberOfChangedTreesParameterName = "NumberOfChangedTrees"; 48 private const string NumberOfSchemasParameterName = "NumberOfSchemas"; 49 private const string AverageSchemaLengthParameterName = "AverageSchemaLength"; 46 50 47 51 #region parameters 52 public IFixedValueParameter<BoolValue> ExclusiveMatchingParameter { 53 get { return (IFixedValueParameter<BoolValue>)Parameters[ExclusiveMatchingParameterName]; } 54 } 55 public IFixedValueParameter<BoolValue> ScaleEstimatedValuesParameter { 56 get { return (IFixedValueParameter<BoolValue>)Parameters[ScaleEstimatedValuesParameterName]; } 57 } 58 public IFixedValueParameter<PercentValue> PercentageOfPopulationParameter { 59 get { return (IFixedValueParameter<PercentValue>)Parameters[PercentageOfPopulationParameterName]; } 60 } 48 61 public IFixedValueParameter<IntValue> MinimumSchemaLengthParameter { 49 62 get { return (IFixedValueParameter<IntValue>)Parameters[MinimumSchemaLengthParameterName]; } 50 63 } 51 52 64 public IFixedValueParameter<BoolValue> ExecuteInParallelParameter { 53 65 get { return (IFixedValueParameter<BoolValue>)Parameters[ExecuteInParallelParameterName]; } 54 66 } 55 56 67 public IFixedValueParameter<IntValue> MaxDegreeOfParallelismParameter { 57 68 get { return (IFixedValueParameter<IntValue>)Parameters[MaxDegreeOfParalellismParameterName]; } 58 69 } 59 60 70 public IFixedValueParameter<PercentValue> MinimumSchemaFrequencyParameter { 61 71 get { return (IFixedValueParameter<PercentValue>)Parameters[MinimumSchemaFrequencyParameterName]; } 62 72 } 63 64 73 public IFixedValueParameter<PercentValue> MinimumPhenotypicSimilarityParameter { 65 74 get { return (IFixedValueParameter<PercentValue>)Parameters[MinimumPhenotypicSimilarityParameterName]; } 66 75 } 67 68 76 public IFixedValueParameter<PercentValue> ReplacementRatioParameter { 69 77 get { return (IFixedValueParameter<PercentValue>)Parameters[ReplacementRatioParameterName]; } 78 } 79 public IValueParameter<IntValue> NumberOfSchemasParameter { 80 get { return (IValueParameter<IntValue>)Parameters[NumberOfSchemasParameterName]; } 81 } 82 public IValueParameter<DoubleValue> AverageSchemaLengthParameter { 83 get { return (IValueParameter<DoubleValue>)Parameters[AverageSchemaLengthParameterName]; } 84 } 85 public IValueParameter<IntValue> NumberOfChangedTreesParameter { 86 get { return (IValueParameter<IntValue>)Parameters[NumberOfChangedTreesParameterName]; } 70 87 } 71 88 #endregion … … 75 92 public int MaxDegreeOfParallelism { get { return MaxDegreeOfParallelismParameter.Value.Value; } } 76 93 public bool ExecuteInParallel { get { return ExecuteInParallelParameter.Value.Value; } } 94 public double PercentageOfPopulation { get { return PercentageOfPopulationParameter.Value.Value; } } 77 95 #endregion 78 96 79 private SchemaEvaluator schemaEvaluator;80 private SchemaCleanupOperator schemaCleanupOperator;81 private DataReducer changedTreesReducer;82 private DataTableValuesCollector valuesCollector;83 private ResultsCollector resultsCollector;84 97 private UpdateEstimatedValuesOperator updateEstimatedValuesOperator; 85 86 private void ParameterizeOperators() { 87 schemaEvaluator = new SchemaEvaluator(); 88 schemaCleanupOperator = new SchemaCleanupOperator(); 89 90 changedTreesReducer = new DataReducer(); 91 changedTreesReducer.ParameterToReduce.ActualName = schemaEvaluator.ChangedTreesParameter.ActualName; 92 changedTreesReducer.ReductionOperation.Value = new ReductionOperation(ReductionOperations.Sum); 93 changedTreesReducer.TargetOperation.Value = new ReductionOperation(ReductionOperations.Assign); // asign the sum to the target parameter 94 changedTreesReducer.TargetParameter.ActualName = "NumberOfChangedTrees"; 95 96 valuesCollector = new DataTableValuesCollector(); 97 valuesCollector.CollectedValues.Add(new LookupParameter<IntValue>("NumberOfChangedTrees")); 98 valuesCollector.DataTableParameter.ActualName = "Diversification"; 99 100 resultsCollector = new ResultsCollector(); 101 resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>("Diversification")); 102 103 updateEstimatedValuesOperator = new UpdateEstimatedValuesOperator(); 104 } 98 private DiversificationStatisticsOperator diversificationStatisticsOperator; 105 99 106 100 public SchemaCreator() { … … 109 103 Parameters.Add(new FixedValueParameter<PercentValue>(MinimumPhenotypicSimilarityParameterName, new PercentValue(0.9))); 110 104 Parameters.Add(new FixedValueParameter<PercentValue>(ReplacementRatioParameterName, new PercentValue(0.9))); 105 Parameters.Add(new FixedValueParameter<PercentValue>(PercentageOfPopulationParameterName, new PercentValue(1))); 111 106 Parameters.Add(new FixedValueParameter<BoolValue>(RandomReplacementParameterName, new BoolValue(false))); 112 107 Parameters.Add(new FixedValueParameter<BoolValue>(ExecuteInParallelParameterName, new BoolValue(false))); 113 108 Parameters.Add(new FixedValueParameter<IntValue>(MaxDegreeOfParalellismParameterName, new IntValue(-1))); 109 Parameters.Add(new FixedValueParameter<BoolValue>(ScaleEstimatedValuesParameterName, new BoolValue(true))); 110 Parameters.Add(new FixedValueParameter<BoolValue>(ExclusiveMatchingParameterName, new BoolValue(false))); 111 Parameters.Add(new ValueParameter<IntValue>(NumberOfChangedTreesParameterName, new IntValue(0))); 112 Parameters.Add(new ValueParameter<IntValue>(NumberOfSchemasParameterName, new IntValue(0))); 113 Parameters.Add(new ValueParameter<DoubleValue>(AverageSchemaLengthParameterName, new DoubleValue(0))); 114 115 NumberOfChangedTreesParameter.Hidden = true; 116 NumberOfSchemasParameter.Hidden = true; 117 AverageSchemaLengthParameter.Hidden = true; 114 118 115 119 ExecuteInParallelParameter.Hidden = true; 116 120 MaxDegreeOfParallelismParameter.Hidden = true; 117 118 ParameterizeOperators();119 121 } 120 122 … … 133 135 if (gen < 1 || GenealogyGraph == null) 134 136 return base.Apply(); 137 138 var n = (int)Math.Round(ExecutionContext.Scope.SubScopes.Count * PercentageOfPopulation); 139 var scopes = new ScopeList(ExecutionContext.Scope.SubScopes.Take(n)); 140 135 141 // for now, only consider crossover offspring 136 137 var scopes = new ScopeList(this.ExecutionContext.Scope.SubScopes); 138 var vertices = GenealogyGraph.GetByRank(gen).Where(x => x.InDegree == 2).Cast<IGenealogyGraphNode<ISymbolicExpressionTree>>(); 142 var vertices = from s in scopes 143 let t = (ISymbolicExpressionTree)s.Variables["SymbolicExpressionTree"].Value 144 let v = GenealogyGraph.GetByContent(t) 145 where v.InDegree == 2 146 select v; 147 139 148 var groups = vertices.GroupBy(x => x.Parents.First()).OrderByDescending(g => g.Count()).ToList(); 140 149 var anySubtreeSymbol = new AnySubtreeSymbol(); 141 150 142 if (schemaEvaluator == null || schemaCleanupOperator == null || changedTreesReducer == null || valuesCollector == null || resultsCollector == null)143 ParameterizeOperators();144 145 var reduceChangedTrees = ExecutionContext.CreateChildOperation(changedTreesReducer);146 var collectValues = ExecutionContext.CreateChildOperation(valuesCollector);147 var collectResults = ExecutionContext.CreateChildOperation(resultsCollector);148 149 151 var updateEstimatedValues = new OperationCollection { Parallel = true }; 152 if (updateEstimatedValuesOperator == null) 153 updateEstimatedValuesOperator = new UpdateEstimatedValuesOperator(); 154 150 155 foreach (var s in scopes) { 151 156 if (!s.Variables.ContainsKey("EstimatedValues")) … … 153 158 updateEstimatedValues.Add(ExecutionContext.CreateChildOperation(updateEstimatedValuesOperator, s)); 154 159 } 155 var oc = new OperationCollection { updateEstimatedValues }; 156 160 161 var evaluateSchemas = new OperationCollection(); 162 var schemas = new List<ISymbolicExpressionTree>(); 163 var wildCardCounts = new List<double>(); 157 164 #region create schemas and add subscopes representing the individuals 158 165 foreach (var g in groups) { … … 167 174 Array.Sort(indices); 168 175 var nodesToReplace = indices.Select(x => nodes[x]).ToList(); 176 int w = 0; 169 177 for (int i = nodesToReplace.Count - 1; i >= 0; --i) { 170 178 var node = nodesToReplace[i]; … … 177 185 ReplaceSubtree(node, replacement, false); 178 186 replaced = true; 187 ++w; 179 188 } 180 189 if (replaced) { 181 var scope = new Scope("Schema"); 182 scope.Variables.Add(new Core.Variable("Schema", schema)); 183 scope.SubScopes.AddRange(ShallowCopy(scopes)); 184 185 oc.Add(ExecutionContext.CreateChildOperation(schemaEvaluator, scope)); 186 ExecutionContext.Scope.SubScopes.Add(scope); 190 // store the schemas and the number of wildcards they contain in two lists 191 schemas.Add(schema); 192 wildCardCounts.Add(w); 187 193 } 188 194 } 195 196 for (int i = 0; i < schemas.Count; ++i) { 197 var schema = schemas[i]; 198 evaluateSchemas.Add(ExecutionContext.CreateChildOperation(new SchemaEvaluator { Schema = schema }, ExecutionContext.Scope)); 199 } 189 200 #endregion 190 201 191 var cleanup = ExecutionContext.CreateChildOperation(schemaCleanupOperator); 202 if (diversificationStatisticsOperator == null) 203 diversificationStatisticsOperator = new DiversificationStatisticsOperator(); 204 205 var calculateStatistics = ExecutionContext.CreateChildOperation(diversificationStatisticsOperator); 206 207 // set parameters for statistics 208 AverageSchemaLengthParameter.Value = new DoubleValue(schemas.Average(x => x.Length)); 209 NumberOfSchemasParameter.Value = new IntValue(schemas.Count); 210 NumberOfChangedTreesParameter.Value = new IntValue(0); 211 192 212 // return an operation collection containing all the scope operations + base.Apply() 193 return new OperationCollection { oc, reduceChangedTrees, collectValues, collectResults, cleanup, base.Apply() }; 194 } 195 196 private static ScopeList ShallowCopy(ScopeList scopes) { 197 var scopeList = new ScopeList(); 198 // shallow-copy means that we create a new scope but reuse the variables 199 foreach (var scope in scopes) { 200 var s = new Scope(scope.Name); 201 foreach (var v in scope.Variables) 202 s.Variables.Add(v); 203 scopeList.Add(s); 204 } 205 return scopeList; 213 return new OperationCollection { updateEstimatedValues, evaluateSchemas, calculateStatistics, base.Apply() }; 206 214 } 207 215 -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SchemaDiversification/SchemaEvaluator.cs
r12979 r12988 50 50 private const string MutatorParameterName = "Mutator"; 51 51 private const string RandomReplacementParameterName = "RandomReplacement"; 52 private const string ChangedTreesParameterName = "ChangedTrees";52 private const string NumberOfChangedTreesParameterName = "NumberOfChangedTrees"; 53 53 private const string ExecuteInParallelParameterName = "ExecuteInParallel"; 54 54 private const string MaxDegreeOfParalellismParameterName = "MaxDegreeOfParallelism"; 55 private const string ExclusiveMatchingParameterName = "ExclusiveMatching"; 55 56 #endregion 56 57 57 58 #region parameters 59 public ILookupParameter<BoolValue> ExclusiveMatchingParameter { 60 get { return (ILookupParameter<BoolValue>)Parameters[ExclusiveMatchingParameterName]; } 61 } 58 62 public ILookupParameter<BoolValue> ExecuteInParallelParameter { 59 63 get { return (ILookupParameter<BoolValue>)Parameters[ExecuteInParallelParameterName]; } … … 101 105 get { return (ILookupParameter<PercentValue>)Parameters[MinimumPhenotypicSimilarityParameterName]; } 102 106 } 103 public LookupParameter<IntValue> ChangedTreesParameter {104 get { return (LookupParameter<IntValue>)Parameters[ ChangedTreesParameterName]; }107 public LookupParameter<IntValue> NumberOfChangedTreesParameter { 108 get { return (LookupParameter<IntValue>)Parameters[NumberOfChangedTreesParameterName]; } 105 109 } 106 110 #endregion … … 111 115 public PercentValue MinimumPhenotypicSimilarity { get { return MinimumPhenotypicSimilarityParameter.ActualValue; } } 112 116 public BoolValue RandomReplacement { get { return RandomReplacementParameter.ActualValue; } } 117 public IntValue NumberOfChangedTrees { get { return NumberOfChangedTreesParameter.ActualValue; } } 113 118 #endregion 114 119 … … 122 127 }; 123 128 129 public ISymbolicExpressionTree Schema { get; set; } 130 124 131 [Storable] 125 132 private readonly UpdateEstimatedValuesOperator updateEstimatedValuesOperator; … … 128 135 qm = new QueryMatch(comp) { MatchParents = true }; 129 136 this.updateEstimatedValuesOperator = new UpdateEstimatedValuesOperator(); 130 137 #region add parameters 131 138 Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(SchemaParameterName, "The current schema to be evaluated")); 132 139 Parameters.Add(new LookupParameter<PercentValue>(MinimumSchemaFrequencyParameterName)); … … 142 149 Parameters.Add(new LookupParameter<ISymbolicExpressionTreeManipulator>(MutatorParameterName)); 143 150 Parameters.Add(new LookupParameter<BoolValue>(RandomReplacementParameterName)); 144 Parameters.Add(new LookupParameter<IntValue>( ChangedTreesParameterName));151 Parameters.Add(new LookupParameter<IntValue>(NumberOfChangedTreesParameterName)); 145 152 Parameters.Add(new LookupParameter<BoolValue>(ExecuteInParallelParameterName)); 146 153 Parameters.Add(new LookupParameter<IntValue>(MaxDegreeOfParalellismParameterName)); 154 Parameters.Add(new LookupParameter<BoolValue>(ExclusiveMatchingParameterName)); 155 #endregion 147 156 } 148 157 … … 170 179 var mutator = MutatorParameter.ActualValue; 171 180 172 var s = Schema Parameter.ActualValue;181 var s = Schema; 173 182 var sRoot = s.Root.GetSubtree(0).GetSubtree(0); 174 183 int countThreshold = (int)Math.Max(2, Math.Round(MinimumSchemaFrequency.Value * individuals.Count)); 175 184 176 185 // first apply the length and root equality checks in order to filter the individuals 177 var filtered = (from ind in individuals 178 let t = (ISymbolicExpressionTree)ind.Variables["SymbolicExpressionTree"].Value 179 where t.Length >= s.Length && qm.Comparer.Equals(t.Root.GetSubtree(0).GetSubtree(0), sRoot) 180 select ind).ToList(); 186 var exclusiveMatching = ExclusiveMatchingParameter.ActualValue.Value; 187 var filtered = exclusiveMatching ? (from ind in individuals 188 where !ind.Variables.ContainsKey("AlreadyMatched") 189 let t = (ISymbolicExpressionTree)ind.Variables["SymbolicExpressionTree"].Value 190 where t.Length >= s.Length && qm.Comparer.Equals(t.Root.GetSubtree(0).GetSubtree(0), sRoot) 191 select ind).ToList() 192 : (from ind in individuals 193 let t = (ISymbolicExpressionTree)ind.Variables["SymbolicExpressionTree"].Value 194 where t.Length >= s.Length && qm.Comparer.Equals(t.Root.GetSubtree(0).GetSubtree(0), sRoot) 195 select ind).ToList(); 181 196 182 197 // if we don't have enough filtered individuals, then we are done 183 198 if (filtered.Count < countThreshold) { 184 ChangedTreesParameter.ActualValue = new IntValue(0);185 199 return base.Apply(); 186 200 } … … 210 224 } else { 211 225 for (int i = 0; i < filtered.Count; ++i) { 212 213 226 // break early if it becomes impossible to reach the minimum threshold 214 227 if (matchingIndividuals.Count + filtered.Count - i < countThreshold) … … 223 236 } 224 237 238 // additional condition: the average schema quality should be equal or greater than the population average quality 225 239 if (matchingIndividuals.Count < countThreshold) { 226 ChangedTreesParameter.ActualValue = new IntValue(0);227 240 return base.Apply(); 228 241 } … … 230 243 var similarity = CalculatePhenotypicSimilarity(matchingIndividuals, calculator, executeInParallel, maxDegreeOfParallelism); 231 244 if (similarity < MinimumPhenotypicSimilarity.Value) { 232 ChangedTreesParameter.ActualValue = new IntValue(0);233 245 return base.Apply(); 234 246 } … … 244 256 mutationOc.Add(mutatorOp); 245 257 updateEstimatedValues.Add(updateOp); 246 } 247 ChangedTreesParameter.ActualValue = new IntValue(individualsToReplace.Count); 258 if (exclusiveMatching) 259 ind.Variables.Add(new Core.Variable("AlreadyMatched")); 260 } 261 262 NumberOfChangedTrees.Value += individualsToReplace.Count; // a lock is not necessary here because the SchemaEvaluators cannot be executed in parallel 263 248 264 return new OperationCollection(mutationOc, updateEstimatedValues, base.Apply()); 249 265 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SchemaDiversification/UpdateEstimatedValuesOperator.cs
r12979 r12988 38 38 private const string EstimationLimitsParameterName = "EstimationLimits"; 39 39 private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree"; 40 private const string ScaleEstimatedValuesParameterName = "ScaleEstimatedValues"; 40 41 41 42 public ILookupParameter<IRegressionProblemData> ProblemDataParameter { … … 51 52 get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; } 52 53 } 53 54 public ILookupParameter<BoolValue> ScaleEstimatedValuesParameter { 55 get { return (ILookupParameter<BoolValue>)Parameters[ScaleEstimatedValuesParameterName]; } 56 } 54 57 55 58 public UpdateEstimatedValuesOperator() { … … 58 61 Parameters.Add(new LookupParameter<DoubleLimit>(EstimationLimitsParameterName)); 59 62 Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName)); 63 Parameters.Add(new LookupParameter<BoolValue>(ScaleEstimatedValuesParameterName)); 60 64 } 61 65 … … 100 104 OnlineCalculatorError error; 101 105 var r = OnlinePearsonsRCalculator.Calculate(targetValues, scaled, out error); 102 if (error != OnlineCalculatorError.None) r = 0;106 if (error != OnlineCalculatorError.None) r = double.NaN; 103 107 104 108 var r2 = r * r; 105 if (r2 > 1.0) r2 = 1.0;106 109 107 110 var variables = ExecutionContext.Scope.Variables; 108 111 ((DoubleValue)variables["Quality"].Value).Value = r2; 112 113 var scaleEstimatedValues = ScaleEstimatedValuesParameter.ActualValue; 114 if (!scaleEstimatedValues.Value) 115 scaled = estimatedValues.LimitToRange(estimationLimits.Lower, estimationLimits.Upper).ToArray(); 109 116 110 117 if (variables.ContainsKey("EstimatedValues")) {
Note: See TracChangeset
for help on using the changeset viewer.