Changeset 8207


Ignore:
Timestamp:
07/03/12 17:36:20 (10 years ago)
Author:
gkronber
Message:

#1847: fixed some bugs

Location:
branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/ReplaceBranchMoveEvaluator.cs

    r8206 r8207  
    7878    public override IOperation Apply() {
    7979      var evaluator = EvaluatorParameter.ActualValue;
    80       var move = (ReplaceBranchMove)MoveParameter.ActualValue.Clone();
     80
     81      var move = MoveParameter.ActualValue;
    8182
    8283      // calculate linear scaling
     
    8889      move.Beta = beta;
    8990
    90       move.Parent.RemoveSubtree(move.SubtreeIndex);
    91       move.Parent.InsertSubtree(move.SubtreeIndex, Scale(move.NewBranch, alpha, beta));
     91      // clone tree and parent
     92      var cloner = new Cloner();
     93      var clonedTree = cloner.Clone(move.Tree);
     94      var clonedParent = cloner.Clone(move.Parent);
     95      var clonedBranch = cloner.Clone(move.NewBranch);
     96
     97      clonedParent.RemoveSubtree(move.SubtreeIndex);
     98      clonedParent.InsertSubtree(move.SubtreeIndex, Scale(clonedBranch, alpha, beta));
    9299
    93100      var problemData = ProblemDataParameter.ActualValue;
     
    96103      var fitnessPartition = FitnessCalculationPartitionParameter.ActualValue;
    97104      var rows = Enumerable.Range(fitnessPartition.Start, fitnessPartition.End - fitnessPartition.Start);
    98       var quality = evaluator.Evaluate(childContext, move.Tree, problemData, rows);
     105      var quality = evaluator.Evaluate(childContext, clonedTree, problemData, rows);
    99106
    100107      MoveQualityParameter.ActualValue = new DoubleValue(quality);
  • branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/ReplaceBranchMoveMaker.cs

    r8206 r8207  
    7474
    7575      quality.Value = moveQuality.Value;
     76      // update solution
     77      SymbolicExpressionTreeParameter.ActualValue = move.Tree;
    7678
    7779      return base.Apply();
  • branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/ReplaceBranchMultiMoveGenerator.cs

    r8206 r8207  
    112112      base.ClearState();
    113113    }
     114    public override void InitializeState() {
     115      trees = null;
     116      treeOutput = null;
     117      base.InitializeState();
     118    }
    114119
    115120    public override IOperation Apply() {
     
    149154      var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue;
    150155      var ds = ProblemDataParameter.ActualValue.Dataset;
    151       var rows = ProblemDataParameter.ActualValue.TrainingIndizes;
     156      var rows = ProblemDataParameter.ActualValue.TrainingIndices;
    152157
    153158      while (count < n) {
     
    160165
    161166        var bestTrees = new SortedList<double, Tuple<ISymbolicExpressionTree, double[]>>();
    162         double bestSimilarity = 0.0;
     167        double bestSimilarity = 0;
    163168        // iterate over the whole pool of branches for replacement
    164169        for (int i = 0; i < trees.Count; i++) {
     
    175180              bestTrees.Add(similarity, Tuple.Create(trees[i], treeOutput[i]));
    176181              if (bestTrees.Count > 30)
    177                 bestTrees.RemoveAt(bestTrees.Count - 1);
     182                bestTrees.RemoveAt(0); // remove moves with small R² at the beginning
     183
    178184            }
    179185          }
     
    206212      var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue;
    207213      var ds = ProblemDataParameter.ActualValue.Dataset;
    208       var rows = ProblemDataParameter.ActualValue.TrainingIndizes;
     214      var rows = ProblemDataParameter.ActualValue.TrainingIndices;
    209215      // create pool of random branches for replacement (no constants)
    210216      // and evaluate the output
Note: See TracChangeset for help on using the changeset viewer.