Changeset 13565 for branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SchemaDiversification
- Timestamp:
- 01/24/16 21:53:06 (9 years ago)
- Location:
- branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SchemaDiversification
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SchemaDiversification/SchemaCreator.cs
r13527 r13565 189 189 } 190 190 191 Func<double, double> rule;192 191 var replacementRule = ReplacementRatioUpdateRuleParameter.Value.Value; 193 194 switch (replacementRule) {195 case "f(x) = x": {196 rule = x => x;197 break;198 }199 case "f(x) = tanh(x)": {200 rule = x => Math.Tanh(x);201 break;202 }203 case "f(x) = tanh(2x)": {204 rule = x => Math.Tanh(2 * x);205 break;206 }207 case "f(x) = tanh(3x)": {208 rule = x => Math.Tanh(3 * x);209 break;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 }219 default:220 throw new ArgumentException("Unknown replacement rule");221 }222 192 223 193 var evaluateSchemas = new OperationCollection(); … … 235 205 #region create schemas and add subscopes representing the individuals 236 206 foreach (var schema in schemas) { 237 evaluateSchemas.Add(ExecutionContext.CreateChildOperation(new SchemaEvaluator { Schema = schema, ReplacementRule = r ule }, ExecutionContext.Scope));207 evaluateSchemas.Add(ExecutionContext.CreateChildOperation(new SchemaEvaluator { Schema = schema, ReplacementRule = replacementRule }, ExecutionContext.Scope)); 238 208 } 239 209 #endregion -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SchemaDiversification/SchemaEvaluator.cs
r13527 r13565 132 132 #endregion 133 133 134 private readonly SymbolicExpressionTreePhenotypicSimilarityCalculator calculator = new SymbolicExpressionTreePhenotypicSimilarityCalculator();135 private readonly QueryMatch qm; 136 137 p ublic Func<double, double> ReplacementRule { get; set; }138 139 private readonly ISymbolicExpressionTreeNodeEqualityComparer comp = new SymbolicExpressionTreeNodeEqualityComparer {140 MatchConstantValues = false,141 MatchVariableWeights = false, 142 MatchVariableNames = true143 };134 private QueryMatch qm; 135 136 [Storable] 137 private SymbolicExpressionTreePhenotypicSimilarityCalculator calculator; 138 139 [Storable] 140 public string ReplacementRule { get; set; } 141 142 [Storable] 143 private ISymbolicExpressionTreeNodeEqualityComparer comparer; 144 144 145 145 [Storable] … … 153 153 if (!Parameters.ContainsKey(StrictSchemaMatchingParameterName)) 154 154 Parameters.Add(new LookupParameter<BoolValue>(StrictSchemaMatchingParameterName)); 155 156 if (calculator == null) 157 calculator = new SymbolicExpressionTreePhenotypicSimilarityCalculator(); 158 159 if (comparer == null) 160 comparer = new SymbolicExpressionTreeNodeEqualityComparer { MatchVariableNames = true, MatchVariableWeights = true, MatchConstantValues = false }; 161 162 qm = new QueryMatch(comparer) { MatchParents = true }; 155 163 } 156 164 157 165 public SchemaEvaluator() { 158 qm = new QueryMatch(comp) { MatchParents = true }; 159 this.updateQualityOperator = new UpdateQualityOperator(); 166 calculator = new SymbolicExpressionTreePhenotypicSimilarityCalculator(); 167 comparer = new SymbolicExpressionTreeNodeEqualityComparer { MatchVariableNames = true, MatchVariableWeights = true, MatchConstantValues = false }; 168 qm = new QueryMatch(comparer) { MatchParents = true }; 169 updateQualityOperator = new UpdateQualityOperator(); 160 170 #region add parameters 161 171 Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(SchemaParameterName, "The current schema to be evaluated")); … … 186 196 187 197 protected SchemaEvaluator(SchemaEvaluator original, Cloner cloner) : base(original, cloner) { 188 this.comp = new SymbolicExpressionTreeNodeEqualityComparer(); 189 this.qm = new QueryMatch(comp) { MatchParents = original.qm?.MatchParents ?? true }; 190 this.updateQualityOperator = new UpdateQualityOperator(); 198 calculator = cloner.Clone(original.calculator); 199 comparer = cloner.Clone(original.comparer); 200 qm = new QueryMatch(comparer) { MatchParents = true }; 201 updateQualityOperator = new UpdateQualityOperator(); 191 202 Schema = original.Schema; 192 203 } … … 199 210 var strictSchemaMatching = StrictSchemaMatchingParameter.ActualValue.Value; 200 211 if (strictSchemaMatching) { 201 comp .MatchVariableWeights = true;202 comp .MatchConstantValues = true;212 comparer.MatchVariableWeights = true; 213 comparer.MatchConstantValues = true; 203 214 } else { 204 comp .MatchVariableWeights = false;205 comp .MatchConstantValues = false;215 comparer.MatchVariableWeights = false; 216 comparer.MatchConstantValues = false; 206 217 } 207 218 … … 281 292 if (adaptiveReplacementRatio) { 282 293 var r = (double)matchingIndividuals.Count / individuals.Count; 283 replacementRatio = ReplacementRule(r);294 replacementRatio = CalculateReplacementRatio(r); 284 295 } else { 285 296 replacementRatio = ReplacementRatio.Value; … … 305 316 } 306 317 318 private double CalculateReplacementRatio(double r) { 319 switch (ReplacementRule) { 320 case "f(x) = x": { 321 return r; 322 } 323 case "f(x) = tanh(x)": { 324 return Math.Tanh(r); 325 } 326 case "f(x) = tanh(2x)": { 327 return Math.Tanh(2 * r); 328 } 329 case "f(x) = tanh(3x)": { 330 return Math.Tanh(3 * r); 331 } 332 case "f(x) = tanh(4x)": { 333 return Math.Tanh(4 * r); 334 } 335 case "f(x) = 1-sqrt(1-x)": { 336 return 1 - Math.Sqrt(1 - r); 337 } 338 default: 339 throw new ArgumentException("Unknown replacement rule"); 340 } 341 } 342 307 343 public static double CalculateSimilarity(ScopeList individuals, ISolutionSimilarityCalculator calculator, bool parallel = false, int nThreads = -1) { 308 344 double similarity = 0;
Note: See TracChangeset
for help on using the changeset viewer.