- Timestamp:
- 07/17/19 22:02:08 (5 years ago)
- Location:
- stable
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
-
stable/HeuristicLab.Problems.DataAnalysis.Symbolic
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Problems.DataAnalysis.Symbolic merged: 17076
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionDiversityPreservingCrossover.cs
r17099 r17141 42 42 private const string StrictHashingParameterName = "StrictHashing"; 43 43 44 private static readonly Func<byte[], ulong> hashFunction = HashUtil. JSHash;44 private static readonly Func<byte[], ulong> hashFunction = HashUtil.DJBHash; 45 45 46 46 #region Parameter Properties … … 88 88 } 89 89 90 public SymbolicDataAnalysisExpressionDiversityPreservingCrossover() { 91 name = "DiversityCrossover"; 90 public SymbolicDataAnalysisExpressionDiversityPreservingCrossover() : base() { 92 91 Parameters.Add(new ValueLookupParameter<PercentValue>(InternalCrossoverPointProbabilityParameterName, "The probability to select an internal crossover point (instead of a leaf node).", new PercentValue(0.9))); 93 92 Parameters.Add(new ValueLookupParameter<BoolValue>(WindowingParameterName, "Use proportional sampling with windowing for cutpoint selection.", new BoolValue(false))); … … 96 95 } 97 96 98 private SymbolicDataAnalysisExpressionDiversityPreservingCrossover(SymbolicDataAnalysisExpressionDiversityPreservingCrossover<T> original, Cloner cloner) : base(original, cloner) { 99 } 97 private SymbolicDataAnalysisExpressionDiversityPreservingCrossover(SymbolicDataAnalysisExpressionDiversityPreservingCrossover<T> original, Cloner cloner) : base(original, cloner) { } 100 98 101 99 public override IDeepCloneable Clone(Cloner cloner) { -
stable/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Hashing/HashExtensions.cs
r17099 r17141 25 25 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 26 26 public static class SymbolicExpressionHashExtensions { 27 /// <summary> 28 /// Holds data that is necessary to handle tree nodes in hashing / simplification. 29 /// </summary> 30 /// <typeparam name="T">The tree node type</typeparam> 27 31 public sealed class HashNode<T> : IComparable<HashNode<T>>, IEquatable<HashNode<T>> where T : class { 28 32 public T Data; … … 38 42 public SimplifyAction Simplify; 39 43 40 //public IComparer<T> Comparer;41 42 44 public bool IsLeaf => Arity == 0; 43 44 //public HashNode(IComparer<T> comparer) {45 // Comparer = comparer;46 //}47 48 //public HashNode() { }49 45 50 46 public int CompareTo(HashNode<T> other) { … … 170 166 171 167 /// <summary> 172 /// Get a function node's child indices t168 /// Get a function node's child indices 173 169 /// </summary> 174 170 /// <typeparam name="T">The data type encapsulated by a hash node</typeparam> 175 /// <param name="nodes">An array of hash nodes with up-to-date node sizes </param>171 /// <param name="nodes">An array of hash nodes with up-to-date node sizes (see UpdateNodeSizes)</param> 176 172 /// <param name="i">The index in the array of hash nodes of the node whose children we want to iterate</param> 177 173 /// <returns>An array containing child indices</returns> … … 188 184 } 189 185 186 /// <summary> 187 /// Determines size of each branch and sets the results for each node. 188 /// </summary> 189 /// <typeparam name="T">The data type encapsulated by a hash node</typeparam> 190 /// <param name="nodes">An array of hash nodes in postfix order.</param> 191 /// <returns>The array with updated node sizes. The array is not copied.</returns> 190 192 public static HashNode<T>[] UpdateNodeSizes<T>(this HashNode<T>[] nodes) where T : class { 191 193 for (int i = 0; i < nodes.Length; ++i) { … … 196 198 } 197 199 node.Size = node.Arity; 198 200 // visit all children and sum up their size (assumes postfix order). 199 201 for (int j = i - 1, k = 0; k < node.Arity; j -= 1 + nodes[j].Size, ++k) { 200 202 node.Size += nodes[j].Size; … … 204 206 } 205 207 208 // disables duplicate branches and removes the disabled nodes 206 209 public static HashNode<T>[] Reduce<T>(this HashNode<T>[] nodes) where T : class { 207 210 int count = 0; -
stable/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Hashing/SymbolicExpressionTreeHash.cs
r17099 r17141 48 48 ulong hashFunction(byte[] input) => HashUtil.DJBHash(input); 49 49 50 var hashNodes = simplify ? node.MakeNodes(strict).Simplify(hashFunction) : node.MakeNodes(strict).Sort(hashFunction); 50 var hashNodes = simplify ? node.MakeNodes(strict).Simplify(hashFunction) : node.MakeNodes(strict).Sort(hashFunction); // simplify sorts implicitly 51 51 var hashes = new ulong[hashNodes.Length]; 52 52 for (int i = 0; i < hashes.Length; ++i) { … … 210 210 var treeNodes = nodes.Select(x => x.Data.Symbol.CreateTreeNode()).ToArray(); 211 211 212 // construct tree top down (assumes postfix order for nodes) 212 213 for (int i = nodes.Length - 1; i >= 0; --i) { 213 214 var node = nodes[i]; … … 244 245 // (in other words simplification should be applied in a bottom-up fashion) 245 246 public static ISymbolicExpressionTree Simplify(ISymbolicExpressionTree tree) { 246 ulong hashFunction(byte[] bytes) => HashUtil. JSHash(bytes);247 var root = tree. Root.GetSubtree(0).GetSubtree(0);247 ulong hashFunction(byte[] bytes) => HashUtil.DJBHash(bytes); 248 var root = tree.ActualRoot(); 248 249 var nodes = root.MakeNodes(); 249 250 var simplified = nodes.Simplify(hashFunction); … … 369 370 nodes[i].Enabled = false; 370 371 } else if ((parentSymbol is Exponential && childSymbol is Logarithm) || (parentSymbol is Logarithm && childSymbol is Exponential)) { 372 // exp(log(x)) == x only for positive x. We consider this as equivalent for hashing anyway. 371 373 child.Enabled = parent.Enabled = false; 372 374 } -
stable/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Selectors/DiversitySelector.cs
r17140 r17141 66 66 } 67 67 68 public bool StrictSimilarity { get { return StrictSimilarityParameter.Value.Value; } } 69 70 public double SimilarityWeight { get { return SimilarityWeightParameter.Value.Value; } } 68 public bool StrictSimilarity { 69 get { return StrictSimilarityParameter.Value.Value; } 70 set { StrictSimilarityParameter.Value.Value = value; } 71 } 72 73 public double SimilarityWeight { 74 get { return SimilarityWeightParameter.Value.Value; } 75 set { SimilarityWeightParameter.Value.Value = value; } 76 } 71 77 72 78 public DiversitySelector() : base() { … … 74 80 Parameters.Add(new FixedValueParameter<DoubleValue>(SimilarityWeightParameterName, "Weight of the diversity term.", new DoubleValue(1))); 75 81 Parameters.Add(new ScopeTreeLookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression trees that should be analyzed.")); 76 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>(DiversityParameterName));77 82 Parameters.Add(new ValueParameter<ISingleObjectiveSelector>(SelectorParameterName, "The inner selection operator to select the parents.", new TournamentSelector())); 83 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>(DiversityParameterName, "The diversity value calcuated by the operator (output). The inner selector uses this value.")); 78 84 79 85 RegisterParameterEventHandlers(); … … 81 87 82 88 [StorableConstructor] 83 private DiversitySelector(StorableConstructorFlag deserializing) : base(deserializing) { }89 private DiversitySelector(StorableConstructorFlag _) : base(_) { } 84 90 85 91 private DiversitySelector(DiversitySelector original, Cloner cloner) : base(original, cloner) { } … … 91 97 [StorableHook(HookType.AfterDeserialization)] 92 98 private void AfterDeserialization() { 93 RegisterParameterEventHandlers();94 95 99 if (!Parameters.ContainsKey(DiversityParameterName)) { 96 100 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>(DiversityParameterName)); 97 101 } 102 103 RegisterParameterEventHandlers(); 98 104 } 99 105 … … 103 109 CopySelectedParameter.ValueChanged += CopySelectedParameter_ValueChanged; 104 110 CopySelected.ValueChanged += CopySelected_ValueChanged; 105 } 111 112 MaximizationParameter.NameChanged += MaximizationParameter_NameChanged; 113 QualityParameter.NameChanged += QualityParameter_NameChanged; 114 RandomParameter.NameChanged += RandomParameter_NameChanged; 115 } 116 117 private void RandomParameter_NameChanged(object sender, EventArgs e) { ParameterizeSelector(Selector); } 118 private void QualityParameter_NameChanged(object sender, EventArgs e) { ParameterizeSelector(Selector); } 119 private void MaximizationParameter_NameChanged(object sender, EventArgs e) { ParameterizeSelector(Selector); } 106 120 107 121 private void CopySelectedParameter_ValueChanged(object sender, EventArgs e) { … … 127 141 if (w.IsAlmost(0)) { 128 142 ApplyInnerSelector(); 129 return CurrentScope.SubScopes[1].SubScopes.ToArray(); 143 return CurrentScope.SubScopes[1].SubScopes.ToArray(); // return selected individuals (selectors create two sub-scopes with remaining and selected) 130 144 } 131 145
Note: See TracChangeset
for help on using the changeset viewer.