Free cookie consent management tool by TermsFeed Policy Generator

Changeset 9241


Ignore:
Timestamp:
02/21/13 16:55:07 (11 years ago)
Author:
bburlacu
Message:

#1772: Merged trunk changes for HeuristicLab.Problems.DataAnalysis.Symbolic. Added SymbolicDataAnalysisSolutionTextRenderer, a class for displaying symbolic expression trees in the console.

Location:
branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic
Files:
1 added
2 deleted
40 edited
4 copied

Legend:

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

  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4

    • Property svn:ignore
      •  

        old new  
         1*.user
         2Plugin.cs
        13bin
        2 *.user
        3 HeuristicLabProblemsDataAnalysisSymbolicPlugin.cs
        44obj
        5 *.vs10x
        6 Plugin.cs
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisMultiObjectiveAnalyzer.cs

    r7259 r9241  
    2020#endregion
    2121
    22 using System.Collections.Generic;
    23 using System.Linq;
    2422using HeuristicLab.Common;
    2523using HeuristicLab.Core;
    2624using HeuristicLab.Data;
    27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    28 using HeuristicLab.Operators;
    2925using HeuristicLab.Parameters;
    3026using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    31 using HeuristicLab.Optimization;
    3227
    3328namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     
    3934    private const string QualitiesParameterName = "Qualities";
    4035    private const string MaximizationParameterName = "Maximization";
     36    private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";
    4137    #region parameter properties
    4238    public IScopeTreeLookupParameter<DoubleArray> QualitiesParameter {
     
    4541    public ILookupParameter<BoolArray> MaximizationParameter {
    4642      get { return (ILookupParameter<BoolArray>)Parameters[MaximizationParameterName]; }
     43    }
     44    public ILookupParameter<BoolValue> ApplyLinearScalingParameter {
     45      get { return (ILookupParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }
    4746    }
    4847    #endregion
     
    6463      Parameters.Add(new ScopeTreeLookupParameter<DoubleArray>(QualitiesParameterName, "The qualities of the trees that should be analyzed."));
    6564      Parameters.Add(new LookupParameter<BoolArray>(MaximizationParameterName, "The directions of optimization for each dimension."));
     65      Parameters.Add(new LookupParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the individual should be linearly scaled before evaluating."));
     66    }
     67
     68    [StorableHook(HookType.AfterDeserialization)]
     69    private void AfterDeserialization() {
     70      if (Parameters.ContainsKey(ApplyLinearScalingParameterName) && Parameters[ApplyLinearScalingParameterName] is LookupParameter<BoolValue>)
     71        Parameters.Remove(ApplyLinearScalingParameterName);
     72      if (!Parameters.ContainsKey(ApplyLinearScalingParameterName))
     73        Parameters.Add(new LookupParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the individual should be linearly scaled before evaluating."));
    6674    }
    6775  }
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisMultiObjectiveTrainingBestSolutionAnalyzer.cs

    r7259 r9241  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.Linq;
     
    2627using HeuristicLab.Data;
    2728using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    28 using HeuristicLab.Operators;
    2929using HeuristicLab.Optimization;
    3030using HeuristicLab.Parameters;
    3131using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    32 using System;
    3332
    3433namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     
    4241    private const string TrainingBestSolutionsParameterName = "Best training solutions";
    4342    private const string TrainingBestSolutionQualitiesParameterName = "Best training solution qualities";
     43    private const string UpdateAlwaysParameterName = "Always update best solutions";
    4444
    4545    #region parameter properties
     
    4949    public ILookupParameter<ItemList<DoubleArray>> TrainingBestSolutionQualitiesParameter {
    5050      get { return (ILookupParameter<ItemList<DoubleArray>>)Parameters[TrainingBestSolutionQualitiesParameterName]; }
     51    }
     52    public IFixedValueParameter<BoolValue> UpdateAlwaysParameter {
     53      get { return (IFixedValueParameter<BoolValue>)Parameters[UpdateAlwaysParameterName]; }
    5154    }
    5255    #endregion
     
    6063      set { TrainingBestSolutionQualitiesParameter.ActualValue = value; }
    6164    }
     65    public BoolValue UpdateAlways {
     66      get { return UpdateAlwaysParameter.Value; }
     67    }
    6268    #endregion
    6369
     
    6975      Parameters.Add(new LookupParameter<ItemList<T>>(TrainingBestSolutionsParameterName, "The training best (Pareto-optimal) symbolic data analysis solutions."));
    7076      Parameters.Add(new LookupParameter<ItemList<DoubleArray>>(TrainingBestSolutionQualitiesParameterName, "The qualities of the training best (Pareto-optimal) solutions."));
     77      Parameters.Add(new FixedValueParameter<BoolValue>(UpdateAlwaysParameterName, "Determines if the best training solutions should always be updated regardless of its quality.", new BoolValue(false)));
     78      UpdateAlwaysParameter.Hidden = true;
     79    }
     80
     81    [StorableHook(HookType.AfterDeserialization)]
     82    private void AfterDeserialization() {
     83      if (!Parameters.ContainsKey(UpdateAlwaysParameterName)) {
     84        Parameters.Add(new FixedValueParameter<BoolValue>(UpdateAlwaysParameterName, "Determines if the best training solutions should always be updated regardless of its quality.", new BoolValue(false)));
     85        UpdateAlwaysParameter.Hidden = true;
     86      }
    7187    }
    7288
     
    8197      }
    8298
    83       IList<double[]> trainingBestQualities = TrainingBestSolutionQualities
    84         .Select(x => x.ToArray())
    85         .ToList();
     99      //if the pareto front of best solutions shall be updated regardless of the quality, the list initialized empty to discard old solutions
     100      IList<double[]> trainingBestQualities;
     101      if (UpdateAlways.Value) {
     102        trainingBestQualities = new List<double[]>();
     103      } else {
     104        trainingBestQualities = TrainingBestSolutionQualities.Select(x => x.ToArray()).ToList();
     105      }
    86106
    87107      #region find best trees
     
    131151      public bool Equals(double[] x, double[] y) {
    132152        if (y.Length != x.Length) throw new ArgumentException();
    133         for (int i = 0; i < x.Length;i++ ) {
     153        for (int i = 0; i < x.Length; i++) {
    134154          if (!x[i].IsAlmost(y[i])) return false;
    135155        }
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisMultiObjectiveValidationBestSolutionAnalyzer.cs

    r7259 r9241  
    4444    private const string ValidationBestSolutionsParameterName = "Best validation solutions";
    4545    private const string ValidationBestSolutionQualitiesParameterName = "Best validation solution qualities";
     46    private const string UpdateAlwaysParameterName = "Always update best solutions";
    4647
    4748    #region parameter properties
     
    5152    public ILookupParameter<ItemList<DoubleArray>> ValidationBestSolutionQualitiesParameter {
    5253      get { return (ILookupParameter<ItemList<DoubleArray>>)Parameters[ValidationBestSolutionQualitiesParameterName]; }
     54    }
     55    public IFixedValueParameter<BoolValue> UpdateAlwaysParameter {
     56      get { return (IFixedValueParameter<BoolValue>)Parameters[UpdateAlwaysParameterName]; }
    5357    }
    5458    #endregion
     
    6266      set { ValidationBestSolutionQualitiesParameter.ActualValue = value; }
    6367    }
     68    public BoolValue UpdateAlways {
     69      get { return UpdateAlwaysParameter.Value; }
     70    }
    6471    #endregion
    6572
     
    7178      Parameters.Add(new LookupParameter<ItemList<S>>(ValidationBestSolutionsParameterName, "The validation best (Pareto-optimal) symbolic data analysis solutions."));
    7279      Parameters.Add(new LookupParameter<ItemList<DoubleArray>>(ValidationBestSolutionQualitiesParameterName, "The qualities of the validation best (Pareto-optimal) solutions."));
     80      Parameters.Add(new FixedValueParameter<BoolValue>(UpdateAlwaysParameterName, "Determines if the best validation solutions should always be updated regardless of its quality.", new BoolValue(false)));
     81      UpdateAlwaysParameter.Hidden = true;
     82    }
     83
     84    [StorableHook(HookType.AfterDeserialization)]
     85    private void AfterDeserialization() {
     86      if (!Parameters.ContainsKey(UpdateAlwaysParameterName)) {
     87        Parameters.Add(new FixedValueParameter<BoolValue>(UpdateAlwaysParameterName, "Determines if the best training solutions should always be updated regardless of its quality.", new BoolValue(false)));
     88        UpdateAlwaysParameter.Hidden = true;
     89      }
    7390    }
    7491
     
    86103      }
    87104
    88       IList<double[]> trainingBestQualities = ValidationBestSolutionQualities
    89         .Select(x => x.ToArray())
    90         .ToList();
     105      //if the pareto front of best solutions shall be updated regardless of the quality, the list initialized empty to discard old solutions
     106      IList<double[]> trainingBestQualities;
     107      if (UpdateAlways.Value) {
     108        trainingBestQualities = new List<double[]>();
     109      } else {
     110        trainingBestQualities = ValidationBestSolutionQualities.Select(x => x.ToArray()).ToList();
     111      }
    91112
    92113      #region find best trees
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisSingleObjectiveAnalyzer.cs

    r7259 r9241  
    2020#endregion
    2121
    22 using System.Collections.Generic;
    23 using System.Linq;
    2422using HeuristicLab.Common;
    2523using HeuristicLab.Core;
    2624using HeuristicLab.Data;
    27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    28 using HeuristicLab.Operators;
    2925using HeuristicLab.Parameters;
    3026using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    31 using HeuristicLab.Optimization;
    3227
    3328namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     
    3934    private const string QualityParameterName = "Quality";
    4035    private const string MaximizationParameterName = "Maximization";
     36    private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";
     37
    4138    #region parameter properties
    4239    public IScopeTreeLookupParameter<DoubleValue> QualityParameter {
     
    4542    public ILookupParameter<BoolValue> MaximizationParameter {
    4643      get { return (ILookupParameter<BoolValue>)Parameters[MaximizationParameterName]; }
     44    }
     45    public ILookupParameter<BoolValue> ApplyLinearScalingParameter {
     46      get { return (ILookupParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }
    4747    }
    4848    #endregion
     
    6464      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>(QualityParameterName, "The qualities of the trees that should be analyzed."));
    6565      Parameters.Add(new LookupParameter<BoolValue>(MaximizationParameterName, "The direction of optimization."));
     66      Parameters.Add(new LookupParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the individual should be linearly scaled before evaluating."));
     67    }
     68
     69    [StorableHook(HookType.AfterDeserialization)]
     70    private void AfterDeserialization() {
     71      if (Parameters.ContainsKey(ApplyLinearScalingParameterName) && !(Parameters[ApplyLinearScalingParameterName] is LookupParameter<BoolValue>))
     72        Parameters.Remove(ApplyLinearScalingParameterName);
     73      if (!Parameters.ContainsKey(ApplyLinearScalingParameterName))
     74        Parameters.Add(new LookupParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the individual should be linearly scaled before evaluating."));
    6675    }
    6776  }
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisSingleObjectiveTrainingBestSolutionAnalyzer.cs

    r7259 r9241  
    2020#endregion
    2121
    22 using System.Collections.Generic;
    2322using System.Linq;
    2423using HeuristicLab.Common;
     
    2625using HeuristicLab.Data;
    2726using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    28 using HeuristicLab.Operators;
    2927using HeuristicLab.Optimization;
    3028using HeuristicLab.Parameters;
     
    4139    private const string TrainingBestSolutionParameterName = "Best training solution";
    4240    private const string TrainingBestSolutionQualityParameterName = "Best training solution quality";
     41    private const string UpdateAlwaysParameterName = "Always update best solution";
    4342
    4443    #region parameter properties
     
    4847    public ILookupParameter<DoubleValue> TrainingBestSolutionQualityParameter {
    4948      get { return (ILookupParameter<DoubleValue>)Parameters[TrainingBestSolutionQualityParameterName]; }
     49    }
     50    public IFixedValueParameter<BoolValue> UpdateAlwaysParameter {
     51      get { return (IFixedValueParameter<BoolValue>)Parameters[UpdateAlwaysParameterName]; }
    5052    }
    5153    #endregion
     
    5961      set { TrainingBestSolutionQualityParameter.ActualValue = value; }
    6062    }
     63    public BoolValue UpdateAlways {
     64      get { return UpdateAlwaysParameter.Value; }
     65    }
    6166    #endregion
    6267
     
    6873      Parameters.Add(new LookupParameter<T>(TrainingBestSolutionParameterName, "The training best symbolic data analyis solution."));
    6974      Parameters.Add(new LookupParameter<DoubleValue>(TrainingBestSolutionQualityParameterName, "The quality of the training best symbolic data analysis solution."));
     75      Parameters.Add(new FixedValueParameter<BoolValue>(UpdateAlwaysParameterName, "Determines if the best training solution should always be updated regardless of its quality.", new BoolValue(false)));
     76      UpdateAlwaysParameter.Hidden = true;
     77    }
     78
     79    [StorableHook(HookType.AfterDeserialization)]
     80    private void AfterDeserialization() {
     81      if (!Parameters.ContainsKey(UpdateAlwaysParameterName)) {
     82        Parameters.Add(new FixedValueParameter<BoolValue>(UpdateAlwaysParameterName, "Determines if the best training solution should always be updated regardless of its quality.", new BoolValue(false)));
     83        UpdateAlwaysParameter.Hidden = true;
     84      }
    7085    }
    7186
     
    85100
    86101      var results = ResultCollection;
    87       if (TrainingBestSolutionQuality == null ||
    88         IsBetter(bestQuality, TrainingBestSolutionQuality.Value, Maximization.Value)) {
     102      if (bestTree != null && (UpdateAlways.Value || TrainingBestSolutionQuality == null ||
     103        IsBetter(bestQuality, TrainingBestSolutionQuality.Value, Maximization.Value))) {
    89104        TrainingBestSolution = CreateSolution(bestTree, bestQuality);
    90105        TrainingBestSolutionQuality = new DoubleValue(bestQuality);
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisSingleObjectiveValidationAnalyzer.cs

    r7721 r9241  
    7676      : base(original, cloner) {
    7777    }
    78     public SymbolicDataAnalysisSingleObjectiveValidationAnalyzer()
    79       : base() {
     78
     79    protected SymbolicDataAnalysisSingleObjectiveValidationAnalyzer(): base() {
    8080      Parameters.Add(new LookupParameter<IRandom>(RandomParameterName, "The random generator."));
    8181      Parameters.Add(new LookupParameter<U>(ProblemDataParameterName, "The problem data of the symbolic data analysis problem."));
    8282      Parameters.Add(new LookupParameter<T>(EvaluatorParameterName, "The operator to use for fitness evaluation on the validation partition."));
    8383      Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The interpreter for symbolic data analysis expression trees."));
    84       Parameters.Add(new ValueLookupParameter<IntRange>(ValidationPartitionParameterName, "Thes validation partition."));
     84      Parameters.Add(new ValueLookupParameter<IntRange>(ValidationPartitionParameterName, "The validation partition."));
    8585      Parameters.Add(new ValueLookupParameter<PercentValue>(RelativeNumberOfEvaluatedSamplesParameterName, "The relative number of samples of the dataset partition, which should be randomly chosen for evaluation between the start and end index."));
    8686      Parameters.Add(new ValueLookupParameter<PercentValue>(PercentageOfBestSolutionsParameterName,
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisSingleObjectiveValidationBestSolutionAnalyzer.cs

    r7721 r9241  
    4343    private const string ValidationBestSolutionParameterName = "Best validation solution";
    4444    private const string ValidationBestSolutionQualityParameterName = "Best validation solution quality";
     45    private const string UpdateAlwaysParameterName = "Always update best solution";
    4546
    4647    #region parameter properties
     
    5051    public ILookupParameter<DoubleValue> ValidationBestSolutionQualityParameter {
    5152      get { return (ILookupParameter<DoubleValue>)Parameters[ValidationBestSolutionQualityParameterName]; }
     53    }
     54    public IFixedValueParameter<BoolValue> UpdateAlwaysParameter {
     55      get { return (IFixedValueParameter<BoolValue>)Parameters[UpdateAlwaysParameterName]; }
    5256    }
    5357    #endregion
     
    6165      set { ValidationBestSolutionQualityParameter.ActualValue = value; }
    6266    }
     67    public BoolValue UpdateAlways {
     68      get { return UpdateAlwaysParameter.Value; }
     69    }
    6370    #endregion
    6471
     
    7077      Parameters.Add(new LookupParameter<S>(ValidationBestSolutionParameterName, "The validation best symbolic data analyis solution."));
    7178      Parameters.Add(new LookupParameter<DoubleValue>(ValidationBestSolutionQualityParameterName, "The quality of the validation best symbolic data analysis solution."));
     79      Parameters.Add(new FixedValueParameter<BoolValue>(UpdateAlwaysParameterName, "Determines if the best validation solution should always be updated regardless of its quality.", new BoolValue(false)));
     80      UpdateAlwaysParameter.Hidden = true;
     81    }
     82
     83    [StorableHook(HookType.AfterDeserialization)]
     84    private void AfterDeserialization() {
     85      if (!Parameters.ContainsKey(UpdateAlwaysParameterName)) {
     86        Parameters.Add(new FixedValueParameter<BoolValue>(UpdateAlwaysParameterName, "Determines if the best training solution should always be updated regardless of its quality.", new BoolValue(false)));
     87        UpdateAlwaysParameter.Hidden = true;
     88      }
    7289    }
    7390
     
    117134
    118135      var results = ResultCollection;
    119       if (ValidationBestSolutionQuality == null ||
     136      if (UpdateAlways.Value || ValidationBestSolutionQuality == null ||
    120137        IsBetter(bestValidationQuality, ValidationBestSolutionQuality.Value, Maximization.Value)) {
    121138        ValidationBestSolution = CreateSolution(bestTree, bestValidationQuality);
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisVariableFrequencyAnalyzer.cs

    r7259 r9241  
    109109      // update variable impacts matrix
    110110      var orderedImpacts = (from row in datatable.Rows
    111                             select new { Name = row.Name, Impact = datatable.Rows[row.Name].Values.Average() })
     111                            select new { Name = row.Name, Impact = Math.Round(datatable.Rows[row.Name].Values.Average(), 3) })
    112112                           .OrderByDescending(p => p.Impact)
    113113                           .ToList();
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/MultiSymbolicDataAnalysisExpressionCrossover.cs

    r7521 r9241  
    3535namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    3636  [Item("MultiSymbolicDataAnalysisExpressionCrossover", "Randomly selects and applies one of its crossovers every time it is called.")]
    37   public class MultiSymbolicDataAnalysisExpressionCrossover<T> : StochasticMultiBranch<ISymbolicExpressionTreeCrossover>,
     37  public class MultiSymbolicDataAnalysisExpressionCrossover<T> : StochasticMultiBranch<ISymbolicExpressionTreeCrossover>, ITracingSymbolicExpressionTreeOperator,
    3838    ISymbolicDataAnalysisExpressionCrossover<T> where T : class, IDataAnalysisProblemData {
    3939    private const string ParentsParameterName = "Parents";
     
    4646    private const string RelativeNumberOfEvaluatedSamplesParameterName = "RelativeNumberOfEvaluatedSamples";
    4747    private const string ProblemDataParameterName = "ProblemData";
     48
     49    private const string SymbolicExpressionTreeNodeComparerParameterName = "SymbolicExpressionTreeNodeComparer";
     50    private const string SymbolicExpressionTreeNodeComparerParameterDescription = "The comparison operator used to check if two symbolic expression tree nodes are equal or similar.";
    4851
    4952    protected override bool CreateChildOperation {
     
    8386      get { return (IValueLookupParameter<T>)Parameters[ProblemDataParameterName]; }
    8487    }
     88    public ValueParameter<ISymbolicExpressionTreeNodeComparer> SymbolicExpressionTreeNodeComparerParameter {
     89      get { return (ValueParameter<ISymbolicExpressionTreeNodeComparer>)Parameters[SymbolicExpressionTreeNodeComparerParameterName]; }
     90    }
     91    #endregion
     92
     93    #region Properties
     94    public ISymbolicExpressionTreeNodeComparer SymbolicExpressionTreeNodeComparer {
     95      get { return (ISymbolicExpressionTreeNodeComparer)SymbolicExpressionTreeNodeComparerParameter.ActualValue; }
     96    }
    8597    #endregion
    8698
     
    100112      Parameters.Add(new ScopeTreeLookupParameter<ISymbolicExpressionTree>(ParentsParameterName, "The parent symbolic expression trees which should be crossed."));
    101113      Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(ChildParameterName, "The child symbolic expression tree resulting from the crossover."));
     114      Parameters.Add(new ValueParameter<ISymbolicExpressionTreeNodeComparer>(SymbolicExpressionTreeNodeComparerParameterName, SymbolicExpressionTreeNodeComparerParameterDescription));
    102115
    103116      EvaluatorParameter.Hidden = true;
     
    163176        op.MaximumSymbolicExpressionTreeLengthParameter.ActualName = MaximumSymbolicExpressionTreeLengthParameter.Name;
    164177      }
    165 
    166178      foreach (ISymbolicDataAnalysisInterpreterOperator op in Operators.OfType<ISymbolicDataAnalysisInterpreterOperator>()) {
    167179        op.SymbolicDataAnalysisTreeInterpreterParameter.ActualName = SymbolicDataAnalysisTreeInterpreterParameter.Name;
     
    173185        op.EvaluatorParameter.ActualName = EvaluatorParameter.Name;
    174186      }
     187      var comparers = ApplicationManager.Manager.GetInstances<ISymbolicExpressionTreeNodeComparer>();
     188      foreach (var op in Operators.OfType<ITracingSymbolicExpressionTreeOperator>()) {
     189        op.SymbolicExpressionTreeNodeComparerParameter.ActualValue = comparers.First();
     190      }
    175191    }
    176192  }
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionCrossover.cs

    r7521 r9241  
    3232
    3333namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    34   public abstract class SymbolicDataAnalysisExpressionCrossover<T> : SymbolicExpressionTreeCrossover, ISymbolicDataAnalysisExpressionCrossover<T> where T : class, IDataAnalysisProblemData {
     34  public abstract class SymbolicDataAnalysisExpressionCrossover<T> : TracingSymbolicExpressionTreeCrossover, ISymbolicDataAnalysisExpressionCrossover<T> where T : class, IDataAnalysisProblemData {
    3535    private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicExpressionTreeInterpreter";
    3636    private const string ProblemDataParameterName = "ProblemData";
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionDepthConstrainedCrossover.cs

    r7521 r9241  
    4141
    4242    #region Parameter properties
    43     public ConstrainedValueParameter<StringValue> DepthRangeParameter {
    44       get { return (ConstrainedValueParameter<StringValue>)Parameters[DepthRangeParameterName]; }
     43    public IConstrainedValueParameter<StringValue> DepthRangeParameter {
     44      get { return (IConstrainedValueParameter<StringValue>)Parameters[DepthRangeParameterName]; }
    4545    }
    4646    #endregion
     
    8989      var depthRange = new IntRange();
    9090      const int depthOffset = 2; // skip the first 2 levels (root + startNode)
    91       switch ((int)Enum.Parse(typeof(Ranges), mode)) {
    92         case (int)Ranges.HighLevel:
     91      switch ((Ranges)Enum.Parse(typeof(Ranges), mode)) {
     92        case Ranges.HighLevel:
    9393          depthRange.Start = depthOffset; // skip the first 2 levels (root + startNode)
    9494          depthRange.End = depthRange.Start + (int)Math.Round(depth * 0.25);
    9595          break;
    96         case (int)Ranges.Standard:
     96        case Ranges.Standard:
    9797          depthRange.Start = depthOffset + (int)Math.Round(depth * 0.25);
    9898          depthRange.End = depthRange.Start + (int)Math.Round(depth * 0.5);
    9999          break;
    100         case (int)Ranges.LowLevel:
     100        case Ranges.LowLevel:
    101101          depthRange.Start = depthOffset + (int)Math.Round(depth * 0.75);
    102102          depthRange.End = Math.Max(depthRange.Start, depth);
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Evaluators/SymbolicDataAnalysisEvaluator.cs

    r7259 r9241  
    2828using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2929using HeuristicLab.Operators;
     30using HeuristicLab.Optimization;
    3031using HeuristicLab.Parameters;
    3132using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3536  [StorableClass]
    3637  public abstract class SymbolicDataAnalysisEvaluator<T> : SingleSuccessorOperator,
    37     ISymbolicDataAnalysisEvaluator<T>, ISymbolicDataAnalysisInterpreterOperator, ISymbolicDataAnalysisBoundedOperator
     38    ISymbolicDataAnalysisEvaluator<T>, ISymbolicDataAnalysisInterpreterOperator, ISymbolicDataAnalysisBoundedOperator, IStochasticOperator
    3839  where T : class, IDataAnalysisProblemData {
    3940    private const string RandomParameterName = "Random";
     
    4445    private const string EvaluationPartitionParameterName = "EvaluationPartition";
    4546    private const string RelativeNumberOfEvaluatedSamplesParameterName = "RelativeNumberOfEvaluatedSamples";
     47    private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";
     48    private const string ValidRowIndicatorParameterName = "ValidRowIndicator";
    4649
    4750    public override bool CanChangeName { get { return false; } }
    4851
    4952    #region parameter properties
     53    ILookupParameter<IRandom> IStochasticOperator.RandomParameter {
     54      get { return RandomParameter; }
     55    }
     56
    5057    public IValueLookupParameter<IRandom> RandomParameter {
    5158      get { return (IValueLookupParameter<IRandom>)Parameters[RandomParameterName]; }
     
    7077      get { return (IValueLookupParameter<PercentValue>)Parameters[RelativeNumberOfEvaluatedSamplesParameterName]; }
    7178    }
     79    public ILookupParameter<BoolValue> ApplyLinearScalingParameter {
     80      get { return (ILookupParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }
     81    }
     82    public IValueLookupParameter<StringValue> ValidRowIndicatorParameter {
     83      get { return (IValueLookupParameter<StringValue>)Parameters[ValidRowIndicatorParameterName]; }
     84    }
    7285    #endregion
    7386
     
    87100      Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The upper and lower limit that should be used as cut off value for the output values of symbolic data analysis trees."));
    88101      Parameters.Add(new ValueLookupParameter<PercentValue>(RelativeNumberOfEvaluatedSamplesParameterName, "The relative number of samples of the dataset partition, which should be randomly chosen for evaluation between the start and end index."));
     102      Parameters.Add(new LookupParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the individual should be linearly scaled before evaluating."));
     103      Parameters.Add(new ValueLookupParameter<StringValue>(ValidRowIndicatorParameterName, "An indicator variable in the data set that specifies which rows should be evaluated (those for which the indicator <> 0) (optional)."));
     104    }
     105
     106    [StorableHook(HookType.AfterDeserialization)]
     107    private void AfterDeserialization() {
     108      if (Parameters.ContainsKey(ApplyLinearScalingParameterName) && !(Parameters[ApplyLinearScalingParameterName] is LookupParameter<BoolValue>))
     109        Parameters.Remove(ApplyLinearScalingParameterName);
     110      if (!Parameters.ContainsKey(ApplyLinearScalingParameterName))
     111        Parameters.Add(new LookupParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the individual should be linearly scaled before evaluating."));
     112      if (!Parameters.ContainsKey(ValidRowIndicatorParameterName))
     113        Parameters.Add(new ValueLookupParameter<StringValue>(ValidRowIndicatorParameterName, "An indicator variable in the data set that specifies which rows should be evaluated (those for which the indicator <> 0) (optional)."));
    89114    }
    90115
     
    94119
    95120    protected IEnumerable<int> GenerateRowsToEvaluate(double percentageOfRows) {
    96 
    97 
    98121      IEnumerable<int> rows;
    99122      int samplesStart = EvaluationPartitionParameter.ActualValue.Start;
     
    101124      int testPartitionStart = ProblemDataParameter.ActualValue.TestPartition.Start;
    102125      int testPartitionEnd = ProblemDataParameter.ActualValue.TestPartition.End;
    103 
    104126      if (samplesEnd < samplesStart) throw new ArgumentException("Start value is larger than end value.");
    105127
     
    113135      }
    114136
    115       return rows.Where(i => i < testPartitionStart || testPartitionEnd <= i);
     137      rows = rows.Where(i => i < testPartitionStart || testPartitionEnd <= i);
     138      if (ValidRowIndicatorParameter.ActualValue != null) {
     139        string indicatorVar = ValidRowIndicatorParameter.ActualValue.Value;
     140        var problemData = ProblemDataParameter.ActualValue;
     141        var indicatorRow = problemData.Dataset.GetReadOnlyDoubleValues(indicatorVar);
     142        rows = rows.Where(r => !indicatorRow[r].IsAlmost(0.0));
     143      }
     144      return rows;
     145    }
     146
     147    [ThreadStatic]
     148    private static double[] cache;
     149    protected static void CalculateWithScaling(IEnumerable<double> targetValues, IEnumerable<double> estimatedValues,
     150      double lowerEstimationLimit, double upperEstimationLimit,
     151      IOnlineCalculator calculator, int maxRows) {
     152      if (cache == null || cache.Length < maxRows) {
     153        cache = new double[maxRows];
     154      }
     155
     156      // calculate linear scaling
     157      int i = 0;
     158      var linearScalingCalculator = new OnlineLinearScalingParameterCalculator();
     159      var targetValuesEnumerator = targetValues.GetEnumerator();
     160      var estimatedValuesEnumerator = estimatedValues.GetEnumerator();
     161      while (targetValuesEnumerator.MoveNext() & estimatedValuesEnumerator.MoveNext()) {
     162        double target = targetValuesEnumerator.Current;
     163        double estimated = estimatedValuesEnumerator.Current;
     164        cache[i] = estimated;
     165        if (!double.IsNaN(estimated) && !double.IsInfinity(estimated))
     166          linearScalingCalculator.Add(estimated, target);
     167        i++;
     168      }
     169      if (linearScalingCalculator.ErrorState == OnlineCalculatorError.None && (targetValuesEnumerator.MoveNext() || estimatedValuesEnumerator.MoveNext()))
     170        throw new ArgumentException("Number of elements in target and estimated values enumeration do not match.");
     171
     172      double alpha = linearScalingCalculator.Alpha;
     173      double beta = linearScalingCalculator.Beta;
     174      if (linearScalingCalculator.ErrorState != OnlineCalculatorError.None) {
     175        alpha = 0.0;
     176        beta = 1.0;
     177      }
     178
     179      //calculate the quality by using the passed online calculator
     180      targetValuesEnumerator = targetValues.GetEnumerator();
     181      var scaledBoundedEstimatedValuesEnumerator = Enumerable.Range(0, i).Select(x => cache[x] * beta + alpha)
     182        .LimitToRange(lowerEstimationLimit, upperEstimationLimit).GetEnumerator();
     183
     184      while (targetValuesEnumerator.MoveNext() & scaledBoundedEstimatedValuesEnumerator.MoveNext()) {
     185        calculator.Add(targetValuesEnumerator.Current, scaledBoundedEstimatedValuesEnumerator.Current);
     186      }
    116187    }
    117188  }
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionLatexFormatter.cs

    r7708 r9241  
    3333  [StorableClass]
    3434  public sealed class SymbolicDataAnalysisExpressionLatexFormatter : NamedItem, ISymbolicExpressionTreeStringFormatter {
    35     private List<double> constants;
     35    private readonly List<double> constants;
     36    private int targetCount;
    3637    private int currentLag;
    3738
     
    9899      } else if (node.Symbol is Division) {
    99100        if (node.SubtreeCount == 1) {
    100           strBuilder.Append(@" \cfrac{1}{");
     101          strBuilder.Append(@" \cfrac{1");
    101102        } else {
    102103          strBuilder.Append(@" \cfrac{ ");
     
    196197        strBuilder.Append(invokeNode.Symbol.FunctionName + @" \left( ");
    197198      } else if (node.Symbol is StartSymbol) {
    198         strBuilder.Append("Result & = ");
     199        strBuilder.Append("target_" + (targetCount++) + "(t) & = ");
    199200      } else if (node.Symbol is Argument) {
    200201        var argSym = node.Symbol as Argument;
     
    301302        strBuilder.Append(" , ");
    302303      } else if (node.Symbol is StartSymbol) {
    303         strBuilder.Append(@"\\" + Environment.NewLine + " & ");
     304        strBuilder.Append(@"\\" + Environment.NewLine);
     305        strBuilder.Append("target_" + (targetCount++) + "(t) & = ");
    304306      } else if (node.Symbol is Power) {
    305307        strBuilder.Append(@"\right) ^ { \operatorname{round} \left(");
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/FullFunctionalExpressionGrammar.cs

    r7707 r9241  
    116116      var laggedVariable = new LaggedVariable();
    117117      laggedVariable.InitialFrequency = 0.0;
     118      var autoregressiveVariable = new AutoregressiveTargetVariable();
     119      autoregressiveVariable.InitialFrequency = 0.0;
     120      autoregressiveVariable.Enabled = false;
    118121
    119122      var allSymbols = new List<Symbol>() { add, sub, mul, div, mean, sin, cos, tan, log, square, pow, sqrt, root, exp,
    120123        airyA, airyB, bessel, cosineIntegral, dawson, erf, expIntegralEi, fresnelCosineIntegral, fresnelSineIntegral, gamma, hypCosineIntegral, hypSineIntegral, norm, psi, sineIntegral,
    121         @if, gt, lt, and, or, not, timeLag, integral, derivative, constant, variableSymbol, laggedVariable, variableCondition };
     124        @if, gt, lt, and, or, not, timeLag, integral, derivative, constant, variableSymbol, laggedVariable,autoregressiveVariable, variableCondition };
    122125      var unaryFunctionSymbols = new List<Symbol>() { square, sqrt, sin, cos, tan, log, exp, not, timeLag, integral, derivative,
    123126        airyA, airyB, bessel, cosineIntegral, dawson, erf, expIntegralEi, fresnelCosineIntegral, fresnelSineIntegral, gamma, hypCosineIntegral, hypSineIntegral, norm, psi, sineIntegral
     
    126129      var binaryFunctionSymbols = new List<Symbol>() { pow, root, gt, lt, variableCondition };
    127130      var ternarySymbols = new List<Symbol>() { add, sub, mul, div, mean, and, or };
    128       var terminalSymbols = new List<Symbol>() { variableSymbol, constant, laggedVariable };
     131      var terminalSymbols = new List<Symbol>() { variableSymbol, constant, laggedVariable, autoregressiveVariable };
    129132
    130133      foreach (var symb in allSymbols)
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/TypeCoherentExpressionGrammar.cs

    r7696 r9241  
    102102      constant.MinValue = -20;
    103103      constant.MaxValue = 20;
     104      //      var integerConstant = new IntegerConstant { MinValue = 0, MaxValue = 10; }
    104105      var variableSymbol = new Variable();
    105106      var laggedVariable = new LaggedVariable();
     107      var autoregressiveVariable = new AutoregressiveTargetVariable();
    106108      #endregion
    107109
     
    122124      var conditionalSymbols = new GroupSymbol(ConditionalSymbolsName, new List<ISymbol> { conditionSymbols, comparisonSymbols, booleanOperationSymbols });
    123125
    124       var timeSeriesSymbols = new GroupSymbol(TimeSeriesSymbolsName, new List<ISymbol> { timeLag, integral, derivative, laggedVariable });
     126      var timeSeriesSymbols = new GroupSymbol(TimeSeriesSymbolsName, new List<ISymbol> { timeLag, integral, derivative, laggedVariable, autoregressiveVariable });
    125127      #endregion
    126128
     
    152154      SetSubtreeCount(derivative, 1, 1);
    153155      SetSubtreeCount(laggedVariable, 0, 0);
     156      SetSubtreeCount(autoregressiveVariable, 0, 0);
    154157      #endregion
    155158
     
    225228      Symbols.First(s => s.Name == TimeSeriesSymbolsName).Enabled = false;
    226229    }
     230
     231    public void ConfigureAsDefaultTimeSeriesPrognosisGrammar() {
     232      Symbols.First(s => s is Average).Enabled = false;
     233      Symbols.First(s => s.Name == TrigonometricFunctionsName).Enabled = false;
     234      Symbols.First(s => s.Name == PowerFunctionsName).Enabled = false;
     235      Symbols.First(s => s.Name == ConditionalSymbolsName).Enabled = false;
     236      Symbols.First(s => s.Name == SpecialFunctionsName).Enabled = false;
     237
     238      Symbols.First(s => s.Name == TimeSeriesSymbolsName).Enabled = true;
     239      Symbols.First(s => s is Derivative).Enabled = false;
     240      Symbols.First(s => s is Integral).Enabled = false;
     241      Symbols.First(s => s is TimeLag).Enabled = false;
     242    }
    227243  }
    228244}
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj

    r8557 r9241  
    5858  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
    5959    <DebugSymbols>true</DebugSymbols>
    60     <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath>
     60    <OutputPath>$(SolutionDir)\bin\</OutputPath>
    6161    <DefineConstants>DEBUG;TRACE</DefineConstants>
    6262    <DebugType>full</DebugType>
     
    6666  </PropertyGroup>
    6767  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
    68     <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath>
     68    <OutputPath>$(SolutionDir)\bin\</OutputPath>
    6969    <DefineConstants>TRACE</DefineConstants>
    7070    <Optimize>true</Optimize>
     
    7676  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
    7777    <DebugSymbols>true</DebugSymbols>
    78     <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath>
     78    <OutputPath>$(SolutionDir)\bin\</OutputPath>
    7979    <DefineConstants>DEBUG;TRACE</DefineConstants>
    8080    <DebugType>full</DebugType>
     
    8484  </PropertyGroup>
    8585  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
    86     <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath>
     86    <OutputPath>$(SolutionDir)\bin\</OutputPath>
    8787    <DefineConstants>TRACE</DefineConstants>
    8888    <Optimize>true</Optimize>
     
    9393  </PropertyGroup>
    9494  <ItemGroup>
    95     <Reference Include="ALGLIB-3.5.0">
    96       <HintPath>..\..\..\..\trunk\sources\bin\ALGLIB-3.5.0.dll</HintPath>
     95    <Reference Include="ALGLIB-3.6.0, Version=3.6.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     96      <HintPath>..\..\bin\ALGLIB-3.6.0.dll</HintPath>
     97      <Private>False</Private>
    9798    </Reference>
    9899    <Reference Include="HeuristicLab.Analysis-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    99100      <SpecificVersion>False</SpecificVersion>
    100       <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Analysis-3.3.dll</HintPath>
     101      <HintPath>..\..\..\..\Trunk\sources\bin\HeuristicLab.Analysis-3.3.dll</HintPath>
    101102    </Reference>
    102103    <Reference Include="HeuristicLab.Collections-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    103104      <SpecificVersion>False</SpecificVersion>
    104       <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Collections-3.3.dll</HintPath>
     105      <HintPath>..\..\..\..\Trunk\sources\bin\HeuristicLab.Collections-3.3.dll</HintPath>
    105106    </Reference>
    106107    <Reference Include="HeuristicLab.Common-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    107108      <SpecificVersion>False</SpecificVersion>
    108       <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Common-3.3.dll</HintPath>
     109      <HintPath>..\..\..\..\Trunk\sources\bin\HeuristicLab.Common-3.3.dll</HintPath>
    109110    </Reference>
    110111    <Reference Include="HeuristicLab.Common.Resources-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    111112      <SpecificVersion>False</SpecificVersion>
    112       <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Common.Resources-3.3.dll</HintPath>
     113      <HintPath>..\..\..\..\Trunk\sources\bin\HeuristicLab.Common.Resources-3.3.dll</HintPath>
    113114    </Reference>
    114115    <Reference Include="HeuristicLab.Core-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    115116      <SpecificVersion>False</SpecificVersion>
    116       <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Core-3.3.dll</HintPath>
     117      <HintPath>..\..\..\..\Trunk\sources\bin\HeuristicLab.Core-3.3.dll</HintPath>
    117118    </Reference>
    118119    <Reference Include="HeuristicLab.Data-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    119120      <SpecificVersion>False</SpecificVersion>
    120       <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Data-3.3.dll</HintPath>
     121      <HintPath>..\..\..\..\Trunk\sources\bin\HeuristicLab.Data-3.3.dll</HintPath>
    121122    </Reference>
    122123    <Reference Include="HeuristicLab.Operators-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    123124      <SpecificVersion>False</SpecificVersion>
    124       <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Operators-3.3.dll</HintPath>
     125      <HintPath>..\..\..\..\Trunk\sources\bin\HeuristicLab.Operators-3.3.dll</HintPath>
    125126    </Reference>
    126127    <Reference Include="HeuristicLab.Optimization-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    127128      <SpecificVersion>False</SpecificVersion>
    128       <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Optimization-3.3.dll</HintPath>
    129     </Reference>
    130     <Reference Include="HeuristicLab.Optimization.Operators-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    131       <SpecificVersion>False</SpecificVersion>
    132       <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Optimization.Operators-3.3.dll</HintPath>
     129      <HintPath>..\..\..\..\Trunk\sources\bin\HeuristicLab.Optimization-3.3.dll</HintPath>
    133130    </Reference>
    134131    <Reference Include="HeuristicLab.Parameters-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    135132      <SpecificVersion>False</SpecificVersion>
    136       <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Parameters-3.3.dll</HintPath>
     133      <HintPath>..\..\..\..\Trunk\sources\bin\HeuristicLab.Parameters-3.3.dll</HintPath>
    137134    </Reference>
    138135    <Reference Include="HeuristicLab.Persistence-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    139136      <SpecificVersion>False</SpecificVersion>
    140       <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Persistence-3.3.dll</HintPath>
     137      <HintPath>..\..\..\..\Trunk\sources\bin\HeuristicLab.Persistence-3.3.dll</HintPath>
    141138    </Reference>
    142139    <Reference Include="HeuristicLab.PluginInfrastructure-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    143140      <SpecificVersion>False</SpecificVersion>
    144       <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.PluginInfrastructure-3.3.dll</HintPath>
    145     </Reference>
    146     <Reference Include="HeuristicLab.Problems.DataAnalysis-3.4">
    147       <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Problems.DataAnalysis-3.4.dll</HintPath>
    148     </Reference>
    149     <Reference Include="HeuristicLab.Problems.Instances-3.3">
    150       <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Problems.Instances-3.3.dll</HintPath>
     141      <HintPath>..\..\..\..\Trunk\sources\bin\HeuristicLab.PluginInfrastructure-3.3.dll</HintPath>
     142    </Reference>
     143    <Reference Include="HeuristicLab.Problems.DataAnalysis-3.4, Version=3.4.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     144      <SpecificVersion>False</SpecificVersion>
     145      <HintPath>..\..\..\..\Trunk\sources\bin\HeuristicLab.Problems.DataAnalysis-3.4.dll</HintPath>
     146    </Reference>
     147    <Reference Include="HeuristicLab.Problems.Instances-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     148      <SpecificVersion>False</SpecificVersion>
     149      <HintPath>..\..\..\..\Trunk\sources\bin\HeuristicLab.Problems.Instances-3.3.dll</HintPath>
    151150    </Reference>
    152151    <Reference Include="HeuristicLab.Random-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    153152      <SpecificVersion>False</SpecificVersion>
    154       <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Random-3.3.dll</HintPath>
     153      <HintPath>..\..\..\..\Trunk\sources\bin\HeuristicLab.Random-3.3.dll</HintPath>
    155154    </Reference>
    156155    <Reference Include="System" />
     
    159158    </Reference>
    160159    <Reference Include="System.Drawing" />
    161     <Reference Include="System.Xml.Linq">
    162       <RequiredTargetFramework>3.5</RequiredTargetFramework>
    163     </Reference>
    164     <Reference Include="System.Data.DataSetExtensions">
    165       <RequiredTargetFramework>3.5</RequiredTargetFramework>
    166     </Reference>
    167     <Reference Include="System.Data" />
    168     <Reference Include="System.Xml" />
    169160  </ItemGroup>
    170161  <ItemGroup>
    171     <Compile Include="Analyzers\SymbolicDataAnalysisComplexityAnalyzer.cs" />
    172162    <Compile Include="Analyzers\SymbolicDataAnalysisSingleObjectiveValidationParetoBestSolutionAnalyzer.cs" />
    173163    <Compile Include="Analyzers\SymbolicDataAnalysisSingleObjectiveTrainingParetoBestSolutionAnalyzer.cs" />
     
    198188    <Compile Include="Crossovers\SymbolicDataAnalysisExpressionSemanticSimilarityCrossover.cs" />
    199189    <Compile Include="Interfaces\ISymbolicDataAnalysisExpressionCrossover.cs" />
     190    <Compile Include="Interfaces\ISymbolicDataAnalysisImpactValuesCalculator.cs" />
     191    <Compile Include="Interpreter\InterpreterState.cs" />
     192    <Compile Include="Interpreter\OpCodes.cs" />
     193    <Compile Include="Interpreter\SymbolicDataAnalysisExpressionTreeILEmittingInterpreter.cs" />
     194    <Compile Include="Interpreter\SymbolicDataAnalysisExpressionTreeInterpreter.cs" />
    200195    <Compile Include="Plugin.cs" />
    201     <Compile Include="SymbolicDataAnalysisExpressionTreeILEmittingInterpreter.cs" />
    202196    <Compile Include="Formatters\SymbolicDataAnalysisExpressionLatexFormatter.cs" />
    203197    <Compile Include="Formatters\SymbolicDataAnalysisExpressionMATLABFormatter.cs" />
     
    205199    <Compile Include="Interfaces\ISymbolicDataAnalysisExpressionTreeInterpreter.cs" />
    206200    <Compile Include="Interfaces\ISymbolicDataAnalysisProblem.cs" />
     201    <Compile Include="SymbolicDataAnalysisExpressionTreeMatching.cs" />
    207202    <Compile Include="SymbolicDataAnalysisModel.cs">
    208203      <SubType>Code</SubType>
     
    217212    <Compile Include="Interfaces\ISymbolicDataAnalysisAnalyzer.cs" />
    218213    <Compile Include="SymbolicDataAnalysisSingleObjectiveProblem.cs" />
    219     <Compile Include="SymbolicDataAnalysisExpressionTreeInterpreter.cs" />
    220214    <Compile Include="SymbolicDataAnalysisExpressionTreeSimplifier.cs" />
    221215    <Compile Include="SymbolicDataAnalysisProblem.cs" />
    222     <Compile Include="SymbolicDataAnalysisSolutionValuesCalculator.cs" />
    223     <Compile Include="SymbolicDataAnalysisExpressionTreeMatching.cs" />
     216    <Compile Include="SymbolicDataAnalysisSolutionImpactValuesCalculator.cs" />
     217    <Compile Include="SymbolicDataAnalysisSolutionTextRenderer.cs" />
    224218    <Compile Include="Symbols\Addition.cs" />
    225219    <Compile Include="Symbols\And.cs" />
     220    <Compile Include="Symbols\AutoregressiveVariable.cs" />
    226221    <Compile Include="Symbols\Average.cs" />
    227222    <Compile Include="Symbols\Constant.cs" />
     
    306301  <ItemGroup>
    307302    <ProjectReference Include="..\..\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding\3.4\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.csproj">
    308       <Project>{06D4A186-9319-48A0-BADE-A2058D462EEA}</Project>
     303      <Project>{06d4a186-9319-48a0-bade-a2058d462eea}</Project>
    309304      <Name>HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4</Name>
    310305    </ProjectReference>
     
    319314  -->
    320315  <PropertyGroup>
    321     <PreBuildEvent>set Path=%25Path%25;$(ProjectDir);$(SolutionDir)
     316    <PreBuildEvent Condition=" '$(OS)' == 'Windows_NT' ">set Path=%25Path%25;$(ProjectDir);$(SolutionDir)
    322317set ProjectDir=$(ProjectDir)
    323318set SolutionDir=$(SolutionDir)
     
    326321call PreBuildEvent.cmd
    327322</PreBuildEvent>
     323    <PreBuildEvent Condition=" '$(OS)' != 'Windows_NT' ">
     324export ProjectDir=$(ProjectDir)
     325export SolutionDir=$(SolutionDir)
     326
     327$SolutionDir/PreBuildEvent.sh
     328</PreBuildEvent>
    328329  </PropertyGroup>
    329330</Project>
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interfaces/ISymbolicDataAnalysisEvaluator.cs

    r7259 r9241  
    2929    IValueLookupParameter<IntRange> EvaluationPartitionParameter { get; }
    3030    IValueLookupParameter<PercentValue> RelativeNumberOfEvaluatedSamplesParameter { get; }
     31    ILookupParameter<BoolValue> ApplyLinearScalingParameter { get; }
    3132
    3233    IValueLookupParameter<T> ProblemDataParameter { get; }
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interfaces/ISymbolicDataAnalysisMultiObjectiveAnalyzer.cs

    r7259 r9241  
    2121using HeuristicLab.Core;
    2222using HeuristicLab.Data;
    23 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    24 using HeuristicLab.Optimization;
    25 using HeuristicLab.Parameters;
    2623namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    2724  public interface ISymbolicDataAnalysisMultiObjectiveAnalyzer : ISymbolicDataAnalysisAnalyzer {
    2825    IScopeTreeLookupParameter<DoubleArray> QualitiesParameter { get; }
    2926    ILookupParameter<BoolArray> MaximizationParameter { get; }
     27    ILookupParameter<BoolValue> ApplyLinearScalingParameter { get; }
    3028
    3129  }
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interfaces/ISymbolicDataAnalysisProblem.cs

    r7259 r9241  
    2222using HeuristicLab.Core;
    2323using HeuristicLab.Data;
     24using HeuristicLab.Optimization;
    2425
    2526namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    26   public interface ISymbolicDataAnalysisProblem : IDataAnalysisProblem {
     27  public interface ISymbolicDataAnalysisProblem : IDataAnalysisProblem, IHeuristicOptimizationProblem {
    2728    IValueParameter<ISymbolicDataAnalysisGrammar> SymbolicExpressionTreeGrammarParameter { get; }
    2829    IValueParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> SymbolicExpressionTreeInterpreterParameter { get; }
     
    4546    IntRange ValidationPartition { get; }
    4647  }
     48
     49  public interface ISymbolicDataAnalysisSingleObjectiveProblem : ISymbolicDataAnalysisProblem, ISingleObjectiveHeuristicOptimizationProblem { }
     50  public interface ISymbolicDataAnalysisMultiObjectiveProblem : ISymbolicDataAnalysisProblem, IMultiObjectiveHeuristicOptimizationProblem { }
    4751}
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interfaces/ISymbolicDataAnalysisSingleObjectiveAnalyzer.cs

    r7259 r9241  
    2828    IScopeTreeLookupParameter<DoubleValue> QualityParameter { get; }
    2929    ILookupParameter<BoolValue> MaximizationParameter { get; }
     30    ILookupParameter<BoolValue> ApplyLinearScalingParameter { get; }
    3031  }
    3132}
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/OpCodes.cs

    r8477 r9241  
    105105      { typeof(AutoregressiveTargetVariable),OpCodes.LagVariable},
    106106      { typeof(Constant), OpCodes.Constant },
     107//      { typeof(IntegerConstant), OpCodes.Constant},
    107108      { typeof(Argument), OpCodes.Arg },
    108109      { typeof(Power),OpCodes.Power},
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeInterpreter.cs

    r8486 r9241  
    9999        throw new NotSupportedException("Interval arithmetic is not yet supported in the symbolic data analysis interpreter.");
    100100
    101       EvaluatedSolutions.Value++; // increment the evaluated solutions counter
     101      lock (EvaluatedSolutions) {
     102        EvaluatedSolutions.Value++; // increment the evaluated solutions counter
     103      }
    102104      var state = PrepareInterpreterState(tree, dataset);
    103105
     
    109111    }
    110112
    111     private InterpreterState PrepareInterpreterState(ISymbolicExpressionTree tree, Dataset dataset) {
     113    private static InterpreterState PrepareInterpreterState(ISymbolicExpressionTree tree, Dataset dataset) {
    112114      Instruction[] code = SymbolicExpressionTreeCompiler.Compile(tree, OpCodes.MapSymbolToOpCode);
    113115      int necessaryArgStackSize = 0;
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Plugin.cs.frame

    r7834 r9241  
    2626
    2727namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    28   [Plugin("HeuristicLab.Problems.DataAnalysis.Symbolic","Provides base classes for symbolic data analysis tasks.", "3.4.2.$WCREV$")]
     28  [Plugin("HeuristicLab.Problems.DataAnalysis.Symbolic","Provides base classes for symbolic data analysis tasks.", "3.4.3.$WCREV$")]
    2929  [PluginFile("HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.dll", PluginFileType.Assembly)]
    30   [PluginDependency("HeuristicLab.ALGLIB", "3.5.0")]
     30  [PluginDependency("HeuristicLab.ALGLIB", "3.6.0")]
    3131  [PluginDependency("HeuristicLab.Analysis", "3.3")]
    3232  [PluginDependency("HeuristicLab.Collections", "3.3")]
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Properties

    • Property svn:ignore
      --- 
      +++ 
      
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Properties/AssemblyInfo.cs.frame

    r7259 r9241  
    5353// by using the '*' as shown below:
    5454[assembly: AssemblyVersion("3.4.0.0")]
    55 [assembly: AssemblyFileVersion("3.4.2.$WCREV$")]
     55[assembly: AssemblyFileVersion("3.4.3.$WCREV$")]
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeMatching.cs

    r8557 r9241  
    11using System;
    22using System.Collections.Generic;
    3 using System.IO;
    43using System.Linq;
    54using HeuristicLab.Common;
     
    76using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    87using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     8using HeuristicLab.Problems.DataAnalysis.Symbolic;
    99
    1010namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    11   public enum SimilarityLevel {
    12     Exact,   // everything is matched bit by bit (functions and terminals)
    13     High,    // symbols are matched. leaf node types are matched
    14     Relaxed  // only symbols are matched, leafs count as wildcards
    15   }
    1611  [Item("SymbolicExpressionTreeNodeSimilarityComparer", "A comparison operator that checks node equality based on different similarity measures.")]
    1712  [StorableClass]
     
    1914    [StorableConstructor]
    2015    private SymbolicExpressionTreeNodeSimilarityComparer(bool deserializing) : base(deserializing) { }
    21     private SymbolicExpressionTreeNodeSimilarityComparer(SymbolicExpressionTreeNodeSimilarityComparer original, Cloner cloner) : base(original, cloner) { }
     16    private SymbolicExpressionTreeNodeSimilarityComparer(SymbolicExpressionTreeNodeSimilarityComparer original, Cloner cloner)
     17      : base(original, cloner) {
     18      matchConstantValues = original.matchConstantValues;
     19      matchVariableNames = original.matchVariableNames;
     20      matchVariableWeights = original.matchVariableWeights;
     21    }
    2222    public override IDeepCloneable Clone(Cloner cloner) { return new SymbolicExpressionTreeNodeSimilarityComparer(this, cloner); }
    2323
    24     private SimilarityLevel similarityLevel;
    25     public SimilarityLevel SimilarityLevel {
    26       get { return similarityLevel; }
    27       set { similarityLevel = value; }
     24    // more flexible matching criteria
     25    [Storable]
     26    private bool matchConstantValues;
     27    public bool MatchConstantValues {
     28      get { return matchConstantValues; }
     29      set { matchConstantValues = value; }
     30    }
     31
     32    [Storable]
     33    private bool matchVariableNames;
     34    public bool MatchVariableNames {
     35      get { return matchVariableNames; }
     36      set { matchVariableNames = value; }
     37    }
     38
     39    [Storable]
     40    private bool matchVariableWeights;
     41    public bool MatchVariableWeights {
     42      get { return matchVariableWeights; }
     43      set { matchVariableWeights = value; }
     44    }
     45
     46    [StorableHook(HookType.AfterDeserialization)]
     47    private void AfterDeserialization() {
    2848    }
    2949
    3050    public SymbolicExpressionTreeNodeSimilarityComparer() {
    31       this.similarityLevel = SimilarityLevel.Exact;
    32     }
    33 
    34     public SymbolicExpressionTreeNodeSimilarityComparer(SimilarityLevel similarityLevel) {
    35       this.similarityLevel = similarityLevel;
     51      matchConstantValues = true;
     52      matchVariableNames = true;
     53      matchVariableWeights = true;
    3654    }
    3755
     
    4159
    4260    public bool Equals(ISymbolicExpressionTreeNode a, ISymbolicExpressionTreeNode b) {
     61      if (!(a is SymbolicExpressionTreeTerminalNode))
     62        // if a and b are non terminal nodes, check equality of symbol names
     63        return !(b is SymbolicExpressionTreeTerminalNode) && a.Symbol.Name.Equals(b.Symbol.Name);
     64      var va = a as VariableTreeNode;
     65      if (va != null) {
     66        var vb = b as VariableTreeNode;
     67        if (vb == null) return false;
     68
     69        return (!MatchVariableNames || va.VariableName.Equals(vb.VariableName)) && (!MatchVariableWeights || va.Weight.Equals(vb.Weight));
     70      }
    4371      var ca = a as ConstantTreeNode;
    44       var cb = b as ConstantTreeNode;
     72      if (ca != null) {
     73        var cb = b as ConstantTreeNode;
     74        if (cb == null) return false;
     75        return (!MatchConstantValues || ca.Value.Equals(cb.Value));
     76      }
     77      return false;
     78    }
     79  }
     80
     81  public class SymbolicExpressionTreeFragmentSimilarityComparer : IEqualityComparer<IFragment> {
     82    public SymbolicExpressionTreeNodeSimilarityComparer SimilarityComparer { get; set; }
     83
     84    public bool Equals(IFragment x, IFragment y) {
     85      if (SimilarityComparer == null)
     86        throw new ArgumentNullException("SimilarityComparer needs to be initialized first.");
     87      return x.Length == y.Length &&
     88             SymbolicExpressionTreeMatching.Match(x.Root, y.Root, SimilarityComparer) == x.Length;
     89    }
     90
     91    public int GetHashCode(IFragment fragment) {
     92      return fragment.Root.Symbol.Name.ToLower().GetHashCode();
     93    }
     94  }
     95
     96  // this comparer considers that a < b if the type of a is "greater" than the type of b, for example:
     97  // - A function node is "greater" than a terminal node
     98  // - A variable terminal is "greater" than a constant terminal
     99  public class SymbolicExpressionTreeNodeComparer : IComparer<ISymbolicExpressionTreeNode> {
     100    public int Compare(ISymbolicExpressionTreeNode a, ISymbolicExpressionTreeNode b) {
     101      if (!(a is SymbolicExpressionTreeTerminalNode)) {
     102        if (b is SymbolicExpressionTreeTerminalNode) return -1;
     103        return string.Compare(a.Symbol.Name, b.Symbol.Name, StringComparison.Ordinal);
     104      }
     105      if (!(b is SymbolicExpressionTreeTerminalNode)) return 1;
     106      // at this point we know a and b are terminal nodes
    45107      var va = a as VariableTreeNode;
    46       var vb = b as VariableTreeNode;
    47 
    48       var aIsConstant = ca != null;
    49       var aIsVariable = va != null;
    50       var bIsConstant = cb != null;
    51       var bIsVariable = vb != null;
    52       var aIsFunction = (!(aIsConstant | aIsVariable));
    53       var bIsFunction = (!(bIsConstant | bIsVariable));
    54 
    55       if (aIsFunction)
    56         return bIsFunction && a.Symbol.Name.Equals(b.Symbol.Name);
    57       if (bIsFunction) // one is function and the other is not, return false
    58         return false;
    59 
    60       switch (similarityLevel) {
    61         case (SimilarityLevel.Exact):
    62           if (aIsConstant & bIsConstant)
    63             return ca.Value.Equals(cb.Value);
    64           if (aIsVariable & bIsVariable)
    65             return va.Weight.Equals(vb.Weight);
    66           return false;
    67         case (SimilarityLevel.High):
    68           return ((aIsConstant & bIsConstant) || (aIsVariable & bIsVariable));
    69         case (SimilarityLevel.Relaxed):
    70           return true;
    71         default:
    72           return false;
    73       }
    74     }
    75 
    76     public static bool ExactlySimilar(ISymbolicExpressionTreeNode a, ISymbolicExpressionTreeNode b) {
    77       return Similar(a, b, SimilarityLevel.Exact);
    78     }
    79 
    80     public static bool Similar(ISymbolicExpressionTreeNode a, ISymbolicExpressionTreeNode b, SimilarityLevel level) {
    81       var comp = new SymbolicExpressionTreeNodeSimilarityComparer(level);
    82       return comp.Equals(a, b);
    83     }
    84   }
    85 
    86   public class SymbolicExpressionTreeNodeOrderingComparer : IComparer<ISymbolicExpressionTreeNode> {
    87     public int Compare(ISymbolicExpressionTreeNode a, ISymbolicExpressionTreeNode b) {
    88       var ca = a as ConstantTreeNode;
    89       var cb = b as ConstantTreeNode;
    90       var va = a as VariableTreeNode;
    91       var vb = b as VariableTreeNode;
    92 
    93       var aIsConstant = ca != null;
    94       var aIsVariable = va != null;
    95       var bIsConstant = cb != null;
    96       var bIsVariable = vb != null;
    97       var aIsFunction = (!(aIsConstant | aIsVariable));
    98       var bIsFunction = (!(bIsConstant | bIsVariable));
    99 
    100       if (aIsFunction)
    101         return bIsFunction ? a.Symbol.Name.CompareTo(b.Symbol.Name) : -1;
    102       if (bIsFunction) // a is Constant or Variables
    103         return 1;
    104       if (aIsVariable)
    105         return bIsVariable ? va.Weight.CompareTo(vb.Weight) : -1;
    106       return
    107         bIsVariable ? 1 : ca.Value.CompareTo(cb.Value);
     108      if (va != null) {
     109        if (b is ConstantTreeNode) return -1;
     110        var vb = (VariableTreeNode)b;
     111        return (va.VariableName.Equals(vb.VariableName)
     112                  ? va.Weight.CompareTo(vb.Weight)
     113                  : string.Compare(va.VariableName, vb.VariableName, StringComparison.Ordinal));
     114      }
     115      // at this point we know for sure that a is a constant tree node
     116      if (b is VariableTreeNode) return 1;
     117      var ca = (ConstantTreeNode)a;
     118      var cb = (ConstantTreeNode)b;
     119      return ca.Value.CompareTo(cb.Value);
    108120    }
    109121  }
     
    111123  // tree equality
    112124  public class SymbolicExpressionTreeEqualityComparer : IEqualityComparer<ISymbolicExpressionTree> {
     125    public SymbolicExpressionTreeNodeSimilarityComparer SimilarityComparer { get; set; }
     126
    113127    public bool Equals(ISymbolicExpressionTree a, ISymbolicExpressionTree b) {
    114       return SymbolicExpressionTreeMatching.FindMatch(a, b, similarityLevel) == 0;
     128      if (SimilarityComparer == null) throw new ArgumentNullException("SimilarityComparer needs to be initialized first.");
     129      return SymbolicExpressionTreeMatching.Match(a.Root, b.Root, SimilarityComparer) == Math.Min(a.Length, b.Length);
    115130    }
    116131
     
    118133      return (tree.Length << 8) % 12345;
    119134    }
    120 
    121     private SimilarityLevel similarityLevel;
    122     public void SetComparisonMode(SimilarityLevel simLevel) {
    123       similarityLevel = simLevel;
    124     }
    125   }
    126 
    127   public static class SymbolicExpressionTreeMatching {
    128     public static bool IsSimilarTo(this ISymbolicExpressionTree t1, ISymbolicExpressionTree t2, SimilarityLevel mode) {
    129       return FindMatch(t1, t2, mode) == 0;
    130     }
    131 
    132     public static bool IsSimilarTo(this ISymbolicExpressionTreeNode t1, ISymbolicExpressionTreeNode t2, SimilarityLevel mode) {
    133       return FindMatch(t1, t2, mode) == 0;
    134     }
    135 
    136     public static bool ContainsFragment(this ISymbolicExpressionTree tree, ISymbolicExpressionTreeNode fragment, SimilarityLevel mode) {
    137       var matches = FindMatches(tree, fragment, mode);
    138       return matches.Count > 0;
    139     }
    140 
    141     public static void SortSubtrees(this ISymbolicExpressionTree tree) {
     135  }
     136
     137  public class SymbolicExpressionTreeCanonicalSorter {
     138    private readonly HashSet<Type> nonSymmetricSymbols = new HashSet<Type> { typeof(Subtraction), typeof(Division) };
     139
     140    public void SortSubtrees(ISymbolicExpressionTree tree) {
    142141      SortSubtrees(tree.Root);
    143142    }
    144143
    145     public static void SortSubtrees(this ISymbolicExpressionTreeNode node) {
     144    public void SortSubtrees(ISymbolicExpressionTreeNode node) {
    146145      if (node.SubtreeCount == 0) return;
    147       var subtrees = node.Subtrees as List<ISymbolicExpressionTreeNode>;
    148       if (subtrees == null) return;
    149       var comparer = new SymbolicExpressionTreeNodeOrderingComparer();
    150       subtrees.Sort(comparer);
    151       foreach (var subtree in subtrees)
    152         subtree.SortSubtrees();
    153     }
    154 
    155     // return child that is the same as node
    156     public static ISymbolicExpressionTreeNode FindChild(this ISymbolicExpressionTreeNode parent, ISymbolicExpressionTreeNode node) {
    157       var subtrees = parent.Subtrees as List<ISymbolicExpressionTreeNode>;
    158       var comparer = new SymbolicExpressionTreeNodeSimilarityComparer(SimilarityLevel.Exact);
    159       return subtrees.Find(x => comparer.Equals(x, node));
    160     }
    161 
    162     public static int FindMatch(ISymbolicExpressionTree a, ISymbolicExpressionTree b, SimilarityLevel similarityLevel) {
    163       var nodesA = a.IterateNodesPostfix() as List<ISymbolicExpressionTreeNode>;
    164       var nodesB = b.IterateNodesPostfix() as List<ISymbolicExpressionTreeNode>;
    165       return FindMatch(nodesA, nodesB, similarityLevel);
    166     }
    167 
    168     public static int FindMatch(ISymbolicExpressionTreeNode a, ISymbolicExpressionTreeNode b, SimilarityLevel similarityLevel) {
    169       var nodesA = a.IterateNodesPostfix() as List<ISymbolicExpressionTreeNode>;
    170       var nodesB = b.IterateNodesPostfix() as List<ISymbolicExpressionTreeNode>;
    171       return FindMatch(nodesA, nodesB, similarityLevel);
    172     }
    173 
    174     // returns the index in the sequence 'seq', where pattern 'pat' is matched, or -1 for no match
    175     // -1 means no match, 0 means perfect match (the sequences overlap, hence the match index is 0)
    176     public static int FindMatch(List<ISymbolicExpressionTreeNode> seq, List<ISymbolicExpressionTreeNode> pat, SimilarityLevel similarityLevel) {
    177       int patlen = pat.Count;
    178       int seqlen = seq.Count;
    179       if (patlen == 0 || seqlen == 0) return -1;
    180       var comparer = new SymbolicExpressionTreeNodeSimilarityComparer(similarityLevel);
    181       if (patlen == seqlen) return seq.SequenceEqual(pat, comparer) ? 0 : -1;
    182       for (int i = patlen; i <= seqlen; ++i) {
    183         if (comparer.Equals(seq[i - 1], pat.Last())) // first check if last element is a match
    184           if (seq.Skip(i - patlen).Take(patlen).SequenceEqual(pat, comparer)) // then check the whole sequence
    185             return i - patlen;
    186       }
    187       return -1;
    188     }
    189 
    190     public static List<ISymbolicExpressionTreeNode> FindMatches(ISymbolicExpressionTree tree, ISymbolicExpressionTreeNode fragment, SimilarityLevel similarityLevel) {
    191       var comp = new SymbolicExpressionTreeNodeSimilarityComparer(similarityLevel);
    192       return FindMatches(tree.Root, fragment, comp);
    193     }
    194 
    195     public static List<ISymbolicExpressionTreeNode>
     146      var subtrees = node.Subtrees as List<ISymbolicExpressionTreeNode> ?? node.Subtrees.ToList();
     147      if (IsSymmetric(node.Symbol)) {
     148        var comparer = new SymbolicExpressionTreeNodeComparer();
     149        subtrees.Sort(comparer);
     150      }
     151      foreach (var s in subtrees)
     152        SortSubtrees(s);
     153    }
     154
     155    private bool IsSymmetric(ISymbol s) {
     156      return !nonSymmetricSymbols.Contains(s.GetType());
     157    }
     158  }
     159}
     160
     161public static class SymbolicExpressionTreeMatching {
     162  public static bool IsSimilarTo(this ISymbolicExpressionTree t1, ISymbolicExpressionTree t2, SymbolicExpressionTreeNodeSimilarityComparer comparer) {
     163    return t1.Root.IsSimilarTo(t2.Root, comparer);
     164  }
     165  public static bool IsSimilarTo(this ISymbolicExpressionTreeNode t1, ISymbolicExpressionTreeNode t2, SymbolicExpressionTreeNodeSimilarityComparer comparer) {
     166    return Match(t1, t2, comparer) == Math.Min(t1.GetLength(), t2.GetLength());
     167  }
     168  public static bool ContainsFragment(this ISymbolicExpressionTreeNode root, IFragment fragment, SymbolicExpressionTreeNodeSimilarityComparer comparer) {
     169    return FindMatches(root, fragment.Root, comparer).Any();
     170  }
     171  public static IEnumerable<ISymbolicExpressionTreeNode> FindMatches(ISymbolicExpressionTree tree, ISymbolicExpressionTreeNode fragment, SymbolicExpressionTreeNodeSimilarityComparer comparer) {
     172    return FindMatches(tree.Root, fragment, comparer);
     173  }
     174
     175  public static IEnumerable<ISymbolicExpressionTreeNode>
    196176    FindMatches(ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeNode fragment, SymbolicExpressionTreeNodeSimilarityComparer comp) {
    197       var matches = new List<ISymbolicExpressionTreeNode>();
    198       root.ForEachNodePostfix(node => {
    199         if (Match(node, fragment, comp) == fragment.GetLength()) matches.Add(node);
    200       });
    201       return matches;
    202     }
    203 
    204     ///<summary>
    205     /// Finds the longest common subsequence in quadratic time and linear space
    206     /// Variant of:
    207     /// D . S. Hirschberg. A linear space algorithm for or computing maximal common subsequences. 1975.
    208     /// http://dl.acm.org/citation.cfm?id=360861
    209     /// </summary>
    210     /// <returns>Number of pairs that were matched</returns>
    211     public static int
    212     Match(ISymbolicExpressionTreeNode a, ISymbolicExpressionTreeNode b, SymbolicExpressionTreeNodeSimilarityComparer comp) {
    213       if (!comp.Equals(a, b))
    214         return 0;
    215 
    216       int m = a.SubtreeCount;
    217       int n = b.SubtreeCount;
    218       if (m == 0 || n == 0) return 1;
    219 
    220       var matrix = new int[m + 1, n + 1];
    221       for (int i = 1; i <= m; ++i)
    222         for (int j = 1; j <= n; ++j) {
    223           var ai = a.GetSubtree(i - 1);
    224           var bj = b.GetSubtree(j - 1);
    225           int match = Match(ai, bj, comp);
    226           matrix[i, j] = Math.Max(Math.Max(matrix[i, j - 1], matrix[i - 1, j]), matrix[i - 1, j - 1] + match);
    227         }
    228       return matrix[m, n] + 1;
    229     }
    230 
    231     public static int
    232     LCS(ISymbolicExpressionTreeNode a, ISymbolicExpressionTreeNode b, SymbolicExpressionTreeNodeSimilarityComparer comp) {
    233       var nodesA = a.IterateNodesPrefix().ToList();
    234       var nodesB = b.IterateNodesPrefix().ToList();
    235       int m = nodesA.Count;
    236       int n = nodesB.Count;
    237       var matrix = new int[m + 1, n + 1];
    238       for (int i = 1; i <= m; ++i) {
    239         for (int j = 1; j <= n; ++j) {
    240           int w = comp.Equals(a, b) ? 1 : 0;
    241           matrix[i, j] = Math.Max(Math.Max(matrix[i, j - 1], matrix[i - 1, j]), matrix[i - 1, j - 1] + w);
    242         }
    243       }
    244       return matrix[m, n];
    245     }
    246 
    247     public static void RenderTree(TextWriter writer, ISymbolicExpressionTree tree) {
    248       RenderNode(writer, tree.Root, string.Empty);
    249     }
    250 
    251     public static void RenderNode(TextWriter writer, ISymbolicExpressionTreeNode node, string prefix) {
    252       string label;
    253       if (node is VariableTreeNode) {
    254         var variable = node as VariableTreeNode;
    255         label = string.Concat(string.Format("{0:0.000}", variable.Weight), '·', variable.VariableName);
    256       } else if (node is ConstantTreeNode) {
    257         var constant = node as ConstantTreeNode;
    258         label = string.Format("{0:0.000}", constant.Value);
    259       } else {
    260         label = node.Symbol.ToString();
    261       }
    262 
    263       writer.Write(label);
    264       if (node.SubtreeCount > 0) {
    265         char connector, extender = ' ';
    266         var padding = prefix + new string(' ', label.Length);
    267         for (int i = 0; i != node.SubtreeCount; ++i) {
    268           if (i == 0) {
    269             if (node.SubtreeCount > 1) {
    270               connector = RenderChars.JunctionDown;
    271               extender = RenderChars.VerticalLine;
    272             } else {
    273               connector = RenderChars.HorizontalLine;
    274               extender = ' ';
    275             }
    276           } else {
    277             writer.Write(padding);
    278             if (i == node.SubtreeCount - 1) {
    279               connector = RenderChars.CornerRight;
    280               extender = ' ';
    281             } else {
    282               connector = RenderChars.JunctionRight;
    283               extender = RenderChars.VerticalLine;
    284             }
    285           }
    286           writer.Write(string.Concat(connector, RenderChars.HorizontalLine));
    287           var newPrefix = string.Concat(padding, extender, ' ');
    288           RenderNode(writer, node.GetSubtree(i), newPrefix);
    289         }
    290       } else
    291         writer.WriteLine();
    292     }
    293   }
    294 
    295   // helper class providing characters for displaying a tree in the console
    296   public static class RenderChars {
    297     public const char JunctionDown = '┬';
    298     public const char HorizontalLine = '─';
    299     public const char VerticalLine = '│';
    300     public const char JunctionRight = '├';
    301     public const char CornerRight = '└';
     177    var fragmentLength = fragment.GetLength();
     178    // below, we use ">=" for Match(n, fragment, comp) >= fragmentLength because in case of relaxed conditions,
     179    // we can have multiple matches of the same node
     180    return root.IterateNodesBreadth().Where(n => n.GetLength() >= fragmentLength && Match(n, fragment, comp) == fragmentLength);
     181  }
     182
     183  ///<summary>
     184  /// Finds the longest common subsequence in quadratic time and linear space
     185  /// Variant of:
     186  /// D. S. Hirschberg. A linear space algorithm for or computing maximal common subsequences. 1975.
     187  /// http://dl.acm.org/citation.cfm?id=360861
     188  /// </summary>
     189  /// <returns>Number of pairs that were matched</returns>
     190  public static int Match(ISymbolicExpressionTreeNode a, ISymbolicExpressionTreeNode b, SymbolicExpressionTreeNodeSimilarityComparer comp) {
     191    if (!comp.Equals(a, b)) return 0;
     192    int m = a.SubtreeCount;
     193    int n = b.SubtreeCount;
     194    if (m == 0 || n == 0) return 1;
     195    var matrix = new int[m + 1, n + 1];
     196    for (int i = 1; i <= m; ++i) {
     197      var ai = a.GetSubtree(i - 1);
     198      for (int j = 1; j <= n; ++j) {
     199        var bj = b.GetSubtree(j - 1);
     200        int match = Match(ai, bj, comp);
     201        matrix[i, j] = Math.Max(Math.Max(matrix[i, j - 1], matrix[i - 1, j]), matrix[i - 1, j - 1] + match);
     202      }
     203    }
     204    return matrix[m, n] + 1;
    302205  }
    303206}
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeSimplifier.cs

    r8213 r9241  
    5252    private GreaterThan gtSymbol = new GreaterThan();
    5353    private LessThan ltSymbol = new LessThan();
     54    private Integral integralSymbol = new Integral();
     55    private LaggedVariable laggedVariableSymbol = new LaggedVariable();
     56    private TimeLag timeLagSymbol = new TimeLag();
    5457
    5558    public ISymbolicExpressionTree Simplify(ISymbolicExpressionTree originalTree) {
     
    182185    private bool IsConstant(ISymbolicExpressionTreeNode node) {
    183186      return node.Symbol is Constant;
     187    }
     188
     189    // dynamic
     190    private bool IsTimeLag(ISymbolicExpressionTreeNode node) {
     191      return node.Symbol is TimeLag;
     192    }
     193    private bool IsIntegral(ISymbolicExpressionTreeNode node) {
     194      return node.Symbol is Integral;
    184195    }
    185196
     
    234245      } else if (IsNot(original)) {
    235246        return SimplifyNot(original);
     247      } else if (IsTimeLag(original)) {
     248        return SimplifyTimeLag(original);
     249      } else if (IsIntegral(original)) {
     250        return SimplifyIntegral(original);
    236251      } else {
    237252        return SimplifyAny(original);
     
    376391      return MakePower(GetSimplifiedTree(original.GetSubtree(0)), GetSimplifiedTree(original.GetSubtree(1)));
    377392    }
     393    private ISymbolicExpressionTreeNode SimplifyTimeLag(ISymbolicExpressionTreeNode original) {
     394      var laggedTreeNode = original as ILaggedTreeNode;
     395      var simplifiedSubtree = GetSimplifiedTree(original.GetSubtree(0));
     396      if (!ContainsVariableCondition(simplifiedSubtree)) {
     397        return AddLagToDynamicNodes(simplifiedSubtree, laggedTreeNode.Lag);
     398      } else {
     399        return MakeTimeLag(simplifiedSubtree, laggedTreeNode.Lag);
     400      }
     401    }
     402    private ISymbolicExpressionTreeNode SimplifyIntegral(ISymbolicExpressionTreeNode original) {
     403      var laggedTreeNode = original as ILaggedTreeNode;
     404      var simplifiedSubtree = GetSimplifiedTree(original.GetSubtree(0));
     405      if (IsConstant(simplifiedSubtree)) {
     406        return GetSimplifiedTree(MakeProduct(simplifiedSubtree, MakeConstant(-laggedTreeNode.Lag)));
     407      } else {
     408        return MakeIntegral(simplifiedSubtree, laggedTreeNode.Lag);
     409      }
     410    }
     411
    378412    #endregion
    379413
    380414    #region low level tree restructuring
     415    private ISymbolicExpressionTreeNode MakeTimeLag(ISymbolicExpressionTreeNode subtree, int lag) {
     416      if (lag == 0) return subtree;
     417      if (IsConstant(subtree)) return subtree;
     418      var lagNode = (LaggedTreeNode)timeLagSymbol.CreateTreeNode();
     419      lagNode.Lag = lag;
     420      lagNode.AddSubtree(subtree);
     421      return lagNode;
     422    }
     423
     424    private ISymbolicExpressionTreeNode MakeIntegral(ISymbolicExpressionTreeNode subtree, int lag) {
     425      if (lag == 0) return subtree;
     426      else if (lag == -1 || lag == 1) {
     427        return MakeSum(subtree, AddLagToDynamicNodes((ISymbolicExpressionTreeNode)subtree.Clone(), lag));
     428      } else {
     429        var node = (LaggedTreeNode)integralSymbol.CreateTreeNode();
     430        node.Lag = lag;
     431        node.AddSubtree(subtree);
     432        return node;
     433      }
     434    }
     435
    381436    private ISymbolicExpressionTreeNode MakeNot(ISymbolicExpressionTreeNode t) {
    382437      if (IsConstant(t)) {
     
    847902
    848903    #region helper functions
     904    private bool ContainsVariableCondition(ISymbolicExpressionTreeNode node) {
     905      if (node.Symbol is VariableCondition) return true;
     906      foreach (var subtree in node.Subtrees)
     907        if (ContainsVariableCondition(subtree)) return true;
     908      return false;
     909    }
     910
     911    private ISymbolicExpressionTreeNode AddLagToDynamicNodes(ISymbolicExpressionTreeNode node, int lag) {
     912      var laggedTreeNode = node as ILaggedTreeNode;
     913      var variableNode = node as VariableTreeNode;
     914      var variableConditionNode = node as VariableConditionTreeNode;
     915      if (laggedTreeNode != null)
     916        laggedTreeNode.Lag += lag;
     917      else if (variableNode != null) {
     918        var laggedVariableNode = (LaggedVariableTreeNode)laggedVariableSymbol.CreateTreeNode();
     919        laggedVariableNode.Lag = lag;
     920        laggedVariableNode.VariableName = variableNode.VariableName;
     921        return laggedVariableNode;
     922      } else if (variableConditionNode != null) {
     923        throw new NotSupportedException("Removal of time lags around variable condition symbols is not allowed.");
     924      }
     925      var subtrees = new List<ISymbolicExpressionTreeNode>(node.Subtrees);
     926      while (node.SubtreeCount > 0) node.RemoveSubtree(0);
     927      foreach (var subtree in subtrees) {
     928        node.AddSubtree(AddLagToDynamicNodes(subtree, lag));
     929      }
     930      return node;
     931    }
    849932
    850933    private bool AreSameVariable(ISymbolicExpressionTreeNode a, ISymbolicExpressionTreeNode b) {
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisModel.cs

    r7259 r9241  
    2020#endregion
    2121
     22using System;
    2223using System.Drawing;
    2324using HeuristicLab.Common;
     
    6667      this.interpreter = interpreter;
    6768    }
     69
     70    #region Scaling
     71    protected void Scale(IDataAnalysisProblemData problemData, string targetVariable) {
     72      var dataset = problemData.Dataset;
     73      var rows = problemData.TrainingIndices;
     74      var estimatedValues = Interpreter.GetSymbolicExpressionTreeValues(SymbolicExpressionTree, dataset, rows);
     75      var targetValues = dataset.GetDoubleValues(targetVariable, rows);
     76
     77      var linearScalingCalculator = new OnlineLinearScalingParameterCalculator();
     78      var targetValuesEnumerator = targetValues.GetEnumerator();
     79      var estimatedValuesEnumerator = estimatedValues.GetEnumerator();
     80      while (targetValuesEnumerator.MoveNext() & estimatedValuesEnumerator.MoveNext()) {
     81        double target = targetValuesEnumerator.Current;
     82        double estimated = estimatedValuesEnumerator.Current;
     83        if (!double.IsNaN(estimated) && !double.IsInfinity(estimated))
     84          linearScalingCalculator.Add(estimated, target);
     85      }
     86      if (linearScalingCalculator.ErrorState == OnlineCalculatorError.None && (targetValuesEnumerator.MoveNext() || estimatedValuesEnumerator.MoveNext()))
     87        throw new ArgumentException("Number of elements in target and estimated values enumeration do not match.");
     88
     89      double alpha = linearScalingCalculator.Alpha;
     90      double beta = linearScalingCalculator.Beta;
     91      if (linearScalingCalculator.ErrorState != OnlineCalculatorError.None) return;
     92
     93      ConstantTreeNode alphaTreeNode = null;
     94      ConstantTreeNode betaTreeNode = null;
     95      // check if model has been scaled previously by analyzing the structure of the tree
     96      var startNode = SymbolicExpressionTree.Root.GetSubtree(0);
     97      if (startNode.GetSubtree(0).Symbol is Addition) {
     98        var addNode = startNode.GetSubtree(0);
     99        if (addNode.SubtreeCount == 2 && addNode.GetSubtree(0).Symbol is Multiplication && addNode.GetSubtree(1).Symbol is Constant) {
     100          alphaTreeNode = addNode.GetSubtree(1) as ConstantTreeNode;
     101          var mulNode = addNode.GetSubtree(0);
     102          if (mulNode.SubtreeCount == 2 && mulNode.GetSubtree(1).Symbol is Constant) {
     103            betaTreeNode = mulNode.GetSubtree(1) as ConstantTreeNode;
     104          }
     105        }
     106      }
     107      // if tree structure matches the structure necessary for linear scaling then reuse the existing tree nodes
     108      if (alphaTreeNode != null && betaTreeNode != null) {
     109        betaTreeNode.Value *= beta;
     110        alphaTreeNode.Value *= beta;
     111        alphaTreeNode.Value += alpha;
     112      } else {
     113        var mainBranch = startNode.GetSubtree(0);
     114        startNode.RemoveSubtree(0);
     115        var scaledMainBranch = MakeSum(MakeProduct(mainBranch, beta), alpha);
     116        startNode.AddSubtree(scaledMainBranch);
     117      }
     118    }
     119
     120    private static ISymbolicExpressionTreeNode MakeSum(ISymbolicExpressionTreeNode treeNode, double alpha) {
     121      if (alpha.IsAlmost(0.0)) {
     122        return treeNode;
     123      } else {
     124        var addition = new Addition();
     125        var node = addition.CreateTreeNode();
     126        var alphaConst = MakeConstant(alpha);
     127        node.AddSubtree(treeNode);
     128        node.AddSubtree(alphaConst);
     129        return node;
     130      }
     131    }
     132
     133    private static ISymbolicExpressionTreeNode MakeProduct(ISymbolicExpressionTreeNode treeNode, double beta) {
     134      if (beta.IsAlmost(1.0)) {
     135        return treeNode;
     136      } else {
     137        var multipliciation = new Multiplication();
     138        var node = multipliciation.CreateTreeNode();
     139        var betaConst = MakeConstant(beta);
     140        node.AddSubtree(treeNode);
     141        node.AddSubtree(betaConst);
     142        return node;
     143      }
     144    }
     145
     146    private static ISymbolicExpressionTreeNode MakeConstant(double c) {
     147      var node = (ConstantTreeNode)(new Constant()).CreateTreeNode();
     148      node.Value = c;
     149      return node;
     150    }
     151    #endregion
    68152  }
    69153}
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisMultiObjectiveProblem.cs

    r7259 r9241  
    3030namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    3131  [StorableClass]
    32   public abstract class SymbolicDataAnalysisMultiObjectiveProblem<T, U, V> : SymbolicDataAnalysisProblem<T, U, V>, IMultiObjectiveHeuristicOptimizationProblem
     32  public abstract class SymbolicDataAnalysisMultiObjectiveProblem<T, U, V> : SymbolicDataAnalysisProblem<T, U, V>, ISymbolicDataAnalysisMultiObjectiveProblem
    3333    where T : class,IDataAnalysisProblemData
    3434    where U : class, ISymbolicDataAnalysisMultiObjectiveEvaluator<T>
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisProblem.cs

    r8557 r9241  
    5353    private const string FitnessCalculationPartitionParameterName = "FitnessCalculationPartition";
    5454    private const string ValidationPartitionParameterName = "ValidationPartition";
     55    private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";
    5556
    5657    private const string ProblemDataParameterDescription = "";
     
    6465    private const string FitnessCalculationPartitionParameterDescription = "The partition of the problem data training partition, that should be used to calculate the fitness of an individual.";
    6566    private const string ValidationPartitionParameterDescription = "The partition of the problem data training partition, that should be used to select the best model from (optional).";
     67    private const string ApplyLinearScalingParameterDescription = "Flag that indicates if the individual should be linearly scaled before evaluating.";
    6668    #endregion
    6769
     
    100102      get { return (IFixedValueParameter<IntRange>)Parameters[ValidationPartitionParameterName]; }
    101103    }
     104    public IFixedValueParameter<BoolValue> ApplyLinearScalingParameter {
     105      get { return (IFixedValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }
     106    }
    102107    #endregion
    103108
     
    144149    public IntRange ValidationPartition {
    145150      get { return ValidationPartitionParameter.Value; }
     151    }
     152    public BoolValue ApplyLinearScaling {
     153      get { return ApplyLinearScalingParameter.Value; }
    146154    }
    147155    #endregion
     
    151159    [StorableHook(HookType.AfterDeserialization)]
    152160    private void AfterDeserialization() {
     161      if (!Parameters.ContainsKey(ApplyLinearScalingParameterName)) {
     162        Parameters.Add(new FixedValueParameter<BoolValue>(ApplyLinearScalingParameterName, ApplyLinearScalingParameterDescription, new BoolValue(false)));
     163        ApplyLinearScalingParameter.Hidden = true;
     164
     165        //it is assumed that for all symbolic regression algorithms linear scaling was set to true
     166        //there is no possibility to determine the previous value of the parameter as it was stored in the evaluator
     167        if (GetType().Name.Contains("SymbolicRegression"))
     168          ApplyLinearScaling.Value = true;
     169      }
     170
    153171      RegisterEventHandlers();
    154172    }
     
    170188      Parameters.Add(new FixedValueParameter<IntRange>(ValidationPartitionParameterName, ValidationPartitionParameterDescription));
    171189      Parameters.Add(new FixedValueParameter<PercentValue>(RelativeNumberOfEvaluatedSamplesParameterName, RelativeNumberOfEvaluatedSamplesParameterDescription, new PercentValue(1)));
     190      Parameters.Add(new FixedValueParameter<BoolValue>(ApplyLinearScalingParameterName, ApplyLinearScalingParameterDescription, new BoolValue(false)));
    172191
    173192      SymbolicExpressionTreeInterpreterParameter.Hidden = true;
    174193      MaximumFunctionArgumentsParameter.Hidden = true;
    175194      MaximumFunctionDefinitionsParameter.Hidden = true;
     195      ApplyLinearScalingParameter.Hidden = true;
    176196
    177197      SymbolicExpressionTreeGrammar = new TypeCoherentExpressionGrammar();
     
    191211      SymbolicExpressionTreeGrammar.MaximumFunctionDefinitions = MaximumFunctionDefinitions.Value;
    192212      foreach (var varSymbol in SymbolicExpressionTreeGrammar.Symbols.OfType<HeuristicLab.Problems.DataAnalysis.Symbolic.Variable>()) {
    193         if (!varSymbol.Fixed) varSymbol.VariableNames = ProblemData.AllowedInputVariables;
     213        if (!varSymbol.Fixed) {
     214          varSymbol.AllVariableNames = ProblemData.InputVariables.Select(x => x.Value);
     215          varSymbol.VariableNames = ProblemData.AllowedInputVariables;
     216        }
    194217      }
    195218      foreach (var varSymbol in SymbolicExpressionTreeGrammar.Symbols.OfType<HeuristicLab.Problems.DataAnalysis.Symbolic.VariableCondition>()) {
    196         if (!varSymbol.Fixed) varSymbol.VariableNames = ProblemData.AllowedInputVariables;
     219        if (!varSymbol.Fixed) {
     220          varSymbol.AllVariableNames = ProblemData.InputVariables.Select(x => x.Value);
     221          varSymbol.VariableNames = ProblemData.AllowedInputVariables;
     222        }
    197223      }
    198224    }
     
    274300
    275301      foreach (var op in operators.OfType<ISymbolicExpressionTreeGrammarBasedOperator>()) {
    276         op.SymbolicExpressionTreeGrammarParameter.ActualName = SymbolicExpressionTreeGrammarParameterName;
     302        op.SymbolicExpressionTreeGrammarParameter.ActualName = SymbolicExpressionTreeGrammarParameter.Name;
    277303      }
    278304      foreach (var op in operators.OfType<ISymbolicExpressionTreeSizeConstraintOperator>()) {
    279         op.MaximumSymbolicExpressionTreeDepthParameter.ActualName = MaximumSymbolicExpressionTreeDepthParameterName;
    280         op.MaximumSymbolicExpressionTreeLengthParameter.ActualName = MaximumSymbolicExpressionTreeLengthParameterName;
     305        op.MaximumSymbolicExpressionTreeDepthParameter.ActualName = MaximumSymbolicExpressionTreeDepthParameter.Name;
     306        op.MaximumSymbolicExpressionTreeLengthParameter.ActualName = MaximumSymbolicExpressionTreeLengthParameter.Name;
    281307      }
    282308      foreach (var op in operators.OfType<ISymbolicExpressionTreeArchitectureAlteringOperator>()) {
    283         op.MaximumFunctionArgumentsParameter.ActualName = MaximumFunctionArgumentsParameterName;
    284         op.MaximumFunctionDefinitionsParameter.ActualName = MaximumFunctionDefinitionsParameterName;
     309        op.MaximumFunctionArgumentsParameter.ActualName = MaximumFunctionArgumentsParameter.Name;
     310        op.MaximumFunctionDefinitionsParameter.ActualName = MaximumFunctionDefinitionsParameter.Name;
    285311      }
    286312      foreach (var op in operators.OfType<ISymbolicDataAnalysisEvaluator<T>>()) {
     
    289315        op.EvaluationPartitionParameter.ActualName = FitnessCalculationPartitionParameter.Name;
    290316        op.RelativeNumberOfEvaluatedSamplesParameter.ActualName = RelativeNumberOfEvaluatedSamplesParameter.Name;
     317        op.ApplyLinearScalingParameter.ActualName = ApplyLinearScalingParameter.Name;
    291318      }
    292319      foreach (var op in operators.OfType<ISymbolicExpressionTreeCrossover>()) {
     
    300327        op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    301328      }
     329      foreach (var op in operators.OfType<ISymbolicDataAnalysisSingleObjectiveAnalyzer>()) {
     330        op.ApplyLinearScalingParameter.ActualName = ApplyLinearScalingParameter.Name;
     331      }
     332      foreach (var op in operators.OfType<ISymbolicDataAnalysisMultiObjectiveAnalyzer>()) {
     333        op.ApplyLinearScalingParameter.ActualName = ApplyLinearScalingParameter.Name;
     334      }
    302335      foreach (var op in operators.OfType<ISymbolicDataAnalysisAnalyzer>()) {
    303336        op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
     
    308341      }
    309342      foreach (var op in operators.OfType<ISymbolicDataAnalysisInterpreterOperator>()) {
    310         op.SymbolicDataAnalysisTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameterName;
     343        op.SymbolicDataAnalysisTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name;
    311344      }
    312345      foreach (var op in operators.OfType<ISymbolicDataAnalysisExpressionCrossover<T>>()) {
    313         op.EvaluationPartitionParameter.ActualName = FitnessCalculationPartitionParameterName;
    314       }
    315       foreach (var op in operators.OfType<ISymbolicDataAnalysisExpressionCrossover<T>>()) {
     346        op.EvaluationPartitionParameter.ActualName = FitnessCalculationPartitionParameter.Name;
    316347        op.ProblemDataParameter.ActualName = ProblemDataParameter.Name;
    317348        op.EvaluationPartitionParameter.ActualName = FitnessCalculationPartitionParameter.Name;
     
    331362      Description = data.Description;
    332363      ProblemData = data;
    333       OnReset();
    334364    }
    335365
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisSingleObjectiveProblem.cs

    r7259 r9241  
    3131namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    3232  [StorableClass]
    33   public abstract class SymbolicDataAnalysisSingleObjectiveProblem<T, U, V> : SymbolicDataAnalysisProblem<T, U, V>, ISingleObjectiveHeuristicOptimizationProblem
     33  public abstract class SymbolicDataAnalysisSingleObjectiveProblem<T, U, V> : SymbolicDataAnalysisProblem<T, U, V>, ISymbolicDataAnalysisSingleObjectiveProblem
    3434    where T : class,IDataAnalysisProblemData
    3535    where U : class, ISymbolicDataAnalysisSingleObjectiveEvaluator<T>
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/Constant.cs

    r7259 r9241  
    2828  [StorableClass]
    2929  [Item("Constant", "Represents a constant value.")]
    30   public sealed class Constant : Symbol {
     30  public class Constant : Symbol {
    3131    #region Properties
    3232    [Storable]
     
    100100
    101101    [StorableConstructor]
    102     private Constant(bool deserializing) : base(deserializing) { }
    103     private Constant(Constant original, Cloner cloner)
     102    protected Constant(bool deserializing) : base(deserializing) { }
     103    protected Constant(Constant original, Cloner cloner)
    104104      : base(original, cloner) {
    105105      minValue = original.minValue;
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/ConstantTreeNode.cs

    r7259 r9241  
    2727namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    2828  [StorableClass]
    29   public sealed class ConstantTreeNode : SymbolicExpressionTreeTerminalNode {
     29  public class ConstantTreeNode : SymbolicExpressionTreeTerminalNode {
    3030    public new Constant Symbol {
    3131      get { return (Constant)base.Symbol; }
     
    3434    private double constantValue;
    3535    [Storable]
    36     public double Value {
     36    public virtual double Value {
    3737      get { return constantValue; }
    3838      set { constantValue = value; }
     
    4040
    4141    [StorableConstructor]
    42     private ConstantTreeNode(bool deserializing) : base(deserializing) { }
     42    protected ConstantTreeNode(bool deserializing) : base(deserializing) { }
    4343
    44     private ConstantTreeNode(ConstantTreeNode original, Cloner cloner)
     44    protected ConstantTreeNode(ConstantTreeNode original, Cloner cloner)
    4545      : base(original, cloner) {
    4646      constantValue = original.constantValue;
    4747    }
    4848
    49     private ConstantTreeNode() : base() { }
     49    protected ConstantTreeNode() : base() { }
    5050    public ConstantTreeNode(Constant constantSymbol) : base(constantSymbol) { }
    5151
     
    5555      }
    5656    }
    57     public override void ResetLocalParameters(IRandom random) {
     57    public virtual void ResetLocalParameters(IRandom random) {
    5858      base.ResetLocalParameters(random);
    5959      var range = Symbol.MaxValue - Symbol.MinValue;
     
    6161    }
    6262
    63     public override void ShakeLocalParameters(IRandom random, double shakingFactor) {
     63    public virtual void ShakeLocalParameters(IRandom random, double shakingFactor) {
    6464      base.ShakeLocalParameters(random, shakingFactor);
    6565      // 50% additive & 50% multiplicative
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/LaggedSymbol.cs

    r5809 r9241  
    1 using HeuristicLab.Common;
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using HeuristicLab.Common;
    223using HeuristicLab.Core;
    324using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/LaggedVariable.cs

    r7259 r9241  
    2727  [StorableClass]
    2828  [Item("LaggedVariable", "Represents a variable value with a time offset.")]
    29   public sealed class LaggedVariable : Variable {
     29  public class LaggedVariable : Variable {
    3030    [Storable]
    3131    private int minLag;
     
    4141    }
    4242    [StorableConstructor]
    43     private LaggedVariable(bool deserializing) : base(deserializing) { }
    44     private LaggedVariable(LaggedVariable original, Cloner cloner)
     43    protected LaggedVariable(bool deserializing) : base(deserializing) { }
     44    protected LaggedVariable(LaggedVariable original, Cloner cloner)
    4545      : base(original, cloner) {
    4646      minLag = original.minLag;
    4747      maxLag = original.maxLag;
    4848    }
    49     public LaggedVariable()
    50       : base("LaggedVariable", "Represents a variable value with a time offset.") {
    51       minLag = -1; maxLag = -1;
     49    public LaggedVariable() : this("LaggedVariable", "Represents a variable value with a time offset.") { }
     50    protected LaggedVariable(string name, string description)
     51      : base(name, description) {
     52      MinLag = -1;
     53      MaxLag = -1;
    5254    }
    5355
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/LaggedVariableTreeNode.cs

    r7259 r9241  
    3737    }
    3838
     39    public override bool HasLocalParameters {
     40      get { return true; }
     41    }
     42
    3943    [StorableConstructor]
    4044    private LaggedVariableTreeNode(bool deserializing) : base(deserializing) { }
     
    4347      lag = original.lag;
    4448    }
    45     private LaggedVariableTreeNode() { }
    4649
    4750    public LaggedVariableTreeNode(LaggedVariable variableSymbol) : base(variableSymbol) { }
    4851
    49     public override bool HasLocalParameters {
    50       get {
    51         return true;
    52       }
    53     }
    5452
    5553    public override void ResetLocalParameters(IRandom random) {
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/Variable.cs

    r7259 r9241  
    101101    }
    102102
     103    private List<string> allVariableNames;
     104    [Storable]
     105    public IEnumerable<string> AllVariableNames {
     106      get { return allVariableNames; }
     107      set {
     108        if (value == null) throw new ArgumentNullException();
     109        allVariableNames.Clear();
     110        allVariableNames.AddRange(value);
     111      }
     112    }
     113
     114    public override bool Enabled {
     115      get {
     116        if (variableNames.Count == 0) return false;
     117        return base.Enabled;
     118      }
     119      set {
     120        if (variableNames.Count == 0) base.Enabled = false;
     121        else base.Enabled = value;
     122      }
     123    }
     124
    103125    private const int minimumArity = 0;
    104126    private const int maximumArity = 0;
     
    112134    #endregion
    113135
     136    [StorableHook(HookType.AfterDeserialization)]
     137    private void AfterDeserialization() {
     138      if (allVariableNames == null || (allVariableNames.Count == 0 && variableNames.Count > 0)) {
     139        allVariableNames = variableNames;
     140      }
     141    }
     142
    114143    [StorableConstructor]
    115144    protected Variable(bool deserializing)
    116145      : base(deserializing) {
    117146      variableNames = new List<string>();
     147      allVariableNames = new List<string>();
    118148    }
    119149    protected Variable(Variable original, Cloner cloner)
     
    122152      weightSigma = original.weightSigma;
    123153      variableNames = new List<string>(original.variableNames);
     154      allVariableNames = new List<string>(original.allVariableNames);
    124155      weightManipulatorMu = original.weightManipulatorMu;
    125156      weightManipulatorSigma = original.weightManipulatorSigma;
     
    135166      multiplicativeWeightManipulatorSigma = 0.03;
    136167      variableNames = new List<string>();
    137     }
    138 
    139     protected override void OnChanged(EventArgs e) {
    140       if (@Fixed) {
    141         weightManipulatorMu = 1;
    142         weightManipulatorSigma = 0;
    143         weightMu = 1;
    144         weightSigma = 0;
    145         multiplicativeWeightManipulatorSigma = 0;
    146       }
    147       base.OnChanged(e);
     168      allVariableNames = new List<string>();
    148169    }
    149170
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/VariableCondition.cs

    r8099 r9241  
    8686      set {
    8787        if (value == null) throw new ArgumentNullException();
    88         variableNames = new List<string>(value);
     88        variableNames.Clear();
     89        variableNames.AddRange(value);
    8990        OnChanged(EventArgs.Empty);
     91      }
     92    }
     93
     94    private List<string> allVariableNames;
     95    [Storable]
     96    public IEnumerable<string> AllVariableNames {
     97      get { return allVariableNames; }
     98      set {
     99        if (value == null) throw new ArgumentNullException();
     100        allVariableNames.Clear();
     101        allVariableNames.AddRange(value);
     102        VariableNames = value;
    90103      }
    91104    }
     
    151164
    152165    #region persistence and cloning
     166    [StorableHook(HookType.AfterDeserialization)]
     167    private void AfterDeserialization() {
     168      if (allVariableNames == null || (allVariableNames.Count == 0 && variableNames.Count > 0)) {
     169        allVariableNames = variableNames;
     170      }
     171    }
     172
    153173    [StorableConstructor]
    154     private VariableCondition(bool deserializing) : base(deserializing) { }
     174    private VariableCondition(bool deserializing)
     175      : base(deserializing) {
     176      variableNames = new List<string>();
     177      allVariableNames = new List<string>();
     178    }
    155179    private VariableCondition(VariableCondition original, Cloner cloner)
    156180      : base(original, cloner) {
     
    161185
    162186      variableNames = new List<string>(original.variableNames);
     187      allVariableNames = new List<string>(original.allVariableNames);
    163188
    164189      slopeInitializerMu = original.slopeInitializerMu;
     
    181206
    182207      variableNames = new List<string>();
     208      allVariableNames = new List<string>();
    183209
    184210      slopeInitializerMu = 0.0;
Note: See TracChangeset for help on using the changeset viewer.