Ignore:
Timestamp:
02/20/14 14:29:01 (6 years ago)
Author:
gkronber
Message:

#2124 merged all changes from trunk to prepare for trunk-reintegration

Location:
branches/SpectralKernelForGaussianProcesses
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/SpectralKernelForGaussianProcesses

  • branches/SpectralKernelForGaussianProcesses/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification

  • branches/SpectralKernelForGaussianProcesses/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationSolutionImpactValuesCalculator.cs

    r9456 r10479  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using HeuristicLab.Common;
     25using HeuristicLab.Core;
    2426using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2528
    2629namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification {
     30  [StorableClass]
     31  [Item("SymbolicClassificationSolutionImpactValuesCalculator", "Calculate symbolic expression tree node impact values for classification problems.")]
    2732  public class SymbolicClassificationSolutionImpactValuesCalculator : SymbolicDataAnalysisSolutionImpactValuesCalculator {
     33    public SymbolicClassificationSolutionImpactValuesCalculator() { }
     34    protected SymbolicClassificationSolutionImpactValuesCalculator(SymbolicClassificationSolutionImpactValuesCalculator original, Cloner cloner)
     35      : base(original, cloner) { }
     36    public override IDeepCloneable Clone(Cloner cloner) {
     37      return new SymbolicClassificationSolutionImpactValuesCalculator(this, cloner);
     38    }
     39    [StorableConstructor]
     40    protected SymbolicClassificationSolutionImpactValuesCalculator(bool deserializing) : base(deserializing) { }
     41
    2842    public override double CalculateReplacementValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows) {
    2943      var classificationModel = (ISymbolicClassificationModel)model;
     
    3448
    3549    public override double CalculateImpactValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows, double originalQuality = double.NaN) {
     50      double impactValue, replacementValue;
     51      CalculateImpactAndReplacementValues(model, node, problemData, rows, out impactValue, out replacementValue, originalQuality);
     52      return impactValue;
     53    }
     54
     55    public override void CalculateImpactAndReplacementValues(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node,
     56      IDataAnalysisProblemData problemData, IEnumerable<int> rows, out double impactValue, out double replacementValue,
     57      double originalQuality = Double.NaN) {
    3658      var classificationModel = (ISymbolicClassificationModel)model;
    3759      var classificationProblemData = (IClassificationProblemData)problemData;
     
    4769      }
    4870
    49       var replacementValue = CalculateReplacementValue(classificationModel, node, classificationProblemData, rows);
     71      replacementValue = CalculateReplacementValue(classificationModel, node, classificationProblemData, rows);
    5072      var constantNode = new ConstantTreeNode(new Constant()) { Value = replacementValue };
     73
    5174      var cloner = new Cloner();
    52       cloner.RegisterClonedObject(node, constantNode);
    5375      var tempModel = cloner.Clone(classificationModel);
    54       tempModel.RecalculateModelParameters(classificationProblemData, rows);
     76      var tempModelNode = (ISymbolicExpressionTreeNode)cloner.GetClone(node);
     77
     78      var tempModelParentNode = tempModelNode.Parent;
     79      int i = tempModelParentNode.IndexOfSubtree(tempModelNode);
     80      tempModelParentNode.RemoveSubtree(i);
     81      tempModelParentNode.InsertSubtree(i, constantNode);
    5582
    5683      var estimatedClassValues = tempModel.GetEstimatedClassValues(dataset, rows);
     
    5885      if (errorState != OnlineCalculatorError.None) newQuality = 0.0;
    5986
    60       return originalQuality - newQuality;
     87      impactValue = originalQuality - newQuality;
    6188    }
    62 
    6389  }
    6490}
Note: See TracChangeset for help on using the changeset viewer.