Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/22/15 14:27:37 (9 years ago)
Author:
bburlacu
Message:

#1772: Merge trunk changes. Remove dead code from the genealogy analyzer.

Location:
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic
Files:
26 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic

  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/BuildingBlockAnalyzers/SymbolicDataAnalysisPoly10Analyzer.cs

    r12406 r12891  
    153153            var values = interpreter.GetValues(s, dataset, rows);
    154154            OnlineCalculatorError error;
    155             var r2 = OnlinePearsonsRSquaredCalculator.Calculate(values, evaluationMap[key], out error);
    156             if (error == OnlineCalculatorError.None && r2 >= PhenotypicSimilarityThreshold) {
     155            var r = OnlinePearsonsRCalculator.Calculate(values, evaluationMap[key], out error);
     156            var r2 = error == OnlineCalculatorError.None ? r * r : double.NaN;
     157            if (!double.IsNaN(r2) && r2 >= PhenotypicSimilarityThreshold) {
    157158              bbFrequencies[key]++;
    158159              i += s.GetLength();
     
    162163      }
    163164      var table = (DataTable)results[BuildingBlocksFrequenciesTableName].Value;
    164       double max = bbFrequencies.Max(x => x.Value);
    165165      foreach (var pair in bbFrequencies) {
    166166        var formatter = new SymbolicExpressionTreeStringFormatter();
     
    169169        if (table.Rows.ContainsKey(label)) {
    170170          var row = table.Rows[label];
    171           row.Values.Add(max > 0 ? pair.Value / max : 0);
     171          row.Values.Add(pair.Value);
    172172        }
    173173      }
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisSingleObjectivePruningAnalyzer.cs

    r12155 r12891  
    4545    private const string TotalNumberOfPrunedSubtreesParameterName = "Number of pruned subtrees";
    4646    private const string TotalNumberOfPrunedTreesParameterName = "Number of pruned trees";
     47    private const string TotalNumberOfPrunedNodesParameterName = "Number of pruned nodes";
    4748    private const string RandomParameterName = "Random";
    48     private const string PruneOnlyZeroImpactNodesParameterName = "PruneOnlyZeroImpactNodes";
    49     private const string NodeImpactThresholdParameterName = "ImpactThreshold";
    50     private const string PruningOperatorParameterName = "PruningOperator";
    5149    private const string ResultsParameterName = "Results";
    5250    private const string PopulationSizeParameterName = "PopulationSize";
     
    5452
    5553    #region private members
     54    private DataReducer prunedNodesReducer;
    5655    private DataReducer prunedSubtreesReducer;
    5756    private DataReducer prunedTreesReducer;
     
    6160
    6261    #region parameter properties
    63     public IValueParameter<SymbolicDataAnalysisExpressionPruningOperator> PruningOperatorParameter {
    64       get { return (IValueParameter<SymbolicDataAnalysisExpressionPruningOperator>)Parameters[PruningOperatorParameterName]; }
    65     }
    66     public IFixedValueParameter<BoolValue> PruneOnlyZeroImpactNodesParameter {
    67       get { return (IFixedValueParameter<BoolValue>)Parameters[PruneOnlyZeroImpactNodesParameterName]; }
    68     }
    69     public IFixedValueParameter<DoubleValue> NodeImpactThresholdParameter {
    70       get { return (IFixedValueParameter<DoubleValue>)Parameters[NodeImpactThresholdParameterName]; }
    71     }
    7262    public ILookupParameter<IRandom> RandomParameter {
    7363      get { return (ILookupParameter<IRandom>)Parameters[RandomParameterName]; }
     
    9181
    9282    #region properties
    93     protected SymbolicDataAnalysisExpressionPruningOperator PruningOperator { get { return PruningOperatorParameter.Value; } }
     83    protected abstract SymbolicDataAnalysisExpressionPruningOperator PruningOperator { get; }
    9484    protected int UpdateInterval { get { return UpdateIntervalParameter.Value.Value; } }
    9585
     
    112102      get { return PruningProbabilityParameter.Value.Value; }
    113103      set { PruningProbabilityParameter.Value.Value = value; }
    114     }
    115 
    116     protected bool PruneOnlyZeroImpactNodes {
    117       get { return PruneOnlyZeroImpactNodesParameter.Value.Value; }
    118       set { PruneOnlyZeroImpactNodesParameter.Value.Value = value; }
    119     }
    120     protected double NodeImpactThreshold {
    121       get { return NodeImpactThresholdParameter.Value.Value; }
    122       set { NodeImpactThresholdParameter.Value.Value = value; }
    123104    }
    124105    #endregion
     
    140121    protected SymbolicDataAnalysisSingleObjectivePruningAnalyzer(SymbolicDataAnalysisSingleObjectivePruningAnalyzer original, Cloner cloner)
    141122      : base(original, cloner) {
     123      if (original.prunedNodesReducer != null)
     124        this.prunedNodesReducer = (DataReducer)original.prunedNodesReducer.Clone();
    142125      if (original.prunedSubtreesReducer != null)
    143126        this.prunedSubtreesReducer = (DataReducer)original.prunedSubtreesReducer.Clone();
     
    197180      Parameters.Add(new LookupParameter<IRandom>(RandomParameterName, "The random number generator."));
    198181      Parameters.Add(new LookupParameter<IDataAnalysisProblemData>(ProblemDataParameterName, "The problem data."));
    199       Parameters.Add(new FixedValueParameter<DoubleValue>(NodeImpactThresholdParameterName, "The impact threshold  below which an individual should be pruned.", new DoubleValue(0.0)));
    200       Parameters.Add(new FixedValueParameter<BoolValue>(PruneOnlyZeroImpactNodesParameterName, "Switch to determine of only zero impact individuals should be pruned.", new BoolValue(false)));
    201182      Parameters.Add(new LookupParameter<IntValue>(PopulationSizeParameterName, "The population of individuals."));
    202183      #endregion
     
    225206      var qualities = Quality.Select(x => x.Value).ToArray();
    226207      var indices = Enumerable.Range(0, qualities.Length).ToArray();
    227       Array.Sort(qualities, indices);
     208      indices.StableSort((a, b) => qualities[a].CompareTo(qualities[b]));
     209
    228210      if (!Maximization.Value) Array.Reverse(indices);
    229211
     
    233215      var empty = new EmptyOperator();
    234216
    235       for (int i = 0; i < subscopes.Count; ++i) {
     217      for (int i = 0; i < indices.Length; ++i) {
    236218        IOperator @operator;
    237219        if (range.Start <= i && i < range.End && random.NextDouble() <= PruningProbability)
     
    250232      UpdateCounter = 0;
    251233
    252       if (prunedSubtreesReducer == null || prunedTreesReducer == null || valuesCollector == null || resultsCollector == null) { InitializeOperators(); }
     234      if (prunedNodesReducer == null || prunedSubtreesReducer == null || prunedTreesReducer == null || valuesCollector == null || resultsCollector == null) { InitializeOperators(); }
    253235
    254236      var prune = CreatePruningOperation();
     237      var reducePrunedNodes = ExecutionContext.CreateChildOperation(prunedNodesReducer);
    255238      var reducePrunedSubtrees = ExecutionContext.CreateChildOperation(prunedSubtreesReducer);
    256239      var reducePrunedTrees = ExecutionContext.CreateChildOperation(prunedTreesReducer);
     
    258241      var collectResults = ExecutionContext.CreateChildOperation(resultsCollector);
    259242
    260       return new OperationCollection { prune, reducePrunedSubtrees, reducePrunedTrees, collectValues, collectResults, base.Apply() };
     243      return new OperationCollection { prune, reducePrunedNodes, reducePrunedSubtrees, reducePrunedTrees, collectValues, collectResults, base.Apply() };
    261244    }
    262245
    263246    private void InitializeOperators() {
     247      prunedNodesReducer = new DataReducer();
     248      prunedNodesReducer.ParameterToReduce.ActualName = PruningOperator.PrunedNodesParameter.ActualName;
     249      prunedNodesReducer.ReductionOperation.Value = new ReductionOperation(ReductionOperations.Sum); // sum all the pruned subtrees parameter values
     250      prunedNodesReducer.TargetOperation.Value = new ReductionOperation(ReductionOperations.Assign); // asign the sum to the target parameter
     251      prunedNodesReducer.TargetParameter.ActualName = TotalNumberOfPrunedNodesParameterName;
     252
    264253      prunedSubtreesReducer = new DataReducer();
    265254      prunedSubtreesReducer.ParameterToReduce.ActualName = PruningOperator.PrunedSubtreesParameter.ActualName;
     
    275264
    276265      valuesCollector = new DataTableValuesCollector();
     266      valuesCollector.CollectedValues.Add(new LookupParameter<IntValue>(TotalNumberOfPrunedNodesParameterName));
    277267      valuesCollector.CollectedValues.Add(new LookupParameter<IntValue>(TotalNumberOfPrunedSubtreesParameterName));
    278268      valuesCollector.CollectedValues.Add(new LookupParameter<IntValue>(TotalNumberOfPrunedTreesParameterName));
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/MultiSymbolicDataAnalysisExpressionCrossover.cs

    r12155 r12891  
    3535namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    3636  [Item("MultiSymbolicDataAnalysisExpressionCrossover", "Randomly selects and applies one of its crossovers every time it is called.")]
     37  [StorableClass]
    3738  public class MultiSymbolicDataAnalysisExpressionCrossover<T> : StochasticMultiBranch<ISymbolicExpressionTreeCrossover>,
    3839    ISymbolicDataAnalysisExpressionCrossover<T> where T : class, IDataAnalysisProblemData {
    3940    private const string ParentsParameterName = "Parents";
    40     private const string ChildParameterName = "Child";
     41    private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
    4142    private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength";
    4243    private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth";
     
    6263      get { return (ScopeTreeLookupParameter<ISymbolicExpressionTree>)Parameters[ParentsParameterName]; }
    6364    }
    64     public ILookupParameter<ISymbolicExpressionTree> ChildParameter {
    65       get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters[ChildParameterName]; }
     65    public ILookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter {
     66      get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }
    6667    }
    6768    public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter {
     
    99100      Parameters.Add(new ValueLookupParameter<IntRange>(SymbolicDataAnalysisEvaluationPartitionParameterName, "The start index of the dataset partition on which the symbolic data analysis solution should be evaluated."));
    100101      Parameters.Add(new ScopeTreeLookupParameter<ISymbolicExpressionTree>(ParentsParameterName, "The parent symbolic expression trees which should be crossed."));
    101       Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(ChildParameterName, "The child symbolic expression tree resulting from the crossover."));
     102      Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The child symbolic expression tree resulting from the crossover."));
    102103
    103104      EvaluatorParameter.Hidden = true;
     
    111112
    112113      SelectedOperatorParameter.ActualName = "SelectedCrossoverOperator";
     114    }
     115
     116    [StorableHook(HookType.AfterDeserialization)]
     117    private void AfterDeserialization() {
     118      // BackwardsCompatibility3.3
     119      #region Backwards compatible code, remove with 3.4
     120      if (!Parameters.ContainsKey(SymbolicExpressionTreeParameterName))
     121        Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression tree on which the operator should be applied."));
     122      #endregion
    113123    }
    114124
     
    155165    private void ParameterizeCrossovers() {
    156166      foreach (ISymbolicExpressionTreeCrossover op in Operators) {
    157         op.ChildParameter.ActualName = ChildParameter.Name;
     167        op.SymbolicExpressionTreeParameter.ActualName = SymbolicExpressionTreeParameter.Name;
    158168        op.ParentsParameter.ActualName = ParentsParameter.Name;
    159169      }
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionContextAwareCrossover.cs

    r12155 r12891  
    2727using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2828using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     29using HeuristicLab.Random;
    2930
    3031namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     
    6869          possibleChildren.Add(n);
    6970      });
    70       var selectedChild = possibleChildren.SelectRandom(random);
     71
     72      var selectedChild = possibleChildren.SampleRandom(random);
    7173      var crossoverPoints = new List<CutPoint>();
    7274      var qualities = new List<Tuple<CutPoint, double>>();
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionDepthConstrainedCrossover.cs

    r12155 r12891  
    2929using HeuristicLab.Parameters;
    3030using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     31using HeuristicLab.Random;
    3132
    3233namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     
    115116        throw new Exception("No crossover points available in the first parent");
    116117
    117       var crossoverPoint0 = crossoverPoints0.SelectRandom(random);
    118 
     118      var crossoverPoint0 = crossoverPoints0.SampleRandom(random);
    119119      int level = parent0.Root.GetBranchLevel(crossoverPoint0.Child);
    120120      int length = parent0.Root.GetLength() - crossoverPoint0.Child.GetLength();
     
    126126                             select s).ToList();
    127127      if (allowedBranches.Count == 0) return parent0;
    128       var selectedBranch = allowedBranches.SelectRandom(random);
     128
     129      var selectedBranch = allowedBranches.SampleRandom(random);
    129130      Swap(crossoverPoint0, selectedBranch);
    130131      return parent0;
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionDeterministicBestCrossover.cs

    r12155 r12891  
    2727using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2828using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     29using HeuristicLab.Random;
    2930
    3031namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     
    6768          crossoverPoints0.Add(new CutPoint(n.Parent, n));
    6869      });
    69       CutPoint crossoverPoint0 = crossoverPoints0.SelectRandom(random);
     70
     71      CutPoint crossoverPoint0 = crossoverPoints0.SampleRandom(random);
    7072      int level = parent0.Root.GetBranchLevel(crossoverPoint0.Child);
    7173      int length = parent0.Root.GetLength() - crossoverPoint0.Child.GetLength();
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionProbabilisticFunctionalCrossover.cs

    r12155 r12891  
    2727using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2828using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     29using HeuristicLab.Random;
    2930
    3031namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     
    6970        }
    7071      });
    71       var crossoverPoint0 = crossoverPoints0.SelectRandom(random);
     72
     73      var crossoverPoint0 = crossoverPoints0.SampleRandom(random);
    7274      int level = parent0.Root.GetBranchLevel(crossoverPoint0.Child);
    7375      int length = parent0.Root.GetLength() - crossoverPoint0.Child.GetLength();
     
    137139          weights[i] /= sum;
    138140
     141#pragma warning disable 612, 618
    139142        selectedBranch = allowedBranches.SelectRandom(weights, random);
     143#pragma warning restore 612, 618
    140144      }
    141145      Swap(crossoverPoint0, selectedBranch);
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionSemanticSimilarityCrossover.cs

    r12155 r12891  
    2828using HeuristicLab.Parameters;
    2929using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     30using HeuristicLab.Random;
    3031
    3132namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     
    8182          crossoverPoints0.Add(new CutPoint(n.Parent, n));
    8283      });
    83       var crossoverPoint0 = crossoverPoints0.SelectRandom(random);
     84
     85      var crossoverPoint0 = crossoverPoints0.SampleRandom(random);
    8486      int level = parent0.Root.GetBranchLevel(crossoverPoint0.Child);
    8587      int length = parent0.Root.GetLength() - crossoverPoint0.Child.GetLength();
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionExcelFormatter.cs

    r12155 r12891  
    7171    }
    7272
    73     public string Format(ISymbolicExpressionTree symbolicExpressionTree, Dataset dataset) {
     73    public string Format(ISymbolicExpressionTree symbolicExpressionTree, IDataset dataset) {
    7474      var stringBuilder = new StringBuilder();
    7575      if (dataset != null) CalculateVariableMapping(symbolicExpressionTree, dataset);
     
    8585    }
    8686
    87     private void CalculateVariableMapping(ISymbolicExpressionTree tree, Dataset dataset) {
     87    private void CalculateVariableMapping(ISymbolicExpressionTree tree, IDataset dataset) {
    8888      int columnIndex = 0;
    8989      int inputIndex = 0;
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interfaces/ISymbolicDataAnalysisExpressionTreeInterpreter.cs

    r12155 r12891  
    2727namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    2828  public interface ISymbolicDataAnalysisExpressionTreeInterpreter : INamedItem, IStatefulItem {
    29     IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, Dataset dataset, IEnumerable<int> rows);
     29    IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, IDataset dataset, IEnumerable<int> rows);
    3030    IntValue EvaluatedSolutions { get; set; }
    3131  }
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interfaces/ISymbolicDataAnalysisImpactValuesCalculator.cs

    r10459 r12891  
    66  public interface ISymbolicDataAnalysisSolutionImpactValuesCalculator : IItem {
    77    double CalculateReplacementValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows);
    8     double CalculateImpactValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows, double originalQuality = double.NaN);
     8    double CalculateImpactValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows, double qualityForImpactsCalculation = double.NaN);
    99    void CalculateImpactAndReplacementValues(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData,
    10       IEnumerable<int> rows, out double impactValue, out double replacementValue, double originalQuality = double.NaN);
     10      IEnumerable<int> rows, out double impactValue, out double replacementValue, out double newQualityForImpactsCalculation, double qualityForImpactsCalculation = double.NaN);
    1111  }
    1212}
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeILEmittingInterpreter.cs

    r12155 r12891  
    138138    #endregion
    139139
    140     public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, Dataset dataset, IEnumerable<int> rows) {
     140    public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, IDataset dataset, IEnumerable<int> rows) {
    141141      if (CheckExpressionsWithIntervalArithmetic.Value)
    142142        throw new NotSupportedException("Interval arithmetic is not yet supported in the symbolic data analysis interpreter.");
     
    161161    }
    162162
    163     private InterpreterState PrepareInterpreterState(ISymbolicExpressionTree tree, Dataset dataset) {
     163    private InterpreterState PrepareInterpreterState(ISymbolicExpressionTree tree, IDataset dataset) {
    164164      Instruction[] code = SymbolicExpressionTreeCompiler.Compile(tree, OpCodes.MapSymbolToOpCode);
    165165      Dictionary<string, int> doubleVariableNames = dataset.DoubleVariables.Select((x, i) => new { x, i }).ToDictionary(e => e.x, e => e.i);
     
    182182    }
    183183
    184     private void CompileInstructions(ILGenerator il, InterpreterState state, Dataset ds) {
     184    private void CompileInstructions(ILGenerator il, InterpreterState state, IDataset ds) {
    185185      Instruction currentInstr = state.NextInstruction();
    186186      int nArgs = currentInstr.nArguments;
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeInterpreter.cs

    r12155 r12891  
    9595    #endregion
    9696
    97     public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, Dataset dataset, IEnumerable<int> rows) {
     97    public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, IDataset dataset, IEnumerable<int> rows) {
    9898      if (CheckExpressionsWithIntervalArithmetic.Value)
    9999        throw new NotSupportedException("Interval arithmetic is not yet supported in the symbolic data analysis interpreter.");
     
    111111    }
    112112
    113     private static InterpreterState PrepareInterpreterState(ISymbolicExpressionTree tree, Dataset dataset) {
     113    private static InterpreterState PrepareInterpreterState(ISymbolicExpressionTree tree, IDataset dataset) {
    114114      Instruction[] code = SymbolicExpressionTreeCompiler.Compile(tree, OpCodes.MapSymbolToOpCode);
    115115      int necessaryArgStackSize = 0;
     
    132132
    133133
    134     public virtual double Evaluate(Dataset dataset, ref int row, InterpreterState state) {
     134    public virtual double Evaluate(IDataset dataset, ref int row, InterpreterState state) {
    135135      Instruction currentInstr = state.NextInstruction();
    136136      switch (currentInstr.opCode) {
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeLinearInterpreter.cs

    r12155 r12891  
    102102    #endregion
    103103
    104     public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, Dataset dataset, IEnumerable<int> rows) {
     104    public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, IDataset dataset, IEnumerable<int> rows) {
    105105      if (CheckExpressionsWithIntervalArithmetic.Value)
    106106        throw new NotSupportedException("Interval arithmetic is not yet supported in the symbolic data analysis interpreter.");
     
    116116
    117117    // NOTE: do not use this method when evaluating trees. this method is provided as a shortcut for evaluating subtrees ad-hoc
    118     public IEnumerable<double> GetValues(ISymbolicExpressionTreeNode node, Dataset dataset, IEnumerable<int> rows) {
     118    public IEnumerable<double> GetValues(ISymbolicExpressionTreeNode node, IDataset dataset, IEnumerable<int> rows) {
    119119      var code = SymbolicExpressionTreeLinearCompiler.Compile(node, OpCodes.MapSymbolToOpCode);
    120120      PrepareInstructions(code, dataset);
     
    122122    }
    123123
    124     private double Evaluate(Dataset dataset, int row, LinearInstruction[] code) {
     124    private double Evaluate(IDataset dataset, int row, LinearInstruction[] code) {
    125125      for (int i = code.Length - 1; i >= 0; --i) {
    126126        if (code[i].skip) continue;
     
    361361    }
    362362
    363     public static void PrepareInstructions(LinearInstruction[] code, Dataset dataset) {
     363    public static void PrepareInstructions(LinearInstruction[] code, IDataset dataset) {
    364364      for (int i = 0; i != code.Length; ++i) {
    365365        var instr = code[i];
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Plugin.cs.frame

    r12155 r12891  
    2626
    2727namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    28   [Plugin("HeuristicLab.Problems.DataAnalysis.Symbolic","Provides base classes for symbolic data analysis tasks.", "3.4.7.$WCREV$")]
     28  [Plugin("HeuristicLab.Problems.DataAnalysis.Symbolic","Provides base classes for symbolic data analysis tasks.", "3.4.8.$WCREV$")]
    2929  [PluginFile("HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.dll", PluginFileType.Assembly)]
    3030  [PluginDependency("HeuristicLab.ALGLIB", "3.7.0")]
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Properties/AssemblyInfo.cs.frame

    r12155 r12891  
    5353// by using the '*' as shown below:
    5454[assembly: AssemblyVersion("3.4.0.0")]
    55 [assembly: AssemblyFileVersion("3.4.7.$WCREV$")]
     55[assembly: AssemblyFileVersion("3.4.8.$WCREV$")]
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionPruningOperator.cs

    r12208 r12891  
    3434  [StorableClass]
    3535  [Item("SymbolicExpressionTreePruningOperator", "An operator that replaces introns with constant values in a symbolic expression tree.")]
    36   public abstract class SymbolicDataAnalysisExpressionPruningOperator : SingleSuccessorOperator {
     36  public abstract class SymbolicDataAnalysisExpressionPruningOperator : SingleSuccessorOperator, ISymbolicExpressionTreeOperator {
    3737    #region parameter names
    3838    private const string ProblemDataParameterName = "ProblemData";
     
    4141    private const string PrunedSubtreesParameterName = "PrunedSubtrees";
    4242    private const string PrunedTreesParameterName = "PrunedTrees";
     43    private const string PrunedNodesParameterName = "PrunedNodes";
    4344    private const string FitnessCalculationPartitionParameterName = "FitnessCalculationPartition";
    4445    private const string NodeImpactThresholdParameterName = "ImpactThreshold";
     
    4849    private const string EstimationLimitsParameterName = "EstimationLimits";
    4950    private const string InterpreterParameterName = "SymbolicExpressionTreeInterpreter";
     51    private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";
    5052    #endregion
    5153
     
    7274      get { return (ILookupParameter<IntValue>)Parameters[PrunedTreesParameterName]; }
    7375    }
     76    public ILookupParameter<IntValue> PrunedNodesParameter {
     77      get { return (ILookupParameter<IntValue>)Parameters[PrunedNodesParameterName]; }
     78    }
    7479    public IFixedValueParameter<DoubleValue> NodeImpactThresholdParameter {
    7580      get { return (IFixedValueParameter<DoubleValue>)Parameters[NodeImpactThresholdParameterName]; }
     
    8489      get { return (ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>)Parameters[InterpreterParameterName]; }
    8590    }
     91    public ILookupParameter<BoolValue> ApplyLinearScalingParameter {
     92      get { return (ILookupParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }
     93    }
    8694    #endregion
    8795
    8896    #region properties
    89     protected IDataAnalysisProblemData ProblemData { get { return ProblemDataParameter.ActualValue; } }
    90     protected ISymbolicDataAnalysisSolutionImpactValuesCalculator ImpactValuesCalculator { get { return ImpactValuesCalculatorParameter.Value; } }
    91     protected IntRange FitnessCalculationPartition { get { return FitnessCalculationPartitionParameter.ActualValue; } }
    92     protected bool PruneOnlyZeroImpactNodes {
     97    public ISymbolicDataAnalysisSolutionImpactValuesCalculator ImpactValuesCalculator {
     98      get { return ImpactValuesCalculatorParameter.Value; }
     99      set { ImpactValuesCalculatorParameter.Value = value; }
     100    }
     101    public bool PruneOnlyZeroImpactNodes {
    93102      get { return PruneOnlyZeroImpactNodesParameter.Value.Value; }
    94103      set { PruneOnlyZeroImpactNodesParameter.Value.Value = value; }
    95104    }
    96     protected double NodeImpactThreshold {
     105    public double NodeImpactThreshold {
    97106      get { return NodeImpactThresholdParameter.Value.Value; }
    98107      set { NodeImpactThresholdParameter.Value.Value = value; }
    99108    }
    100     protected ISymbolicExpressionTree SymbolicExpressionTree { get { return SymbolicExpressionTreeParameter.ActualValue; } }
    101     protected DoubleValue Quality { get { return QualityParameter.ActualValue; } }
    102     protected DoubleLimit EstimationLimits { get { return EstimationLimitsParameter.ActualValue; } }
    103     protected ISymbolicDataAnalysisExpressionTreeInterpreter Interpreter { get { return InterpreterParameter.ActualValue; } }
    104109    #endregion
    105110
     
    114119      Parameters.Add(new LookupParameter<ISymbolicDataAnalysisModel>(SymbolicDataAnalysisModelParameterName));
    115120      Parameters.Add(new LookupParameter<IntRange>(FitnessCalculationPartitionParameterName));
     121      Parameters.Add(new LookupParameter<IntValue>(PrunedNodesParameterName, "A counter of how many nodes were pruned."));
    116122      Parameters.Add(new LookupParameter<IntValue>(PrunedSubtreesParameterName, "A counter of how many subtrees were replaced."));
    117123      Parameters.Add(new LookupParameter<IntValue>(PrunedTreesParameterName, "A counter of how many trees were pruned."));
     
    122128      Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName));
    123129      Parameters.Add(new LookupParameter<DoubleValue>(QualityParameterName));
     130      Parameters.Add(new LookupParameter<BoolValue>(ApplyLinearScalingParameterName));
    124131      Parameters.Add(new ValueParameter<ISymbolicDataAnalysisSolutionImpactValuesCalculator>(ImpactValuesCalculatorParameterName, impactValuesCalculator));
    125132      #endregion
    126133    }
    127134
     135    [StorableHook(HookType.AfterDeserialization)]
     136    private void AfterDeserialization() {
     137      // BackwardsCompatibility3.3
     138      #region Backwards compatible code, remove with 3.4
     139      if (!Parameters.ContainsKey(PrunedNodesParameterName)) {
     140        Parameters.Add(new LookupParameter<IntValue>(PrunedNodesParameterName, "A counter of how many nodes were pruned."));
     141      }
     142      if (!Parameters.ContainsKey(ApplyLinearScalingParameterName)) {
     143        Parameters.Add(new LookupParameter<BoolValue>(ApplyLinearScalingParameterName));
     144      }
     145      if (!Parameters.ContainsKey(ImpactValuesCalculatorParameterName)) {
     146        // value must be set by derived operators (regression/classification)
     147        Parameters.Add(new ValueParameter<ISymbolicDataAnalysisSolutionImpactValuesCalculator>(ImpactValuesCalculatorParameterName));
     148      }
     149      #endregion
     150    }
     151
    128152    protected abstract ISymbolicDataAnalysisModel CreateModel(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, IDataAnalysisProblemData problemData, DoubleLimit estimationLimits);
    129153
     
    131155
    132156    public override IOperation Apply() {
    133       var model = CreateModel(SymbolicExpressionTree, Interpreter, ProblemData, EstimationLimits);
    134       var nodes = SymbolicExpressionTree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix().ToList();
    135       var rows = Enumerable.Range(FitnessCalculationPartition.Start, FitnessCalculationPartition.Size);
     157      var tree = SymbolicExpressionTreeParameter.ActualValue;
     158      var problemData = ProblemDataParameter.ActualValue;
     159      var fitnessCalculationPartition = FitnessCalculationPartitionParameter.ActualValue;
     160      var estimationLimits = EstimationLimitsParameter.ActualValue;
     161      var interpreter = InterpreterParameter.ActualValue;
     162
     163      var model = CreateModel(tree, interpreter, problemData, estimationLimits);
     164      var nodes = tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix().ToList();
     165      var rows = Enumerable.Range(fitnessCalculationPartition.Start, fitnessCalculationPartition.Size).ToList();
    136166      var prunedSubtrees = 0;
    137167      var prunedTrees = 0;
    138 
    139       double quality = Evaluate(model);
     168      var prunedNodes = 0;
     169
     170      double qualityForImpactsCalculation = double.NaN;
    140171
    141172      for (int i = 0; i < nodes.Count; ++i) {
     
    144175
    145176        double impactValue, replacementValue;
    146         ImpactValuesCalculator.CalculateImpactAndReplacementValues(model, node, ProblemData, rows, out impactValue, out replacementValue, quality);
    147 
    148         if (PruneOnlyZeroImpactNodes) {
    149           if (!impactValue.IsAlmost(0.0)) continue;
    150         } else if (NodeImpactThreshold < impactValue) {
    151           continue;
    152         }
     177        double newQualityForImpacts;
     178        ImpactValuesCalculator.CalculateImpactAndReplacementValues(model, node, problemData, rows, out impactValue, out replacementValue, out newQualityForImpacts, qualityForImpactsCalculation);
     179
     180        if (PruneOnlyZeroImpactNodes && !impactValue.IsAlmost(0.0)) continue;
     181        if (!PruneOnlyZeroImpactNodes && impactValue > NodeImpactThreshold) continue;
    153182
    154183        var constantNode = (ConstantTreeNode)node.Grammar.GetSymbol("Constant").CreateTreeNode();
    155184        constantNode.Value = replacementValue;
    156185
     186        var length = node.GetLength();
    157187        ReplaceWithConstant(node, constantNode);
    158         i += node.GetLength() - 1; // skip subtrees under the node that was folded
    159 
    160         quality -= impactValue;
     188        i += length - 1; // skip subtrees under the node that was folded
    161189
    162190        prunedSubtrees++;
     191        prunedNodes += length;
     192
     193        qualityForImpactsCalculation = newQualityForImpacts;
    163194      }
    164195
     
    166197      PrunedSubtreesParameter.ActualValue = new IntValue(prunedSubtrees);
    167198      PrunedTreesParameter.ActualValue = new IntValue(prunedTrees);
     199      PrunedNodesParameter.ActualValue = new IntValue(prunedNodes);
     200
     201      if (prunedSubtrees > 0) // if nothing was pruned then there's no need to re-evaluate the tree
     202        QualityParameter.ActualValue.Value = Evaluate(model);
    168203
    169204      return base.Apply();
    170     }
    171 
    172     public ISymbolicExpressionTree Prune(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, IDataAnalysisProblemData problemData, DoubleLimit estimationLimits) {
    173       var model = CreateModel((ISymbolicExpressionTree)tree.Clone(), Interpreter, ProblemData, EstimationLimits);
    174       var nodes = SymbolicExpressionTree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix().ToList();
    175       var rows = Enumerable.Range(FitnessCalculationPartition.Start, FitnessCalculationPartition.Size);
    176 
    177       double quality = Evaluate(model);
    178 
    179       for (int i = 0; i < nodes.Count; ++i) {
    180         var node = nodes[i];
    181         if (node is ConstantTreeNode) continue;
    182 
    183         double impactValue, replacementValue;
    184         ImpactValuesCalculator.CalculateImpactAndReplacementValues(model, node, ProblemData, rows, out impactValue, out replacementValue, quality);
    185 
    186         if (PruneOnlyZeroImpactNodes) {
    187           if (!impactValue.IsAlmost(0.0)) continue;
    188         } else if (NodeImpactThreshold < impactValue) {
    189           continue;
    190         }
    191 
    192         var constantNode = (ConstantTreeNode)node.Grammar.GetSymbol("Constant").CreateTreeNode();
    193         constantNode.Value = replacementValue;
    194 
    195         ReplaceWithConstant(node, constantNode);
    196         i += node.GetLength() - 1; // skip subtrees under the node that was folded
    197 
    198         quality -= impactValue;
    199       }
    200       return model.SymbolicExpressionTree;
    201205    }
    202206
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeSimplifier.cs

    r12155 r12891  
    287287        // make sum(x0..xn) / n
    288288        var sum = original.Subtrees
    289           .Select(x => GetSimplifiedTree(x))
    290           .Aggregate((a, b) => MakeSum(a, b));
     289          .Select(GetSimplifiedTree)
     290          .Aggregate(MakeSum);
    291291        return MakeFraction(sum, MakeConstant(original.Subtrees.Count()));
    292292      }
     
    299299        // simplify expressions x0..xn
    300300        // make multiplication (x0 * 1/(x1 * x1 * .. * xn))
    301         var simplifiedTrees = original.Subtrees.Select(x => GetSimplifiedTree(x));
     301        var first = original.GetSubtree(0);
     302        var second = original.GetSubtree(1);
     303        var remaining = original.Subtrees.Skip(2);
    302304        return
    303           MakeProduct(simplifiedTrees.First(), Invert(simplifiedTrees.Skip(1).Aggregate((a, b) => MakeProduct(a, b))));
     305          MakeProduct(GetSimplifiedTree(first), Invert(remaining.Aggregate(GetSimplifiedTree(second), (a, b) => MakeProduct(a, GetSimplifiedTree(b)))));
    304306      }
    305307    }
     
    310312      } else {
    311313        return original.Subtrees
    312           .Select(x => GetSimplifiedTree(x))
    313           .Aggregate((a, b) => MakeProduct(a, b));
     314          .Select(GetSimplifiedTree)
     315          .Aggregate(MakeProduct);
    314316      }
    315317    }
     
    321323        // simplify expressions x0..xn
    322324        // make addition (x0,-x1..-xn)
    323         var simplifiedTrees = original.Subtrees.Select(x => GetSimplifiedTree(x));
    324         return simplifiedTrees.Take(1)
    325           .Concat(simplifiedTrees.Skip(1).Select(x => Negate(x)))
    326           .Aggregate((a, b) => MakeSum(a, b));
     325        var first = original.Subtrees.First();
     326        var remaining = original.Subtrees.Skip(1);
     327        return remaining.Aggregate(GetSimplifiedTree(first), (a, b) => MakeSum(a, Negate(GetSimplifiedTree(b))));
    327328      }
    328329    }
     
    335336        // make addition (x0..xn)
    336337        return original.Subtrees
    337           .Select(x => GetSimplifiedTree(x))
    338           .Aggregate((a, b) => MakeSum(a, b));
     338          .Select(GetSimplifiedTree)
     339          .Aggregate(MakeSum);
    339340      }
    340341    }
     
    345346    private ISymbolicExpressionTreeNode SimplifyOr(ISymbolicExpressionTreeNode original) {
    346347      return original.Subtrees
    347         .Select(x => GetSimplifiedTree(x))
    348         .Aggregate((a, b) => MakeOr(a, b));
     348        .Select(GetSimplifiedTree)
     349        .Aggregate(MakeOr);
    349350    }
    350351    private ISymbolicExpressionTreeNode SimplifyAnd(ISymbolicExpressionTreeNode original) {
    351352      return original.Subtrees
    352         .Select(x => GetSimplifiedTree(x))
    353         .Aggregate((a, b) => MakeAnd(a, b));
     353        .Select(GetSimplifiedTree)
     354        .Aggregate(MakeAnd);
    354355    }
    355356    private ISymbolicExpressionTreeNode SimplifyLessThan(ISymbolicExpressionTreeNode original) {
     
    831832    private void MergeVariablesInSum(ISymbolicExpressionTreeNode sum) {
    832833      var subtrees = new List<ISymbolicExpressionTreeNode>(sum.Subtrees);
    833       while (sum.Subtrees.Count() > 0) sum.RemoveSubtree(0);
     834      while (sum.Subtrees.Any()) sum.RemoveSubtree(0);
    834835      var groupedVarNodes = from node in subtrees.OfType<VariableTreeNode>()
    835836                            let lag = (node is LaggedVariableTreeNode) ? ((LaggedVariableTreeNode)node).Lag : 0
     
    949950    private void MergeVariablesAndConstantsInProduct(ISymbolicExpressionTreeNode prod) {
    950951      var subtrees = new List<ISymbolicExpressionTreeNode>(prod.Subtrees);
    951       while (prod.Subtrees.Count() > 0) prod.RemoveSubtree(0);
     952      while (prod.Subtrees.Any()) prod.RemoveSubtree(0);
    952953      var groupedVarNodes = from node in subtrees.OfType<VariableTreeNode>()
    953954                            let lag = (node is LaggedVariableTreeNode) ? ((LaggedVariableTreeNode)node).Lag : 0
     
    10041005      } else if (IsAddition(x)) {
    10051006        // (x0 + x1 + .. + xn) * -1 => (-x0 + -x1 + .. + -xn)       
    1006         List<ISymbolicExpressionTreeNode> subtrees = new List<ISymbolicExpressionTreeNode>(x.Subtrees);
    1007         while (x.Subtrees.Count() > 0) x.RemoveSubtree(0);
     1007        var subtrees = new List<ISymbolicExpressionTreeNode>(x.Subtrees);
     1008        while (x.Subtrees.Any()) x.RemoveSubtree(0);
    10081009        foreach (var subtree in subtrees) {
    10091010          x.AddSubtree(Negate(subtree));
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisProblem.cs

    r12155 r12891  
    300300
    301301    protected virtual void ParameterizeOperators() {
    302       var operators = Parameters.OfType<IValueParameter>().Select(p => p.Value).OfType<IOperator>().Union(Operators).ToList();
     302      var operators =
     303        Parameters.OfType<IValueParameter>().Select(p => p.Value).OfType<IOperator>().Union(Operators).ToList();
    303304
    304305      foreach (var op in operators.OfType<ISymbolicExpressionTreeGrammarBasedOperator>()) {
     
    322323      foreach (var op in operators.OfType<ISymbolicExpressionTreeCrossover>()) {
    323324        op.ParentsParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    324         op.ChildParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
     325        op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    325326      }
    326327      foreach (var op in operators.OfType<ISymbolicExpressionTreeManipulator>()) {
     
    357358        op.BeforeCrossoverOperatorParameter.ActualValue = new SymbolicDataAnalysisExpressionBeforeCrossoverOperator();
    358359        op.AfterCrossoverOperatorParameter.ActualValue = new SymbolicDataAnalysisExpressionAfterCrossoverOperator();
    359         op.BeforeManipulatorOperatorParameter.ActualValue = new SymbolicDataAnalysisExpressionBeforeManipulatorOperator();
     360        op.BeforeManipulatorOperatorParameter.ActualValue =
     361          new SymbolicDataAnalysisExpressionBeforeManipulatorOperator();
    360362        op.AfterManipulatorOperatorParameter.ActualValue = new SymbolicDataAnalysisExpressionAfterManipulatorOperator();
    361363        // get crossover parameter names
     
    364366          op.BeforeCrossoverOperator.ParentsParameter.ActualName = crossover.ParentsParameter.Name;
    365367          op.AfterCrossoverOperator.ParentsParameter.ActualName = crossover.ParentsParameter.Name;
    366           op.BeforeCrossoverOperator.ChildParameter.ActualName = crossover.ChildParameter.Name;
    367           op.AfterCrossoverOperator.ChildParameter.ActualName = crossover.ChildParameter.Name;
    368         }
    369         // get manipulator parameter names
    370         var manipulator = operators.OfType<ISymbolicExpressionTreeManipulator>().FirstOrDefault();
    371         if (manipulator != null) {
    372           op.BeforeManipulatorOperator.ChildParameter.ActualName = manipulator.SymbolicExpressionTreeParameter.Name;
    373           op.AfterManipulatorOperator.ChildParameter.ActualName = manipulator.SymbolicExpressionTreeParameter.Name;
    374         }
    375         var creator = operators.OfType<ISymbolicExpressionTreeCreator>().FirstOrDefault();
    376         if (creator != null) {
    377           op.PopulationParameter.ActualName = creator.SymbolicExpressionTreeParameter.ActualName;
     368          op.BeforeCrossoverOperator.ChildParameter.ActualName = crossover.SymbolicExpressionTreeParameter.Name;
     369          op.AfterCrossoverOperator.ChildParameter.ActualName = crossover.SymbolicExpressionTreeParameter.Name;
     370          // get manipulator parameter names
     371          var manipulator = operators.OfType<ISymbolicExpressionTreeManipulator>().FirstOrDefault();
     372          if (manipulator != null) {
     373            op.BeforeManipulatorOperator.ChildParameter.ActualName = manipulator.SymbolicExpressionTreeParameter.Name;
     374            op.AfterManipulatorOperator.ChildParameter.ActualName = manipulator.SymbolicExpressionTreeParameter.Name;
     375          }
     376          var creator = operators.OfType<ISymbolicExpressionTreeCreator>().FirstOrDefault();
     377          if (creator != null) {
     378            op.PopulationParameter.ActualName = creator.SymbolicExpressionTreeParameter.ActualName;
     379          }
    378380        }
    379381      }
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisSolutionImpactValuesCalculator.cs

    r12155 r12891  
    3737    protected SymbolicDataAnalysisSolutionImpactValuesCalculator(bool deserializing) : base(deserializing) { }
    3838    public abstract double CalculateReplacementValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows);
    39     public abstract double CalculateImpactValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows, double originalQuality = double.NaN);
    40     public abstract void CalculateImpactAndReplacementValues(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows, out double impactValue, out double replacementValue, double originalQuality = double.NaN);
     39    public abstract double CalculateImpactValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows, double qualityForImpactsCalculation = double.NaN);
     40    public abstract void CalculateImpactAndReplacementValues(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows, out double impactValue, out double replacementValue, out double newQualityForImpactsCalculation, double qualityForImpactsCalculation = double.NaN);
    4141
    4242    protected static double CalculateReplacementValue(ISymbolicExpressionTreeNode node, ISymbolicExpressionTree sourceTree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
    43       Dataset dataset, IEnumerable<int> rows) {
     43      IDataset dataset, IEnumerable<int> rows) {
    4444      //optimization: constant nodes return always the same value
    4545      ConstantTreeNode constantNode = node as ConstantTreeNode;
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/VariableConditionTreeNode.cs

    r12155 r12891  
    7474      base.ResetLocalParameters(random);
    7575      threshold = NormalDistributedRandom.NextDouble(random, Symbol.ThresholdInitializerMu, Symbol.ThresholdInitializerSigma);
     76
     77#pragma warning disable 612, 618
    7678      variableName = Symbol.VariableNames.SelectRandom(random);
     79#pragma warning restore 612, 618
     80
    7781      slope = NormalDistributedRandom.NextDouble(random, Symbol.SlopeInitializerMu, Symbol.SlopeInitializerSigma);
    7882    }
     
    8286      double x = NormalDistributedRandom.NextDouble(random, Symbol.ThresholdManipulatorMu, Symbol.ThresholdManipulatorSigma);
    8387      threshold = threshold + x * shakingFactor;
     88
     89#pragma warning disable 612, 618
    8490      variableName = Symbol.VariableNames.SelectRandom(random);
     91#pragma warning restore 612, 618
     92
    8593      x = NormalDistributedRandom.NextDouble(random, Symbol.SlopeManipulatorMu, Symbol.SlopeManipulatorSigma);
    8694      slope = slope + x * shakingFactor;
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/VariableTreeNode.cs

    r12155 r12891  
    6161      base.ResetLocalParameters(random);
    6262      weight = NormalDistributedRandom.NextDouble(random, Symbol.WeightMu, Symbol.WeightSigma);
     63
     64#pragma warning disable 612, 618
    6365      variableName = Symbol.VariableNames.SelectRandom(random);
     66#pragma warning restore 612, 618
    6467    }
    6568
     
    7073        double x = NormalDistributedRandom.NextDouble(random, Symbol.WeightManipulatorMu, Symbol.WeightManipulatorSigma);
    7174        weight = weight + x * shakingFactor;
    72       } else {       
     75      } else {
    7376        double x = NormalDistributedRandom.NextDouble(random, 1.0, Symbol.MultiplicativeWeightManipulatorSigma);
    7477        weight = weight * x;
    7578      }
     79#pragma warning disable 612, 618
    7680      variableName = Symbol.VariableNames.SelectRandom(random);
     81#pragma warning restore 612, 618
    7782    }
    7883
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreeBottomUpSimilarityCalculator.cs

    r12287 r12891  
    11#region License Information
     2
    23/* HeuristicLab
    34 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     
    1819 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
    1920 */
    20 #endregion
     21
     22#endregion License Information
    2123
    2224using System;
     
    3234
    3335namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     36
    3437  [StorableClass]
    3538  [Item("SymbolicExpressionTreeBottomUpSimilarityCalculator", "A similarity calculator which uses the tree bottom-up distance as a similarity metric.")]
     
    3740    private readonly HashSet<string> commutativeSymbols = new HashSet<string> { "Addition", "Multiplication", "Average", "And", "Or", "Xor" };
    3841
    39     public SymbolicExpressionTreeBottomUpSimilarityCalculator() { }
     42    public SymbolicExpressionTreeBottomUpSimilarityCalculator() {
     43    }
     44
    4045    protected override bool IsCommutative { get { return true; } }
    4146
     
    107112
    108113        // at this point we know that v and w are isomorphic, however, the mapping cannot be done directly
    109         // (as in the paper) because the trees are unordered (subtree order might differ). the solution is 
     114        // (as in the paper) because the trees are unordered (subtree order might differ). the solution is
    110115        // to sort subtrees from under commutative labels (this will work because the subtrees are isomorphic!)
    111116        // while iterating over the two subtrees
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreeNodeComparer.cs

    r12155 r12891  
    1818 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
    1919 */
    20 #endregion
     20#endregion License Information
    2121
    2222using System;
     
    2929  // - used for bringing subtrees to a "canonical" form when the operation allows reordering of arguments
    3030  public class SymbolicExpressionTreeNodeComparer : ISymbolicExpressionTreeNodeComparer {
     31
    3132    public static int CompareNodes(ISymbolicExpressionTreeNode a, ISymbolicExpressionTreeNode b) {
    3233      var ta = a as SymbolicExpressionTreeTerminalNode;
     
    6970    }
    7071  }
    71 
    7272}
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreePhenotypicSimilarityCalculator.cs

    r12155 r12891  
    6565
    6666      OnlineCalculatorError error;
    67       var r2 = OnlinePearsonsRSquaredCalculator.Calculate(v1, v2, out error);
     67      var r = OnlinePearsonsRCalculator.Calculate(v1, v2, out error);
     68
     69      var r2 = error == OnlineCalculatorError.None ? r * r : 0;
    6870
    6971      if (r2 > 1.0)
    7072        r2 = 1.0;
    7173
    72       return error == OnlineCalculatorError.None ? r2 : 0;
     74      return r2;
    7375    }
    7476
     
    8789
    8890      OnlineCalculatorError error;
    89       var r2 = OnlinePearsonsRSquaredCalculator.Calculate(leftValues, rightValues, out error);
     91      var r = OnlinePearsonsRCalculator.Calculate(leftValues, rightValues, out error);
     92
     93      var r2 = error == OnlineCalculatorError.None ? r * r : 0;
    9094
    9195      if (r2 > 1.0)
    92         r2 = 1.0; // sometimes due to fp errors it can happen that the r2 is over 1 (like 1.0000000009)
     96        r2 = 1.0;
    9397
    94       return error == OnlineCalculatorError.None ? r2 : 0;
     98      return r2;
    9599    }
    96100  }
Note: See TracChangeset for help on using the changeset viewer.