Free cookie consent management tool by TermsFeed Policy Generator

Changeset 7522


Ignore:
Timestamp:
02/24/12 17:30:16 (13 years ago)
Author:
bburlacu
Message:

#1772: Merged changes from trunk, rigged the TournamentSelector to track clones, improved tracking code.

Location:
branches/HeuristicLab.EvolutionaryTracking
Files:
1 deleted
17 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Analyzers/MinAverageMaxSymbolicExpressionTreeLengthAnalyzer.cs

    r7439 r7522  
    7373    private MinAverageMaxSymbolicExpressionTreeLengthAnalyzer(MinAverageMaxSymbolicExpressionTreeLengthAnalyzer original, Cloner cloner)
    7474      : base(original, cloner) {
     75      valueAnalyzer = cloner.Clone(original.valueAnalyzer);
     76      subScopesProcessor = cloner.Clone(original.subScopesProcessor);
    7577      AfterDeserialization();
    7678    }
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers/SubtreeCrossover.cs

    r7479 r7522  
    3636  /// until a valid configuration is found.
    3737  /// </summary> 
    38   [Item("SubtreeCrossover", "An operator which performs subtree swapping crossover.")]
     38  [Item("SubtreeSwappingCrossover", "An operator which performs subtree swapping crossover.")]
    3939  [StorableClass]
    40   public sealed class SubtreeCrossover : TracingSymbolicExpressionTreeCrossover, ISymbolicExpressionTreeSizeConstraintOperator {
     40  public class SubtreeCrossover : TracingSymbolicExpressionTreeCrossover, ISymbolicExpressionTreeSizeConstraintOperator {
    4141    private const string InternalCrossoverPointProbabilityParameterName = "InternalCrossoverPointProbability";
    4242    private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength";
    4343    private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth";
     44
    4445    #region Parameter Properties
    4546    public IValueLookupParameter<PercentValue> InternalCrossoverPointProbabilityParameter {
     
    6566    #endregion
    6667    [StorableConstructor]
    67     private SubtreeCrossover(bool deserializing) : base(deserializing) { }
    68     private SubtreeCrossover(SubtreeCrossover original, Cloner cloner) : base(original, cloner) { }
     68    protected SubtreeCrossover(bool deserializing) : base(deserializing) { }
     69    protected SubtreeCrossover(SubtreeCrossover original, Cloner cloner) : base(original, cloner) { }
    6970    public SubtreeCrossover()
    7071      : base() {
     
    7879    }
    7980
    80     protected override ISymbolicExpressionTree Cross(IRandom random,
     81    public override ISymbolicExpressionTree Crossover(IRandom random,
    8182      ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1) {
    8283      return Cross(random, parent0, parent1, InternalCrossoverPointProbability.Value,
     
    9495      // calculate the max length and depth that the inserted branch can have
    9596      int maxInsertedBranchLength = maxTreeLength - (parent0.Length - childLength);
    96       int maxInsertedBranchDepth = maxTreeDepth - GetBranchLevel(parent0.Root, crossoverPoint0.Parent);
     97      int maxInsertedBranchDepth = maxTreeDepth - parent0.Root.GetBranchLevel(crossoverPoint0.Parent);
    9798
    9899      List<ISymbolicExpressionTreeNode> allowedBranches = new List<ISymbolicExpressionTreeNode>();
    99100      parent1.Root.ForEachNodePostfix((n) => {
    100101        if (n.GetLength() <= maxInsertedBranchLength &&
    101             n.GetDepth() <= maxInsertedBranchDepth &&
    102             IsMatchingPointType(crossoverPoint0, n))
     102            n.GetDepth() <= maxInsertedBranchDepth && crossoverPoint0.IsMatchingPointType(n))
    103103          allowedBranches.Add(n);
    104104      });
    105105      // empty branch
    106       if (IsMatchingPointType(crossoverPoint0, null)) allowedBranches.Add(null);
     106      if (crossoverPoint0.IsMatchingPointType(null)) allowedBranches.Add(null);
    107107
    108108      if (allowedBranches.Count == 0) {
     
    128128    }
    129129
    130     private static bool IsMatchingPointType(CutPoint cutPoint, ISymbolicExpressionTreeNode newChild) {
    131       var parent = cutPoint.Parent;
    132       if (newChild == null) {
    133         // make sure that one subtree can be removed and that only the last subtree is removed
    134         return parent.Grammar.GetMinimumSubtreeCount(parent.Symbol) < parent.SubtreeCount &&
    135           cutPoint.ChildIndex == parent.SubtreeCount - 1;
    136       } else {
    137         // check syntax constraints of direct parent - child relation
    138         if (!parent.Grammar.ContainsSymbol(newChild.Symbol) ||
    139             !parent.Grammar.IsAllowedChildSymbol(parent.Symbol, newChild.Symbol, cutPoint.ChildIndex)) return false;
    140 
    141         bool result = true;
    142         // check point type for the whole branch
    143         newChild.ForEachNodePostfix((n) => {
    144           result =
    145             result &&
    146             parent.Grammar.ContainsSymbol(n.Symbol) &&
    147             n.SubtreeCount >= parent.Grammar.GetMinimumSubtreeCount(n.Symbol) &&
    148             n.SubtreeCount <= parent.Grammar.GetMaximumSubtreeCount(n.Symbol);
    149         });
    150         return result;
    151       }
    152     }
    153 
    154130    private static void SelectCrossoverPoint(IRandom random, ISymbolicExpressionTree parent0, double internalNodeProbability, int maxBranchLength, int maxBranchDepth, out CutPoint crossoverPoint) {
    155131      if (internalNodeProbability < 0.0 || internalNodeProbability > 1.0) throw new ArgumentException("internalNodeProbability");
     
    157133      List<CutPoint> leafCrossoverPoints = new List<CutPoint>();
    158134      parent0.Root.ForEachNodePostfix((n) => {
    159         if (n.Subtrees.Any() && n != parent0.Root) {
     135        if (n.SubtreeCount > 0 && n != parent0.Root) {
    160136          foreach (var child in n.Subtrees) {
    161137            if (child.GetLength() <= maxBranchLength &&
    162138                child.GetDepth() <= maxBranchDepth) {
    163               if (child.Subtrees.Any())
     139              if (child.SubtreeCount > 0)
    164140                internalCrossoverPoints.Add(new CutPoint(n, child));
    165141              else
     
    167143            }
    168144          }
     145
    169146          // add one additional extension point if the number of sub trees for the symbol is not full
    170147          if (n.SubtreeCount < n.Grammar.GetMaximumSubtreeCount(n.Symbol)) {
     
    173150          }
    174151        }
    175       });
     152      }
     153    );
    176154
    177155      if (random.NextDouble() < internalNodeProbability) {
     
    200178        // select internal node if possible
    201179        allowedInternalBranches = (from branch in branches
    202                                    where branch != null && branch.Subtrees.Any()
     180                                   where branch != null && branch.SubtreeCount > 0
    203181                                   select branch).ToList();
    204182        if (allowedInternalBranches.Count > 0) {
     
    207185          // no internal nodes allowed => select leaf nodes
    208186          allowedLeafBranches = (from branch in branches
    209                                  where branch == null || !branch.Subtrees.Any()
     187                                 where branch == null || branch.SubtreeCount == 0
    210188                                 select branch).ToList();
    211189          return allowedLeafBranches.SelectRandom(random);
     
    214192        // select leaf node if possible
    215193        allowedLeafBranches = (from branch in branches
    216                                where branch == null || !branch.Subtrees.Any()
     194                               where branch == null || branch.SubtreeCount == 0
    217195                               select branch).ToList();
    218196        if (allowedLeafBranches.Count > 0) {
     
    220198        } else {
    221199          allowedInternalBranches = (from branch in branches
    222                                      where branch != null && branch.Subtrees.Any()
     200                                     where branch != null && branch.SubtreeCount > 0
    223201                                     select branch).ToList();
    224202          return allowedInternalBranches.SelectRandom(random);
     
    226204      }
    227205    }
    228 
    229     private static int GetBranchLevel(ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeNode point) {
    230       if (root == point) return 0;
    231       foreach (var subtree in root.Subtrees) {
    232         int branchLevel = GetBranchLevel(subtree, point);
    233         if (branchLevel < int.MaxValue) return 1 + branchLevel;
    234       }
    235       return int.MaxValue;
    236     }
    237206  }
    238207}
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers/SymbolicExpressionTreeCrossover.cs

    r7439 r7522  
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Core;
    25 using HeuristicLab.Data;
    2625using HeuristicLab.Parameters;
    2726using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    6665        throw new ArgumentException("Number of parents must be exactly two for symbolic expression tree crossover operators.");
    6766
    68       ISymbolicExpressionTree result = Cross(Random, Parents[0], Parents[1]);
     67      ISymbolicExpressionTree result = Crossover(Random, Parents[0], Parents[1]);
    6968
    7069      Child = result;
     
    7271    }
    7372
    74     protected abstract ISymbolicExpressionTree Cross(IRandom random,
    75       ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1);
     73    public abstract ISymbolicExpressionTree Crossover(IRandom random, ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1);
    7674  }
    7775}
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers/TracingSymbolicExpressionTreeCrossover.cs

    r7514 r7522  
    9191      }
    9292      var originalParents = new ItemList<IItem>(Parents.Select(x => GlobalCloneMap[x]));
    93       ISymbolicExpressionTree result = Cross(Random, Parents[0], Parents[1]);
     93      ISymbolicExpressionTree result = Crossover(Random, Parents[0], Parents[1]);
    9494      Child = result;
    9595      GlobalTraceMap.Add(Child, originalParents);
     
    9898    }
    9999
    100     protected abstract ISymbolicExpressionTree Cross(IRandom random,
    101       ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1);
     100    public abstract ISymbolicExpressionTree Crossover(IRandom random, ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1);
    102101  }
    103102}
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/CutPoint.cs

    r7439 r7522  
    2222
    2323namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
    24   internal class CutPoint {
     24  public class CutPoint {
    2525    public ISymbolicExpressionTreeNode Parent { get; set; }
    2626    public ISymbolicExpressionTreeNode Child { get; set; }
     
    3939      this.Child = null;
    4040    }
     41
     42    public bool IsMatchingPointType(ISymbolicExpressionTreeNode newChild) {
     43      var parent = this.Parent;
     44      if (newChild == null) {
     45        // make sure that one subtree can be removed and that only the last subtree is removed
     46        return parent.Grammar.GetMinimumSubtreeCount(parent.Symbol) < parent.SubtreeCount &&
     47          this.ChildIndex == parent.SubtreeCount - 1;
     48      } else {
     49        // check syntax constraints of direct parent - child relation
     50        if (!parent.Grammar.ContainsSymbol(newChild.Symbol) ||
     51            !parent.Grammar.IsAllowedChildSymbol(parent.Symbol, newChild.Symbol, this.ChildIndex))
     52          return false;
     53
     54        bool result = true;
     55        // check point type for the whole branch
     56        newChild.ForEachNodePostfix((n) => {
     57          result =
     58            result &&
     59            parent.Grammar.ContainsSymbol(n.Symbol) &&
     60            n.SubtreeCount >= parent.Grammar.GetMinimumSubtreeCount(n.Symbol) &&
     61            n.SubtreeCount <= parent.Grammar.GetMaximumSubtreeCount(n.Symbol);
     62        });
     63        return result;
     64      }
     65    }
    4166  }
    4267}
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/ISymbolicExpressionTreeNode.cs

    r7439 r7522  
    3232    int GetDepth();
    3333    int GetLength();
     34    int GetBranchLevel(ISymbolicExpressionTreeNode child);
    3435
    3536    IEnumerable<ISymbolicExpressionTreeNode> IterateNodesPostfix();
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/Operators/ISymbolicExpressionTreeCrossover.cs

    r7439 r7522  
    3030    ILookupParameter<ItemArray<ISymbolicExpressionTree>> ParentsParameter { get; }
    3131    ILookupParameter<ISymbolicExpressionTree> ChildParameter { get; }
     32    ISymbolicExpressionTree Crossover(IRandom random, ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1);
    3233  }
    3334}
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Plugin.cs

    r7514 r7522  
    2626
    2727namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
    28   [Plugin("HeuristicLab.Encodings.SymbolicExpressionTreeEncoding","Provides operators and related classes for the symbolic expression tree encoding.", "3.4.2.7479")]
     28  [Plugin("HeuristicLab.Encodings.SymbolicExpressionTreeEncoding","Provides operators and related classes for the symbolic expression tree encoding.", "3.4.2.7514")]
    2929  [PluginFile("HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.dll", PluginFileType.Assembly)]
    3030  [PluginDependency("HeuristicLab.Analysis", "3.3")]
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Properties

    • Property svn:ignore set to
      *.bak
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Properties/AssemblyInfo.cs

    r7439 r7522  
    4545
    4646[assembly: AssemblyVersion("3.4.0.0")]
    47 [assembly: AssemblyFileVersion("3.4.2.7280")]
     47[assembly: AssemblyFileVersion("3.4.2.7507")]
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeNode.cs

    r7439 r7522  
    125125    }
    126126
     127    public int GetBranchLevel(ISymbolicExpressionTreeNode child) {
     128      return GetBranchLevel(this, child);
     129    }
     130
     131    private static int GetBranchLevel(ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeNode point) {
     132      if (root == point)
     133        return 0;
     134      foreach (var subtree in root.Subtrees) {
     135        int branchLevel = GetBranchLevel(subtree, point);
     136        if (branchLevel < int.MaxValue)
     137          return 1 + branchLevel;
     138      }
     139      return int.MaxValue;
     140    }
     141
    127142    public virtual void ResetLocalParameters(IRandom random) { }
    128143    public virtual void ShakeLocalParameters(IRandom random, double shakingFactor) { }
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.EvolutionaryTracking/3.4/Analyzers/SymbolicExpressionTreeGenealogyAnalyzer.cs

    r7515 r7522  
    3636using HeuristicLab.Problems.DataAnalysis;
    3737using HeuristicLab.Problems.DataAnalysis.Symbolic;
    38 
     38using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;
    3939using CloneMapType = HeuristicLab.Core.ItemDictionary<HeuristicLab.Core.IItem, HeuristicLab.Core.IItem>;
    4040using TraceMapType = HeuristicLab.Core.ItemDictionary<HeuristicLab.Core.IItem, HeuristicLab.Core.IItemList<HeuristicLab.Core.IItem>>;
     
    229229        // add all individuals to the evolutionary graph
    230230        int generation = Generations.Value;
    231         int count = GlobalTraceMap.Count;
    232231        string label;
    233232
     
    238237            var tree = qualities.ElementAt(i).Key;
    239238            label = (i + 1).ToString(CultureInfo.InvariantCulture);
    240             graph.AddNode(tree, qualities[tree], label, generation);
     239            graph.AddNode(tree, qualities[tree], label, generation, i < Elites.Value);
    241240          }
    242241          return base.Apply();
    243242        }
    244243
    245         // mark and add elites
    246         // elites do not appear in the trace map (because they are never the product of a genetic operation)
    247         var elites = qualities.OrderByDescending(x => x.Value).Take(Elites.Value).Select(x => x.Key).ToList();
    248         for (int i = 0; i != Elites.Value; ++i) {
    249           label = (generation * count + i + 1).ToString(CultureInfo.InvariantCulture);
    250           var elite = elites[i];
    251           if (!graph.HasNode(elite))
    252             graph.AddNode(elite, qualities[elite], label, Generations.Value, true);
    253           else
    254             graph.GetNode(elite).Label += "\\n" + label;
    255 
    256           graph.GetNode(elite).Color = new Color { R = 0, G = 100, B = 150 };
    257         }
    258 
    259         for (int i = 0; i != count; ++i) {
    260           var trace = GlobalTraceMap.ElementAt(i);
    261           var child = (ISymbolicExpressionTree)trace.Key;
    262 
    263           if (!graph.HasNode(child)) {
    264             // due to the structure of the trace map, qualities[child] will never throw an exception, so we use it directly
    265             label = (generation * count + i + 1 + Elites.Value).ToString(CultureInfo.InvariantCulture);
     244        for (int i = 0; i != qualities.Count; ++i) {
     245          var child = qualities.ElementAt(i).Key;
     246          label = (generation * qualities.Count + i + 1).ToString(CultureInfo.InvariantCulture);
     247          if (i < Elites.Value) {
     248            if (graph.HasNode(child))
     249              graph.GetNode(child).Label += "\\n" + label;
     250            else
     251              graph.AddNode(child, qualities[child], label, generation, true);
     252          } else
    266253            graph.AddNode(child, qualities[child], label, generation);
    267           }
    268           var parents = trace.Value;
     254          if (!GlobalTraceMap.ContainsKey(child)) continue;
     255          var parents = GlobalTraceMap[child];
    269256          foreach (var parent in parents) {
    270             if (!graph.HasNode(parent)) {
    271               // if the node is a clone introduced pre-mutation, then its quality value has to be evaluated
    272               if (!qualities.ContainsKey(parent))
    273                 qualities[parent] = Evaluate((ISymbolicExpressionTree)parent);
    274               label = ((generation - 1) * count + i + 1).ToString(CultureInfo.InvariantCulture);
    275               graph.AddNode(parent, qualities[parent], label, generation - 1);
     257            if (GlobalTraceMap.ContainsKey(parent)) {
     258              double quality = Evaluate((ISymbolicExpressionTree)parent);
     259              graph.AddNode(parent, quality, "", generation - 0.5);
     260              foreach (var p in GlobalTraceMap[parent])
     261                graph.AddArc(p, parent);
    276262            }
    277263            graph.AddArc(parent, child);
    278264          }
    279265        }
    280         GlobalTraceMap.Clear(); // no need to check for null here (see line 212)
    281 
    282         // if we've reached the end of the run
     266
     267        GlobalTraceMap.Clear();
     268        GlobalCloneMap.Clear();
     269
     270        #region end of the run
    283271        bool maxGenerationsReached = (Generations.Value == MaximumGenerations.Value);
    284272        bool isOsga = (SelectionPressure != null && MaximumSelectionPressure != null);
    285273        bool maxSelectionPressureReached = isOsga && (SelectionPressure.Value >= MaximumSelectionPressure.Value);
    286 
    287         #region end of the run
    288274        if (maxGenerationsReached || maxSelectionPressureReached) {
    289275          var path = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
     
    300286
    301287          // calculate impact values of nodes in the best solution, attempt to trace those with high impact to their origins
    302           //var impactValuesCalculator = new RegressionSolutionImpactValuesCalculator();
    303           //var impactValues = impactValuesCalculator.CalculateImpactValues(bestSolution, SymbolicExpressionInterpreter, SymbolicRegressionProblemData);
    304           ////var impactValues = CalculateImpactValues(bestSolution);
    305           //foreach (var pair in impactValues.Where(pair => !(pair.Key is ConstantTreeNode || pair.Key is VariableTreeNode) && pair.Value > 0.9)) {
    306           //  var node = pair.Key;
    307 
    308           //  foreach (var ancestor in genealogy.Keys) {
    309           //    graph.GetNode(ancestor).Color = ContainsSubtree(ancestor as ISymbolicExpressionTree, node) ? new Color { R = 0, G = 0, B = 150 } : new Color { R = 255, G = 255, B = 255 };
    310           //  }
    311           //}
    312           //WriteDot(path + @"\impactancestry.dot", genealogy);
     288          var calculator = new SymbolicRegressionSolutionValuesCalculator();
     289          var impactValues = calculator.CalculateImpactValues(bestSolution, SymbolicExpressionInterpreter, SymbolicRegressionProblemData, 0, 0);
     290          foreach (var pair in impactValues.Where(pair => !(pair.Key is ConstantTreeNode || pair.Key is VariableTreeNode) && pair.Value > 0.9)) {
     291            var node = pair.Key;
     292
     293            foreach (var ancestor in genealogy.Keys) {
     294              graph.GetNode(ancestor).Color = ContainsSubtree(ancestor as ISymbolicExpressionTree, node) ? new Color { R = 0, G = 0, B = 150 } : new Color { R = 255, G = 255, B = 255 };
     295            }
     296          }
     297          WriteDot(path + @"\impactancestry.dot", genealogy);
    313298
    314299          // trim the graph
     
    361346        foreach (var node in graph.Values) {
    362347          string fillColor = String.Format("#{0:x2}{1:x2}{2:x2}", node.Color.R, node.Color.G, node.Color.B);
     348          string shape = "circle";
    363349          if (node.IsElite)
    364             fillColor = String.Format("#{0:x2}{1:x2}{2:x2}", node.Color.R, node.Color.G, 150);
    365           file.WriteLine("\t\"" + node.Id + "\" [fillcolor=\"" + fillColor + "\",label=\"" + node.Label + "\"];");
     350            shape = "doublecircle";
     351          file.WriteLine("\t\"" + node.Id + "\" [shape=" + shape + ",fillcolor=\"" + fillColor + "\",label=\"" + node.Label + "\"];");
    366352          if (node.InEdges == null)
    367353            continue;
     
    371357          }
    372358        }
    373         foreach (var g in graph.Values.GroupBy(x => x.Generation)) {
     359        foreach (var g in graph.Values.GroupBy(x => x.Rank)) {
    374360          var sb = new StringBuilder();
    375361          sb.Append("\t{rank=same;");
     
    380366        }
    381367        file.WriteLine("}");
    382       }
    383     }
    384     #endregion
    385 
    386     #region Impact values (code for calculating to be moved in separate class)
    387     private Dictionary<ISymbolicExpressionTreeNode, double> CalculateImpactValues(ISymbolicExpressionTree tree) {
    388       var interpreter = SymbolicExpressionInterpreter;
    389       var problemData = (IRegressionProblemData)SymbolicDataAnalysisEvaluator.Parameters["ProblemData"].ActualValue;
    390       var dataset = problemData.Dataset;
    391       var rows = problemData.TrainingIndizes;
    392       string targetVariable = problemData.TargetVariable;
    393       var impactValues = new Dictionary<ISymbolicExpressionTreeNode, double>();
    394       var nodes = tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPostfix().ToList();
    395       var originalOutput = interpreter.GetSymbolicExpressionTreeValues(tree, dataset, rows);
    396       var targetValues = dataset.GetDoubleValues(targetVariable, rows);
    397       OnlineCalculatorError errorState;
    398       double originalR2 = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, originalOutput, out errorState);
    399       if (errorState != OnlineCalculatorError.None) originalR2 = 0.0;
    400 
    401       var constantNode = ((ConstantTreeNode)new Constant().CreateTreeNode());
    402       var root = new ProgramRootSymbol().CreateTreeNode(); // root node
    403       var start = new StartSymbol().CreateTreeNode(); // start node
    404       root.AddSubtree(start);
    405       var tempTree = new SymbolicExpressionTree(root);
    406 
    407       foreach (ISymbolicExpressionTreeNode node in nodes) {
    408         var parent = node.Parent;
    409         constantNode.Value = CalculateReplacementValue(tempTree, node, tree);
    410         ISymbolicExpressionTreeNode replacementNode = constantNode;
    411         SwitchNode(parent, node, replacementNode);
    412         var newOutput = interpreter.GetSymbolicExpressionTreeValues(tree, dataset, rows);
    413         double newR2 = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, newOutput, out errorState);
    414         if (errorState != OnlineCalculatorError.None) newR2 = 0.0;
    415 
    416         // impact = 0 if no change
    417         // impact < 0 if new solution is better
    418         // impact > 0 if new solution is worse
    419         impactValues[node] = originalR2 - newR2;
    420         SwitchNode(parent, replacementNode, node);
    421       }
    422       return impactValues;
    423     }
    424 
    425     private double CalculateReplacementValue(ISymbolicExpressionTree tempTree, ISymbolicExpressionTreeNode node, ISymbolicExpressionTree sourceTree) {
    426       // remove old ADFs
    427       while (tempTree.Root.SubtreeCount > 1) tempTree.Root.RemoveSubtree(1);
    428       // clone ADFs of source tree
    429       for (int i = 1; i < sourceTree.Root.SubtreeCount; i++) {
    430         tempTree.Root.AddSubtree((ISymbolicExpressionTreeNode)sourceTree.Root.GetSubtree(i).Clone());
    431       }
    432       var start = tempTree.Root.GetSubtree(0);
    433       while (start.SubtreeCount > 0) start.RemoveSubtree(0);
    434       start.AddSubtree((ISymbolicExpressionTreeNode)node.Clone());
    435       var interpreter = SymbolicExpressionInterpreter;
    436       var rows = SymbolicRegressionProblemData.TrainingIndizes;
    437       return interpreter.GetSymbolicExpressionTreeValues(tempTree, SymbolicRegressionProblemData.Dataset, rows).Median();
    438     }
    439 
    440     private static void SwitchNode(ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeNode oldBranch, ISymbolicExpressionTreeNode newBranch) {
    441       for (int i = 0; i < root.SubtreeCount; i++) {
    442         if (root.GetSubtree(i) == oldBranch) {
    443           root.RemoveSubtree(i);
    444           root.InsertSubtree(i, newBranch);
    445           return;
    446         }
    447368      }
    448369    }
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.EvolutionaryTracking/3.4/GenealogyGraph.cs

    r7515 r7522  
    8484    /// <param name="l">The node label</param>
    8585    /// <param name="elite">Specifies if this node is an elite</param>
    86     public void AddNode(object t, double q = 0.0, string l = "", int g = 0, bool elite = false) {
     86    public void AddNode(object t, double q = 0.0, string l = "", double g = 0, bool elite = false) {
    8787      if (HasNode(t)) return;
    8888      var color = new Color { R = (byte)(255 - 255 * q), G = (byte)(255 * q), B = 50 };
    89       _dictionary[t] = new Node { Data = t, Quality = q, Label = l, IsElite = elite, Generation = g, Color = color };
     89      _dictionary[t] = new Node { Data = t, Quality = q, Label = l, IsElite = elite, Rank = g, Color = color };
    9090    }
    9191
     
    186186    public object Data { get; set; }
    187187    public double Quality { get; set; }
    188     public int Generation { get; set; }
     188    public double Rank { get; set; }
    189189    public Color Color { get; set; }
    190190
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.EvolutionaryTracking/3.4/HeuristicLab.EvolutionaryTracking-3.4.csproj

    r7515 r7522  
    102102    <Compile Include="Plugin.cs" />
    103103    <Compile Include="Properties\AssemblyInfo.cs" />
    104     <Compile Include="RegressionSolutionImpactValuesCalculator.cs">
    105       <SubType>UserControl</SubType>
    106     </Compile>
    107104  </ItemGroup>
    108105  <ItemGroup>
Note: See TracChangeset for help on using the changeset viewer.