Free cookie consent management tool by TermsFeed Policy Generator

Changeset 7496


Ignore:
Timestamp:
02/21/12 11:03:08 (12 years ago)
Author:
bburlacu
Message:

#1683: Simplified selection of cut points and allowed branches.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Crossovers/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionSemanticSimilarityCrossover.cs

    r7488 r7496  
    3030
    3131namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    32   [Item("SemanticSimilarityCrossover", "An operator which performs subtree swapping based on the semantic similarity between subtrees.")]
     32  [Item("SemanticSimilarityCrossover", "An operator which performs subtree swapping based on the notion semantic similarity between subtrees\n" +
     33                                       "(criteria: mean of the absolute differences between the estimated output values of the two subtrees, falling into a user-defined range)\n" +
     34                                       "- Take two parent individuals P0 and P1\n" +
     35                                       "- Randomly choose a node N from the P0\n" +
     36                                       "- Find the first node M that satisfies the semantic similarity criteria\n" +
     37                                       "- Swap N for M and return P0")]
    3338  public sealed class SymbolicDataAnalysisExpressionSemanticSimilarityCrossover<T> : SymbolicDataAnalysisExpressionCrossover<T> where T : class, IDataAnalysisProblemData {
    3439    private const string SemanticSimilarityRangeParameterName = "SemanticSimilarityRange";
     
    5257      : base() {
    5358      Parameters.Add(new ValueLookupParameter<DoubleRange>(SemanticSimilarityRangeParameterName, "Semantic similarity interval.", new DoubleRange(0.0001, 10)));
     59      Name = "SemanticSimilarityCrossover";
    5460    }
    5561    public override IDeepCloneable Clone(Cloner cloner) {
     
    7278      var crossoverPoints0 = new List<CutPoint>();
    7379      parent0.Root.ForEachNodePostfix((n) => {
    74         if (n.Subtrees.Any() && n != parent0.Root)
    75           foreach (var child in n.Subtrees)
    76             crossoverPoints0.Add(new CutPoint(n, child));
     80        if (n.Parent != null && n.Parent != parent0.Root)
     81          crossoverPoints0.Add(new CutPoint(n.Parent, n));
    7782      });
    7883      var crossoverPoint0 = crossoverPoints0.SelectRandom(random);
     
    8287      var allowedBranches = new List<ISymbolicExpressionTreeNode>();
    8388      parent1.Root.ForEachNodePostfix((n) => {
    84         if (n.Subtrees.Any() && n != parent1.Root)
    85           allowedBranches.AddRange(n.Subtrees.Where(s => crossoverPoint0.IsMatchingPointType(s) && s.GetDepth() + level <= maxDepth && s.GetLength() + length <= maxLength));
     89        if (n.Parent != null && n.Parent != parent1.Root) {
     90          if (n.GetDepth() + level <= maxDepth && n.GetLength() + length <= maxLength && crossoverPoint0.IsMatchingPointType(n))
     91            allowedBranches.Add(n);
     92        }
    8693      });
    8794
     
    117124      // perform the actual swap
    118125      if (selectedBranch != null)
    119         swap(crossoverPoint0, selectedBranch);
    120 
     126        Swap(crossoverPoint0, selectedBranch);
    121127      return parent0;
    122     }
    123 
    124     private static void swap(CutPoint crossoverPoint, ISymbolicExpressionTreeNode selectedBranch) {
    125       // perform the actual swap
    126       if (crossoverPoint.Child != null) {
    127         // manipulate the tree of parent0 in place
    128         // replace the branch in tree0 with the selected branch from tree1
    129         crossoverPoint.Parent.RemoveSubtree(crossoverPoint.ChildIndex);
    130         if (selectedBranch != null) {
    131           crossoverPoint.Parent.InsertSubtree(crossoverPoint.ChildIndex, selectedBranch);
    132         }
    133       } else {
    134         // child is null (additional child should be added under the parent)
    135         if (selectedBranch != null) {
    136           crossoverPoint.Parent.AddSubtree(selectedBranch);
    137         }
    138       }
    139128    }
    140129  }
Note: See TracChangeset for help on using the changeset viewer.