Changeset 11482 for branches/HeuristicLab.EvolutionTracking
- Timestamp:
- 10/21/14 01:31:20 (10 years ago)
- Location:
- branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4
- Files:
-
- 4 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisBottomUpDiversityAnalyzer.cs
r11291 r11482 22 22 using HeuristicLab.Analysis; 23 23 using HeuristicLab.Core; 24 using HeuristicLab.Data; 25 using HeuristicLab.Parameters; 24 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 25 27 … … 28 30 [StorableClass] 29 31 public class SymbolicDataAnalysisBottomUpDiversityAnalyzer : SingleObjectivePopulationDiversityAnalyzer { 32 private const string MatchConstantValuesParameterName = "MatchConstantValues"; 33 private const string MatchVariableWeightsParameterName = "MatchVariableWeights"; 34 35 public IValueParameter<BoolValue> MatchVariableWeightsParameter { 36 get { return (IValueParameter<BoolValue>)Parameters[MatchVariableWeightsParameterName]; } 37 } 38 39 public IValueParameter<BoolValue> MatchConstantValuesParameter { 40 get { return (IValueParameter<BoolValue>)Parameters[MatchConstantValuesParameterName]; } 41 } 42 43 public bool MatchConstantValues { 44 get { return MatchConstantValuesParameter.Value.Value; } 45 set { 46 MatchConstantValuesParameter.Value.Value = value; 47 ((BottomUpSimilarityCalculator)SimilarityCalculator).MatchConstantValues = value; 48 } 49 } 50 51 public bool MatchVariableWeights { 52 get { return MatchVariableWeightsParameter.Value.Value; } 53 set { 54 MatchVariableWeightsParameter.Value.Value = value; 55 ((BottomUpSimilarityCalculator)SimilarityCalculator).MatchVariableWeights = value; 56 } 57 } 58 30 59 [StorableConstructor] 31 60 protected SymbolicDataAnalysisBottomUpDiversityAnalyzer(bool deserializing) : base(deserializing) { } 32 61 62 [StorableHook(HookType.AfterDeserialization)] 63 private void AfterDeserialization() { 64 if (!Parameters.ContainsKey(MatchConstantValuesParameterName)) 65 Parameters.Add(new ValueParameter<BoolValue>(MatchConstantValuesParameterName, "Specifies if the similarity calculator should match constant values.", new BoolValue(true))); 66 if (!Parameters.ContainsKey(MatchVariableWeightsParameterName)) 67 Parameters.Add(new ValueParameter<BoolValue>(MatchVariableWeightsParameterName, "Specifies if the similarity calculator should match variable weights", new BoolValue(true))); 68 } 69 33 70 public SymbolicDataAnalysisBottomUpDiversityAnalyzer() { 34 71 SimilarityCalculator = new BottomUpSimilarityCalculator { SolutionVariableName = "SymbolicExpressionTree" }; 72 Parameters.Add(new ValueParameter<BoolValue>(MatchConstantValuesParameterName, "Specifies if the similarity calculator should match constant values.", new BoolValue(true))); 73 Parameters.Add(new ValueParameter<BoolValue>(MatchVariableWeightsParameterName, "Specifies if the similarity calculator should match variable weights", new BoolValue(true))); 35 74 } 36 75 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisMaxCommonSubtreeDiversityAnalyzer.cs
r11473 r11482 25 25 26 26 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Analyzers { 27 [Item("SymbolicDataAnalysis BottomUpDiversityAnalyzer", "A diversity analyzer based on the bottom-upsimilarity between trees.")]27 [Item("SymbolicDataAnalysisMaxCommonSubtreeDiversityAnalyzer", "A diversity analyzer based on the max common subtree similarity between trees.")] 28 28 [StorableClass] 29 public class SymbolicDataAnalysis BottomUpDiversityAnalyzer : SingleObjectivePopulationDiversityAnalyzer {29 public class SymbolicDataAnalysisMaxCommonSubtreeDiversityAnalyzer : SingleObjectivePopulationDiversityAnalyzer { 30 30 [StorableConstructor] 31 protected SymbolicDataAnalysis BottomUpDiversityAnalyzer(bool deserializing) : base(deserializing) { }31 protected SymbolicDataAnalysisMaxCommonSubtreeDiversityAnalyzer(bool deserializing) : base(deserializing) { } 32 32 33 public SymbolicDataAnalysis BottomUpDiversityAnalyzer() {34 SimilarityCalculator = new BottomUpSimilarityCalculator { SolutionVariableName = "SymbolicExpressionTree" };33 public SymbolicDataAnalysisMaxCommonSubtreeDiversityAnalyzer() { 34 SimilarityCalculator = new MaxCommonSubtreeSimilarityCalculator { SolutionVariableName = "SymbolicExpressionTree" }; 35 35 } 36 36 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj
r11458 r11482 174 174 </ItemGroup> 175 175 <ItemGroup> 176 <Compile Include="Analyzers\BuildingBlockAnalyzers\SymbolicDataAnalysisPoly10Analyzer.cs" /> 177 <Compile Include="Analyzers\SymbolicDataAnalysisMaxCommonSubtreeDiversityAnalyzer.cs" /> 176 178 <Compile Include="Analyzers\SymbolicDataAnalysisBottomUpDiversityAnalyzer.cs" /> 177 179 <Compile Include="Analyzers\SymbolicDataAnalysisPhenotypicDiversityAnalyzer.cs" /> … … 191 193 <SubType>Code</SubType> 192 194 </Compile> 193 <Compile Include=" Crossovers\SymbolicDataAnalysisExpressionDiversityPreservingCrossover.cs" />195 <Compile Include="Analyzers\SymbolicDataAnalysisUsefulGenesAnalyzer.cs" /> 194 196 <Compile Include="Importer\SymbolicExpressionImporter.cs" /> 195 197 <Compile Include="Importer\Token.cs" /> -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators/BottomUpSimilarityCalculator.cs
r11458 r11482 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Diagnostics; 24 25 using System.Linq; 25 26 using HeuristicLab.Common; … … 34 35 public class BottomUpSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator, ISymbolicDataAnalysisExpressionSimilarityCalculator { 35 36 private readonly HashSet<string> commutativeSymbols = new HashSet<string> { "Addition", "Multiplication", "Average", "And", "Or", "Xor" }; 37 public bool MatchVariableWeights { get; set; } 38 public bool MatchConstantValues { get; set; } 36 39 37 40 public BottomUpSimilarityCalculator() { } 41 42 protected BottomUpSimilarityCalculator(BottomUpSimilarityCalculator original, Cloner cloner) 43 : base(original, cloner) { 44 } 38 45 39 46 public override IDeepCloneable Clone(Cloner cloner) { … … 47 54 var map = ComputeBottomUpMapping(t1.Root, t2.Root); 48 55 return 2.0 * map.Count / (t1.Length + t2.Length); 49 }50 51 protected BottomUpSimilarityCalculator(BottomUpSimilarityCalculator original, Cloner cloner)52 : base(original, cloner) {53 56 } 54 57 … … 96 99 var t = eW.Current; 97 100 98 if (reverseMap.ContainsKey(t)) { 99 throw new Exception("A mapping to this node already exists."); 100 } 101 Debug.Assert(!reverseMap.ContainsKey(t)); 101 102 102 103 forwardMap[s] = t; … … 125 126 foreach (var n in nodes) { 126 127 if (n.SubtreeCount == 0) { 127 var label = n.ToString();128 var label = Label(n); 128 129 if (!labelMap.ContainsKey(label)) { 129 130 var z = new GraphNode { SymbolicExpressionTreeNode = n, Label = label }; … … 204 205 } 205 206 207 private string Label(ISymbolicExpressionTreeNode node) { 208 var constant = node as ConstantTreeNode; 209 if (constant != null && !MatchConstantValues) 210 return constant.Symbol.Name; 211 var variable = node as VariableTreeNode; 212 if (variable != null && !MatchVariableWeights) { 213 return variable.VariableName; 214 } 215 return node.ToString(); 216 } 217 206 218 private class GraphNode { 207 219 public ISymbolicExpressionTreeNode SymbolicExpressionTreeNode; -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators/MaxCommonSubtreeSimilarityCalculator.cs
r11458 r11482 31 31 [Item("MaxCommonSubtreeSimilarityCalculator", "A similarity calculator based on the size of the maximum common subtree between two trees")] 32 32 public class MaxCommonSubtreeSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator, ISymbolicDataAnalysisExpressionSimilarityCalculator { 33 [Storable] 33 34 private readonly SymbolicExpressionTreeNodeSimilarityComparer comparer; 34 35 public bool MatchVariableNames { … … 88 89 } 89 90 90 public static double MaxCommonSubtreeSimilarity(ISymbolicExpressionTree a, ISymbolicExpressionTree b, SymbolicExpressionTreeNodeSimilarityComparer comparer) { 91 public static double MaxCommonSubtreeSimilarity(ISymbolicExpressionTree a, ISymbolicExpressionTree b, ISymbolicExpressionTreeNodeSimilarityComparer comparer) { 92 int m = SymbolicExpressionTreeMatching.Match(a.Root, b.Root, comparer); 93 return 2.0 * m / (a.Length + b.Length); 94 } 95 96 public static double MaxCommonSubtreeSimilarityRestricted(ISymbolicExpressionTree a, ISymbolicExpressionTree b, SymbolicExpressionTreeNodeSimilarityComparer comparer) { 91 97 int max = 0; 92 98 var rootA = a.Root.GetSubtree(0).GetSubtree(0); … … 99 105 if (lenB <= max) continue; 100 106 int matches = SymbolicExpressionTreeMatching.Match(aa, bb, comparer); 107 // if (max < matches) 101 108 if (matches == lenB && max < matches) 102 109 max = matches;
Note: See TracChangeset
for help on using the changeset viewer.