Changeset 13496 for branches/HeuristicLab.EvolutionTracking
- Timestamp:
- 01/11/16 21:29:25 (9 years ago)
- Location:
- branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SchemaDiversification
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SchemaDiversification/DiversificationStatisticsOperator.cs
r13480 r13496 38 38 private const string ResultCollectionParameterName = "Results"; 39 39 private const string EvaluatedSolutionsParameterName = "EvaluatedSolutions"; 40 41 private readonly object locker = new object(); 40 42 41 43 public ILookupParameter<IntValue> NumberOfChangedTreesParameter { … … 83 85 table = new DataTable(); 84 86 results.Add(new Result("NumberOfChangedTrees", table)); 85 var row = new DataRow("Changed trees") ;87 var row = new DataRow("Changed trees") { VisualProperties = { StartIndexZero = true } }; 86 88 table.Rows.Add(row); 87 89 } … … 89 91 table = new DataTable(); 90 92 results.Add(new Result("AverageSchemaLength", table)); 91 var row = new DataRow("Average schema length") ;93 var row = new DataRow("Average schema length") { VisualProperties = { StartIndexZero = true } }; 92 94 table.Rows.Add(row); 93 95 } … … 95 97 table = new DataTable(); 96 98 results.Add(new Result("NumberOfSchemas", table)); 97 var row = new DataRow("Number of schemas") ;99 var row = new DataRow("Number of schemas") { VisualProperties = { StartIndexZero = true } }; 98 100 table.Rows.Add(row); 99 101 } … … 101 103 table = new DataTable(); 102 104 results.Add(new Result("EvaluatedSolutionsPerGeneration", table)); 103 var row = new DataRow("Evaluated solutions") ;105 var row = new DataRow("Evaluated solutions") { VisualProperties = { StartIndexZero = true } }; 104 106 table.Rows.Add(row); 105 107 row.Values.Add(0); 106 108 } 107 109 108 var evaluatedSolutions = EvaluatedSolutionsParameter.ActualValue.Value - evaluatedSolutionsTracker; 110 lock (locker) { 111 // count the extra evaluations performed after diversification 112 EvaluatedSolutionsParameter.ActualValue.Value += NumberOfChangedTreesParameter.ActualValue.Value; 113 } 114 115 var evaluatedSolutions = EvaluatedSolutionsParameter.ActualValue.Value; 116 if (evaluatedSolutions > 0) 117 evaluatedSolutions -= evaluatedSolutionsTracker; 109 118 ((DataTable)results["NumberOfChangedTrees"].Value).Rows["Changed trees"].Values.Add(NumberOfChangedTreesParameter.ActualValue.Value); 110 119 ((DataTable)results["AverageSchemaLength"].Value).Rows["Average schema length"].Values.Add(AverageSchemaLengthParameter.ActualValue.Value); -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SchemaDiversification/SchemaCreator.cs
r13480 r13496 51 51 private const string UseAdaptiveReplacementRatioParameterName = "UseAdaptiveReplacementRatio"; 52 52 private const string ReplacementRatioUpdateRuleParameterName = "ReplacementRatioUpdateRule"; 53 private const string StrictSchemaMatchingParameterName = "StrictSchemaMatching"; 53 54 #endregion 54 55 … … 60 61 public IFixedValueParameter<BoolValue> UseAdaptiveReplacementRatioParameter { 61 62 get { return (IFixedValueParameter<BoolValue>)Parameters[UseAdaptiveReplacementRatioParameterName]; } 63 } 64 public IFixedValueParameter<BoolValue> StrictSchemaMatchingParameter { 65 get { return (IFixedValueParameter<BoolValue>)Parameters[StrictSchemaMatchingParameterName]; } 62 66 } 63 67 public IFixedValueParameter<BoolValue> ExclusiveMatchingParameter { … … 104 108 public bool ExecuteInParallel { get { return ExecuteInParallelParameter.Value.Value; } } 105 109 public double PercentageOfPopulation { get { return PercentageOfPopulationParameter.Value.Value; } } 110 public bool StrictSchemaMatching { get { return StrictSchemaMatchingParameter.Value.Value; } } 106 111 #endregion 107 112 108 113 private UpdateEstimatedValuesOperator updateEstimatedValuesOperator; 109 114 private DiversificationStatisticsOperator diversificationStatisticsOperator; 115 116 public override void ClearState() { 117 NumberOfChangedTreesParameter.Value.Value = 0; 118 NumberOfChangedTreesParameter.Value.Value = 0; 119 AverageSchemaLengthParameter.Value.Value = 0; 120 base.ClearState(); 121 } 110 122 111 123 public SchemaCreator() { … … 121 133 Parameters.Add(new FixedValueParameter<BoolValue>(ScaleEstimatedValuesParameterName, new BoolValue(true))); 122 134 Parameters.Add(new FixedValueParameter<BoolValue>(ExclusiveMatchingParameterName, new BoolValue(false))); 135 Parameters.Add(new FixedValueParameter<BoolValue>(StrictSchemaMatchingParameterName, new BoolValue(false))); 123 136 Parameters.Add(new ValueParameter<IntValue>(NumberOfChangedTreesParameterName, new IntValue(0))); 124 137 Parameters.Add(new ValueParameter<IntValue>(NumberOfSchemasParameterName, new IntValue(0))); … … 126 139 Parameters.Add(new FixedValueParameter<BoolValue>(UseAdaptiveReplacementRatioParameterName, new BoolValue(true))); 127 140 128 var replacementRatioUpdateRules = new ItemSet<StringValue>(new[] { new StringValue("f(x) = x"), new StringValue("f(x) = tanh(x)"), new StringValue("f(x) = tanh(2x)"), new StringValue("f(x) = tanh(3x)") }); 141 var replacementRatioUpdateRules = new ItemSet<StringValue>(new[] { 142 new StringValue("f(x) = x"), 143 new StringValue("f(x) = tanh(x)"), 144 new StringValue("f(x) = tanh(2x)"), 145 new StringValue("f(x) = tanh(3x)"), 146 new StringValue("f(x) = tanh(4x)"), 147 new StringValue("f(x) = 1-sqrt(1-x)") 148 }); 129 149 Parameters.Add(new ConstrainedValueParameter<StringValue>(ReplacementRatioUpdateRuleParameterName, replacementRatioUpdateRules)); 130 150 #endregion … … 146 166 protected SchemaCreator(bool deserializing) : base(deserializing) { } 147 167 168 169 [StorableHook(HookType.AfterDeserialization)] 170 private void AfterDeserialization() { 171 if (!Parameters.ContainsKey(StrictSchemaMatchingParameterName)) 172 Parameters.Add(new FixedValueParameter<BoolValue>(StrictSchemaMatchingParameterName, new BoolValue(false))); 173 } 174 148 175 public override IOperation Apply() { 149 176 // apply only when at least one generation has passed … … 153 180 154 181 var n = (int)Math.Round(ExecutionContext.Scope.SubScopes.Count * PercentageOfPopulation); 155 var scopes = new ScopeList(ExecutionContext.Scope.SubScopes.Take(n));156 182 157 183 var updateEstimatedValues = new OperationCollection { Parallel = true }; … … 159 185 updateEstimatedValuesOperator = new UpdateEstimatedValuesOperator(); 160 186 161 foreach (var s in scopes) { 162 if (!s.Variables.ContainsKey("EstimatedValues")) 163 s.Variables.Add(new Core.Variable("EstimatedValues")); 187 foreach (var s in ExecutionContext.Scope.SubScopes.Where(s => !s.Variables.ContainsKey("EstimatedValues"))) { 164 188 updateEstimatedValues.Add(ExecutionContext.CreateChildOperation(updateEstimatedValuesOperator, s)); 165 189 } … … 185 209 break; 186 210 } 211 case "f(x) = tanh(4x)": { 212 rule = x => Math.Tanh(4 * x); 213 break; 214 } 215 case "f(x) = 1-sqrt(1-x)": { 216 rule = x => 1 - Math.Sqrt(1 - x); 217 break; 218 } 187 219 default: 188 220 throw new ArgumentException("Unknown replacement rule"); … … 192 224 193 225 // for now, only consider crossover offspring 226 var scopes = new ScopeList(ExecutionContext.Scope.SubScopes.OrderByDescending(x => ((DoubleValue)x.Variables["Quality"].Value).Value).Take(n)); 194 227 var vertices = from s in scopes 195 228 let t = (ISymbolicExpressionTree)s.Variables["SymbolicExpressionTree"].Value … … 222 255 public static IEnumerable<ISymbolicExpressionTree> GenerateSchemas(IEnumerable<IGenealogyGraphNode<ISymbolicExpressionTree>> vertices, int minimumSchemaLength) { 223 256 var anySubtreeSymbol = new AnySubtreeSymbol(); 224 // var anyNodeSymbol = new AnyNodeSymbol();257 // var anyNodeSymbol = new AnyNodeSymbol(); 225 258 var groups = vertices.GroupBy(x => x.Parents.First()).OrderByDescending(g => g.Count()).ToList(); 226 259 var hash = new HashSet<string>(); … … 246 279 continue; 247 280 248 //var replacement = anySubtreeSymbol.CreateTreeNode();249 //ReplaceSubtree(node, replacement, false);250 var replacement = new AnyNodeSymbol(node.Symbol.MinimumArity, node.Symbol.MinimumArity).CreateTreeNode();251 ReplaceSubtree(node, replacement, true);281 var replacement = anySubtreeSymbol.CreateTreeNode(); 282 ReplaceSubtree(node, replacement, false); 283 // var replacement = new AnyNodeSymbol(node.Symbol.MinimumArity, node.Symbol.MinimumArity).CreateTreeNode(); 284 // ReplaceSubtree(node, replacement, true); 252 285 replaced = true; 253 286 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SchemaDiversification/SchemaEvaluator.cs
r13480 r13496 58 58 private const string ExclusiveMatchingParameterName = "ExclusiveMatching"; 59 59 private const string UseAdaptiveReplacementRatioParameterName = "UseAdaptiveReplacementRatio"; 60 private const string StrictSchemaMatchingParameterName = "StrictSchemaMatching"; 60 61 #endregion 61 62 … … 117 118 public LookupParameter<IntValue> NumberOfChangedTreesParameter { 118 119 get { return (LookupParameter<IntValue>)Parameters[NumberOfChangedTreesParameterName]; } 120 } 121 public LookupParameter<BoolValue> StrictSchemaMatchingParameter { 122 get { return (LookupParameter<BoolValue>)Parameters[StrictSchemaMatchingParameterName]; } 119 123 } 120 124 #endregion … … 143 147 [Storable] 144 148 private readonly UpdateEstimatedValuesOperator updateEstimatedValuesOperator; 149 150 [StorableHook(HookType.AfterDeserialization)] 151 private void AfterDeserialization() { 152 if (!Parameters.ContainsKey(StrictSchemaMatchingParameterName)) 153 Parameters.Add(new LookupParameter<BoolValue>(StrictSchemaMatchingParameterName)); 154 } 145 155 146 156 public SchemaEvaluator() { … … 159 169 Parameters.Add(new LookupParameter<DoubleLimit>(EstimationLimitsParameterName)); 160 170 Parameters.Add(new LookupParameter<BoolValue>(ApplyLinearScalingParameterName)); 171 Parameters.Add(new LookupParameter<BoolValue>(StrictSchemaMatchingParameterName)); 161 172 Parameters.Add(new LookupParameter<ISymbolicExpressionTreeManipulator>(MutatorParameterName)); 162 173 Parameters.Add(new LookupParameter<ISymbolicExpressionTreeCrossover>(CrossoverParameterName)); … … 188 199 189 200 public override IOperation Apply() { 201 var strictSchemaMatching = StrictSchemaMatchingParameter.ActualValue.Value; 202 if (strictSchemaMatching) { 203 comp.MatchVariableWeights = true; 204 comp.MatchConstantValues = true; 205 } else { 206 comp.MatchVariableWeights = false; 207 comp.MatchConstantValues = false; 208 } 209 190 210 var individuals = ExecutionContext.Scope.SubScopes; // the scopes represent the individuals 191 211 var trees = individuals.Select(x => (ISymbolicExpressionTree)x.Variables["SymbolicExpressionTree"].Value).ToList(); 192 var qualities = individuals.Select(x => (DoubleValue)x.Variables["Quality"].Value).ToList();193 212 194 213 var random = RandomParameter.ActualValue; -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SchemaDiversification/UpdateEstimatedValuesOperator.cs
r12988 r13496 100 100 beta = 1.0; 101 101 } 102 103 102 var scaled = estimatedValues.Select(x => x * beta + alpha).LimitToRange(estimationLimits.Lower, estimationLimits.Upper).ToArray(); 104 103 OnlineCalculatorError error; … … 109 108 110 109 var variables = ExecutionContext.Scope.Variables; 110 111 111 ((DoubleValue)variables["Quality"].Value).Value = r2; 112 112
Note: See TracChangeset
for help on using the changeset viewer.