Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/23/12 16:05:57 (13 years ago)
Author:
mkommend
Message:

#1682: Integrated new gp crossovers into the trunk and corrected the parameter wiring.

Location:
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4
Files:
5 edited
9 copied

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/MultiSymbolicDataAnalysisExpressionCrossover.cs

    r7503 r7506  
    3333using HeuristicLab.PluginInfrastructure;
    3434
    35 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Crossovers {
     35namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    3636  [Item("MultiSymbolicDataAnalysisExpressionCrossover", "Randomly selects and applies one of its crossovers every time it is called.")]
    3737  public class MultiSymbolicDataAnalysisExpressionCrossover<T> : StochasticMultiBranch<ISymbolicExpressionTreeCrossover>,
    38     ISymbolicDataAnalysisExpressionCrossover<T>,
    39     ISymbolicExpressionTreeSizeConstraintOperator,
    40     ISymbolicExpressionTreeGrammarBasedOperator where T : class, IDataAnalysisProblemData {
     38    ISymbolicDataAnalysisExpressionCrossover<T> where T : class, IDataAnalysisProblemData {
     39    private const string ParentsParameterName = "Parents";
     40    private const string ChildParameterName = "Child";
    4141    private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength";
    4242    private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth";
    43     private const string SymbolicExpressionTreeGrammarParameterName = "SymbolicExpressionTreeGrammar";
    44     private const string ClonedSymbolicExpressionTreeGrammarParameterName = "ClonedSymbolicExpressionTreeGrammar";
     43    private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicExpressionTreeInterpreter";
    4544    private const string EvaluatorParameterName = "Evaluator";
    4645    private const string SymbolicDataAnalysisEvaluationPartitionParameterName = "EvaluationPartition";
    47     private const string ParentsParameterName = "Parents";
    48     private const string ChildParameterName = "Child";
     46    private const string RelativeNumberOfEvaluatedSamplesParameterName = "RelativeNumberOfEvaluatedSamples";
     47    private const string ProblemDataParameterName = "ProblemData";
     48
    4949
    5050    public override bool CanChangeName {
     
    5656
    5757    #region parameter properties
     58    public ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> SymbolicDataAnalysisTreeInterpreterParameter {
     59      get { return (ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>)Parameters[SymbolicDataAnalysisTreeInterpreterParameterName]; }
     60    }
    5861    public ILookupParameter<ItemArray<ISymbolicExpressionTree>> ParentsParameter {
    5962      get { return (ScopeTreeLookupParameter<ISymbolicExpressionTree>)Parameters[ParentsParameterName]; }
     
    6871      get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeDepthParameterName]; }
    6972    }
    70     public IValueLookupParameter<ISymbolicExpressionGrammar> SymbolicExpressionTreeGrammarParameter {
    71       get { return (IValueLookupParameter<ISymbolicExpressionGrammar>)Parameters[SymbolicExpressionTreeGrammarParameterName]; }
    72     }
    73     public ILookupParameter<ISymbolicExpressionGrammar> ClonedSymbolicExpressionTreeGrammarParameter {
    74       get { return (ILookupParameter<ISymbolicExpressionGrammar>)Parameters[ClonedSymbolicExpressionTreeGrammarParameterName]; }
    75     }
    7673    public ILookupParameter<ISymbolicDataAnalysisSingleObjectiveEvaluator<T>> EvaluatorParameter {
    7774      get { return (ILookupParameter<ISymbolicDataAnalysisSingleObjectiveEvaluator<T>>)Parameters[EvaluatorParameterName]; }
    7875    }
    79     public IValueLookupParameter<IntRange> SymbolicDataAnalysisEvaluationPartitionParameter {
     76    public IValueLookupParameter<IntRange> EvaluationPartitionParameter {
    8077      get { return (IValueLookupParameter<IntRange>)Parameters[SymbolicDataAnalysisEvaluationPartitionParameterName]; }
     78    }
     79    public IValueLookupParameter<PercentValue> RelativeNumberOfEvaluatedSamplesParameter {
     80      get { return (IValueLookupParameter<PercentValue>)Parameters[RelativeNumberOfEvaluatedSamplesParameterName]; }
     81    }
     82    public IValueLookupParameter<T> ProblemDataParameter {
     83      get { return (IValueLookupParameter<T>)Parameters[ProblemDataParameterName]; }
    8184    }
    8285    #endregion
     
    8891    public MultiSymbolicDataAnalysisExpressionCrossover()
    8992      : base() {
     93      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."));
     94      Parameters.Add(new ValueLookupParameter<T>(ProblemDataParameterName, "The problem data on which the symbolic data analysis solution should be evaluated."));
     95      Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The interpreter that should be used to calculate the output values of the symbolic data analysis tree."));
    9096      Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName, "The maximal length (number of nodes) of the symbolic expression tree."));
    9197      Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, "The maximal depth of the symbolic expression tree (a tree with one node has depth = 0)."));
    92       Parameters.Add(new ValueLookupParameter<ISymbolicExpressionGrammar>(SymbolicExpressionTreeGrammarParameterName, "The tree grammar that defines the correct syntax of symbolic expression trees that should be created."));
    93       Parameters.Add(new LookupParameter<ISymbolicExpressionGrammar>(ClonedSymbolicExpressionTreeGrammarParameterName, "An immutable clone of the concrete grammar that is actually used to create and manipulate trees."));
    9498      Parameters.Add(new LookupParameter<ISymbolicDataAnalysisSingleObjectiveEvaluator<T>>(EvaluatorParameterName, "The single objective solution evaluator"));
    9599      Parameters.Add(new ValueLookupParameter<IntRange>(SymbolicDataAnalysisEvaluationPartitionParameterName, "The start index of the dataset partition on which the symbolic data analysis solution should be evaluated."));
     
    97101      Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(ChildParameterName, "The child symbolic expression tree resulting from the crossover."));
    98102
     103      EvaluatorParameter.Hidden = true;
     104      EvaluationPartitionParameter.Hidden = true;
     105      SymbolicDataAnalysisTreeInterpreterParameter.Hidden = true;
     106      ProblemDataParameter.Hidden = true;
     107      RelativeNumberOfEvaluatedSamplesParameter.Hidden = true;
     108
     109      InitializeOperators();
     110      Name = "MultiSymbolicDataAnalysisExpressionCrossover";
     111    }
     112
     113    private void InitializeOperators() {
    99114      var list = ApplicationManager.Manager.GetInstances<ISymbolicExpressionTreeCrossover>().ToList();
    100115      var dataAnalysisCrossovers = from type in ApplicationManager.Manager.GetTypes(typeof(ISymbolicDataAnalysisExpressionCrossover<T>))
     
    108123      Operators = checkedItemList;
    109124      Operators_ItemsAdded(this, new CollectionItemsChangedEventArgs<IndexedItem<ISymbolicExpressionTreeCrossover>>(Operators.CheckedItems));
    110       Name = "MultiSymbolicDataAnalysisExpressionCrossover";
    111     }
    112 
    113     public override IOperation Apply() {
    114       if (ClonedSymbolicExpressionTreeGrammarParameter.ActualValue == null) {
    115         SymbolicExpressionTreeGrammarParameter.ActualValue.ReadOnly = true;
    116         IScope globalScope = ExecutionContext.Scope;
    117         while (globalScope.Parent != null)
    118           globalScope = globalScope.Parent;
    119 
    120         globalScope.Variables.Add(new Core.Variable(ClonedSymbolicExpressionTreeGrammarParameterName, (ISymbolicExpressionGrammar)SymbolicExpressionTreeGrammarParameter.ActualValue.Clone()));
    121       }
    122       return base.Apply();
    123125    }
    124126
     
    150152
    151153    private void ParameterizeCrossovers() {
     154      foreach (ISymbolicExpressionTreeCrossover op in Operators) {
     155        op.ChildParameter.ActualName = ChildParameter.Name;
     156        op.ParentsParameter.ActualName = ParentsParameter.Name;
     157      }
    152158      foreach (IStochasticOperator op in Operators.OfType<IStochasticOperator>()) {
    153159        op.RandomParameter.ActualName = RandomParameter.Name;
     
    157163        op.MaximumSymbolicExpressionTreeLengthParameter.ActualName = MaximumSymbolicExpressionTreeLengthParameter.Name;
    158164      }
    159       foreach (ISymbolicExpressionTreeGrammarBasedOperator op in Operators.OfType<ISymbolicExpressionTreeGrammarBasedOperator>()) {
    160         op.SymbolicExpressionTreeGrammarParameter.ActualName = SymbolicExpressionTreeGrammarParameter.Name;
     165
     166      foreach (ISymbolicDataAnalysisInterpreterOperator op in Operators.OfType<ISymbolicDataAnalysisInterpreterOperator>()) {
     167        op.SymbolicDataAnalysisTreeInterpreterParameter.ActualName = SymbolicDataAnalysisTreeInterpreterParameter.Name;
     168      }
     169      foreach (var op in Operators.OfType<ISymbolicDataAnalysisExpressionCrossover<T>>()) {
     170        op.ProblemDataParameter.ActualName = ProblemDataParameter.Name;
     171        op.EvaluationPartitionParameter.ActualName = EvaluationPartitionParameter.Name;
     172        op.RelativeNumberOfEvaluatedSamplesParameter.ActualName = RelativeNumberOfEvaluatedSamplesParameter.Name;
     173        op.EvaluatorParameter.ActualName = EvaluatorParameter.Name;
    161174      }
    162175    }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionContextAwareCrossover.cs

    r7503 r7506  
    2929
    3030namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    31 
    3231  [Item("ContextAwareCrossover", "An operator which deterministically choses the best insertion point for a randomly selected node:\n" +
    3332                                 "- Take two parent individuals P0 and P1\n" +
     
    9291          // perform a swap and check the quality of the solution
    9392          Swap(crossoverPoint, selectedChild);
    94           double quality = evaluator.Evaluate(context, parent0, problemData, rows);
     93          IExecutionContext childContext = new ExecutionContext(context, evaluator, context.Scope);
     94          double quality = evaluator.Evaluate(childContext, parent0, problemData, rows);
    9595          qualities.Add(new Tuple<CutPoint, double>(crossoverPoint, quality));
    9696          // restore the correct parent
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionCrossover.cs

    r7503 r7506  
    3535    private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicExpressionTreeInterpreter";
    3636    private const string ProblemDataParameterName = "ProblemData";
    37     private const string EstimationLimitsParameterName = "EstimationLimits";
    3837    private const string EvaluatorParameterName = "Evaluator";
    39     private const string SymbolicDataAnalysisEvaluationPartitionParameterName = "EvaluationPartition";
     38    private const string EvaluationPartitionParameterName = "EvaluationPartition";
    4039    private const string RelativeNumberOfEvaluatedSamplesParameterName = "RelativeNumberOfEvaluatedSamples";
    4140    private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength";
     
    5453      get { return (ILookupParameter<ISymbolicDataAnalysisSingleObjectiveEvaluator<T>>)Parameters[EvaluatorParameterName]; }
    5554    }
    56     public IValueLookupParameter<IntRange> SymbolicDataAnalysisEvaluationPartitionParameter {
    57       get { return (IValueLookupParameter<IntRange>)Parameters[SymbolicDataAnalysisEvaluationPartitionParameterName]; }
    58     }
    59     public IValueLookupParameter<DoubleLimit> EstimationLimitsParameter {
    60       get { return (IValueLookupParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; }
     55    public IValueLookupParameter<IntRange> EvaluationPartitionParameter {
     56      get { return (IValueLookupParameter<IntRange>)Parameters[EvaluationPartitionParameterName]; }
    6157    }
    6258    public IValueLookupParameter<PercentValue> RelativeNumberOfEvaluatedSamplesParameter {
     
    9086      Parameters.Add(new LookupParameter<ISymbolicDataAnalysisSingleObjectiveEvaluator<T>>(EvaluatorParameterName, "The single objective solution evaluator"));
    9187      Parameters.Add(new ValueLookupParameter<T>(ProblemDataParameterName, "The problem data on which the symbolic data analysis solution should be evaluated."));
    92       Parameters.Add(new ValueLookupParameter<IntRange>(SymbolicDataAnalysisEvaluationPartitionParameterName, "The start index of the dataset partition on which the symbolic data analysis solution should be evaluated."));
    93       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."));
     88      Parameters.Add(new ValueLookupParameter<IntRange>(EvaluationPartitionParameterName, "The start index of the dataset partition on which the symbolic data analysis solution should be evaluated."));
    9489      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."));
    9590      Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, "The maximum tree depth."));
     
    9792
    9893      EvaluatorParameter.Hidden = true;
    99       EstimationLimitsParameter.Hidden = true;
    100       SymbolicDataAnalysisEvaluationPartitionParameter.Hidden = true;
     94      EvaluationPartitionParameter.Hidden = true;
    10195      SymbolicDataAnalysisTreeInterpreterParameter.Hidden = true;
    10296      ProblemDataParameter.Hidden = true;
     
    131125    protected IEnumerable<int> GenerateRowsToEvaluate(double percentageOfRows) {
    132126      IEnumerable<int> rows;
    133       int samplesStart = SymbolicDataAnalysisEvaluationPartitionParameter.ActualValue.Start;
    134       int samplesEnd = SymbolicDataAnalysisEvaluationPartitionParameter.ActualValue.End;
     127      int samplesStart = EvaluationPartitionParameter.ActualValue.Start;
     128      int samplesEnd = EvaluationPartitionParameter.ActualValue.End;
    135129      int testPartitionStart = ProblemDataParameter.ActualValue.TestPartition.Start;
    136130      int testPartitionEnd = ProblemDataParameter.ActualValue.TestPartition.End;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionDepthConstrainedCrossover.cs

    r7503 r7506  
    3131
    3232namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    33 
    3433  [Item("DepthConstrainedCrossover", "An operator which performs subtree swapping within a specific depth range. The range parameter controls the crossover behavior:\n" +
    3534                                     "- HighLevel (upper 25% of the tree)\n" +
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionDeterministicBestCrossover.cs

    r7503 r7506  
    2929
    3030namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    31 
    3231  [Item("DeterministicBestCrossover", "An operator which performs subtree swapping by choosing the best subtree to be swapped in a certain position:\n" +
    3332                                      "- Take two parent individuals P0 and P1\n" +
     
    8584      // create symbols in order to improvize an ad-hoc tree so that the child can be evaluated
    8685      ISymbolicExpressionTreeNode selectedBranch = null;
    87 
    8886      var nodeQualities = new List<Tuple<ISymbolicExpressionTreeNode, double>>();
    89 
    9087      var originalChild = crossoverPoint0.Child;
    9188
     
    9390        var parent = node.Parent;
    9491        Swap(crossoverPoint0, node); // the swap will set the nodes parent to crossoverPoint0.Parent
    95         double quality = evaluator.Evaluate(context, parent0, problemData, rows);
     92        IExecutionContext childContext = new ExecutionContext(context, evaluator, context.Scope);
     93        double quality = evaluator.Evaluate(childContext, parent0, problemData, rows);
    9694        Swap(crossoverPoint0, originalChild); // swap the child back (so that the next swap will not affect the currently swapped node from parent1)
    9795        nodeQualities.Add(new Tuple<ISymbolicExpressionTreeNode, double>(node, quality));
     
    9997      }
    10098
    101       nodeQualities.Sort((a, b) => a.Item2.CompareTo(b.Item2)); // assuming this sorts the list in ascending order
     99      nodeQualities.Sort((a, b) => a.Item2.CompareTo(b.Item2));
    102100      selectedBranch = evaluator.Maximization ? nodeQualities.Last().Item1 : nodeQualities.First().Item1;
    103 
    104 
    105       if (selectedBranch == null)
    106         throw new Exception("Selected branch is null");
    107 
    108       if (selectedBranch.Parent == null)
    109         throw new Exception("Parent is null");
    110 
    111101
    112102      // swap the node that would create the best offspring
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionProbabilisticFunctionalCrossover.cs

    r7503 r7506  
    2929
    3030namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    31 
    3231  [Item("ProbabilisticFunctionalCrossover", "An operator which performs subtree swapping based on the behavioral similarity between subtrees:\n" +
    3332                                            "- Take two parent individuals P0 and P1\n" +
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj

    r7037 r7506  
    126126    <Compile Include="Creators\SymbolicDataAnalysisExpressionRampedHalfAndHalfTreeCreator.cs" />
    127127    <Compile Include="Creators\SymbolicDataAnalysisExpressionTreeCreator.cs" />
     128    <Compile Include="Crossovers\MultiSymbolicDataAnalysisExpressionCrossover.cs" />
     129    <Compile Include="Crossovers\SymbolicDataAnalysisExpressionContextAwareCrossover.cs" />
     130    <Compile Include="Crossovers\SymbolicDataAnalysisExpressionCrossover.cs" />
     131    <Compile Include="Crossovers\SymbolicDataAnalysisExpressionDepthConstrainedCrossover.cs" />
     132    <Compile Include="Crossovers\SymbolicDataAnalysisExpressionDeterministicBestCrossover.cs" />
     133    <Compile Include="Crossovers\SymbolicDataAnalysisExpressionProbabilisticFunctionalCrossover.cs" />
     134    <Compile Include="Crossovers\SymbolicDataAnalysisExpressionSemanticSimilarityCrossover.cs" />
     135    <Compile Include="Interfaces\ISymbolicDataAnalysisExpressionCrossover.cs" />
    128136    <Compile Include="Plugin.cs" />
    129137    <Compile Include="SymbolicDataAnalysisExpressionTreeILEmittingInterpreter.cs" />
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interfaces/ISymbolicDataAnalysisExpressionCrossover.cs

    r7503 r7506  
    2525
    2626namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    27   public interface ISymbolicDataAnalysisExpressionCrossover<T> : ISymbolicExpressionTreeCrossover {
    28     IValueLookupParameter<IntRange> SymbolicDataAnalysisEvaluationPartitionParameter { get; }
     27  public interface ISymbolicDataAnalysisExpressionCrossover<T> : ISymbolicExpressionTreeCrossover,
     28    ISymbolicExpressionTreeSizeConstraintOperator, ISymbolicDataAnalysisInterpreterOperator
     29    where T : class, IDataAnalysisProblemData {
     30    IValueLookupParameter<T> ProblemDataParameter { get; }
     31    ILookupParameter<ISymbolicDataAnalysisSingleObjectiveEvaluator<T>> EvaluatorParameter { get; }
     32    IValueLookupParameter<IntRange> EvaluationPartitionParameter { get; }
     33    IValueLookupParameter<PercentValue> RelativeNumberOfEvaluatedSamplesParameter { get; }
    2934  }
    3035}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interfaces/ISymbolicDataAnalysisExpressionTreeInterpreter.cs

    r7259 r7506  
    2222using System.Collections.Generic;
    2323using HeuristicLab.Core;
     24using HeuristicLab.Data;
    2425using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2526
    2627namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    27   public interface ISymbolicDataAnalysisExpressionTreeInterpreter : INamedItem {
     28  public interface ISymbolicDataAnalysisExpressionTreeInterpreter : INamedItem, IStatefulItem {
    2829    IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, Dataset dataset, IEnumerable<int> rows);
     30    IntValue EvaluatedSolutions { get; set; }
    2931  }
    3032}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeILEmittingInterpreter.cs

    r7259 r7506  
    2121
    2222using System;
    23 using System.Collections.ObjectModel;
     23using System.Collections.Generic;
    2424using System.Linq;
    25 using System.Collections.Generic;
    2625using System.Reflection;
    2726using System.Reflection.Emit;
     
    4847    internal delegate double CompiledFunction(int sampleIndex, IList<double>[] columns);
    4948    private const string CheckExpressionsWithIntervalArithmeticParameterName = "CheckExpressionsWithIntervalArithmetic";
     49    private const string EvaluatedSolutionsParameterName = "EvaluatedSolutions";
    5050    #region private classes
    5151    private class InterpreterState {
     
    156156      get { return (IValueParameter<BoolValue>)Parameters[CheckExpressionsWithIntervalArithmeticParameterName]; }
    157157    }
     158
     159    public IValueParameter<IntValue> EvaluatedSolutionsParameter {
     160      get { return (IValueParameter<IntValue>)Parameters[EvaluatedSolutionsParameterName]; }
     161    }
    158162    #endregion
    159163
     
    162166      get { return CheckExpressionsWithIntervalArithmeticParameter.Value; }
    163167      set { CheckExpressionsWithIntervalArithmeticParameter.Value = value; }
     168    }
     169
     170    public IntValue EvaluatedSolutions {
     171      get { return EvaluatedSolutionsParameter.Value; }
     172      set { EvaluatedSolutionsParameter.Value = value; }
    164173    }
    165174    #endregion
     
    176185      : base("SymbolicDataAnalysisExpressionTreeILEmittingInterpreter", "Interpreter for symbolic expression trees.") {
    177186      Parameters.Add(new ValueParameter<BoolValue>(CheckExpressionsWithIntervalArithmeticParameterName, "Switch that determines if the interpreter checks the validity of expressions with interval arithmetic before evaluating the expression.", new BoolValue(false)));
    178     }
     187      Parameters.Add(new ValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0)));
     188    }
     189
     190    [StorableHook(HookType.AfterDeserialization)]
     191    private void AfterDeserialization() {
     192      if (!Parameters.ContainsKey(EvaluatedSolutionsParameterName))
     193        Parameters.Add(new ValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0)));
     194    }
     195
     196    #region IStatefulItem
     197    public void InitializeState() {
     198      EvaluatedSolutions.Value = 0;
     199    }
     200
     201    public void ClearState() {
     202      EvaluatedSolutions.Value = 0;
     203    }
     204    #endregion
    179205
    180206    public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, Dataset dataset, IEnumerable<int> rows) {
    181207      if (CheckExpressionsWithIntervalArithmetic.Value)
    182208        throw new NotSupportedException("Interval arithmetic is not yet supported in the symbolic data analysis interpreter.");
     209      EvaluatedSolutions.Value++; // increment the evaluated solutions counter
    183210      var compiler = new SymbolicExpressionTreeCompiler();
    184211      Instruction[] code = compiler.Compile(tree, MapSymbolToOpCode);
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeInterpreter.cs

    r7259 r7506  
    3434  public sealed class SymbolicDataAnalysisExpressionTreeInterpreter : ParameterizedNamedItem, ISymbolicDataAnalysisExpressionTreeInterpreter {
    3535    private const string CheckExpressionsWithIntervalArithmeticParameterName = "CheckExpressionsWithIntervalArithmetic";
     36    private const string EvaluatedSolutionsParameterName = "EvaluatedSolutions";
    3637    #region private classes
    3738    private class InterpreterState {
     
    176177      get { return (IValueParameter<BoolValue>)Parameters[CheckExpressionsWithIntervalArithmeticParameterName]; }
    177178    }
     179
     180    public IValueParameter<IntValue> EvaluatedSolutionsParameter {
     181      get { return (IValueParameter<IntValue>)Parameters[EvaluatedSolutionsParameterName]; }
     182    }
    178183    #endregion
    179184
     
    183188      set { CheckExpressionsWithIntervalArithmeticParameter.Value = value; }
    184189    }
     190
     191    public IntValue EvaluatedSolutions {
     192      get { return EvaluatedSolutionsParameter.Value; }
     193      set { EvaluatedSolutionsParameter.Value = value; }
     194    }
    185195    #endregion
    186 
    187196
    188197    [StorableConstructor]
     
    196205      : base("SymbolicDataAnalysisExpressionTreeInterpreter", "Interpreter for symbolic expression trees including automatically defined functions.") {
    197206      Parameters.Add(new ValueParameter<BoolValue>(CheckExpressionsWithIntervalArithmeticParameterName, "Switch that determines if the interpreter checks the validity of expressions with interval arithmetic before evaluating the expression.", new BoolValue(false)));
    198     }
     207      Parameters.Add(new ValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0)));
     208    }
     209
     210    [StorableHook(HookType.AfterDeserialization)]
     211    private void AfterDeserialization() {
     212      if (!Parameters.ContainsKey(EvaluatedSolutionsParameterName))
     213        Parameters.Add(new ValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0)));
     214    }
     215
     216    #region IStatefulItem
     217    public void InitializeState() {
     218      EvaluatedSolutions.Value = 0;
     219    }
     220
     221    public void ClearState() {
     222    }
     223    #endregion
    199224
    200225    public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, Dataset dataset, IEnumerable<int> rows) {
    201226      if (CheckExpressionsWithIntervalArithmetic.Value)
    202227        throw new NotSupportedException("Interval arithmetic is not yet supported in the symbolic data analysis interpreter.");
     228      EvaluatedSolutions.Value++; // increment the evaluated solutions counter
    203229      var compiler = new SymbolicExpressionTreeCompiler();
    204230      Instruction[] code = compiler.Compile(tree, MapSymbolToOpCode);
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisProblem.cs

    r7259 r7506  
    198198    private void InitializeOperators() {
    199199      Operators.AddRange(ApplicationManager.Manager.GetInstances<ISymbolicExpressionTreeOperator>());
     200      Operators.AddRange(ApplicationManager.Manager.GetInstances<ISymbolicDataAnalysisExpressionCrossover<T>>());
    200201      Operators.Add(new SymbolicExpressionSymbolFrequencyAnalyzer());
    201202      Operators.Add(new SymbolicDataAnalysisVariableFrequencyAnalyzer());
     
    268269
    269270    protected virtual void ParameterizeOperators() {
    270       var operators = Parameters.OfType<IValueParameter>().Select(p => p.Value).OfType<IOperator>().Union(Operators);
     271      var operators = Parameters.OfType<IValueParameter>().Select(p => p.Value).OfType<IOperator>().Union(Operators).ToList();
    271272
    272273      foreach (var op in operators.OfType<ISymbolicExpressionTreeGrammarBasedOperator>()) {
     
    307308        op.SymbolicDataAnalysisTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameterName;
    308309      }
     310      foreach (var op in operators.OfType<ISymbolicDataAnalysisExpressionCrossover<T>>()) {
     311        op.EvaluationPartitionParameter.ActualName = FitnessCalculationPartitionParameterName;
     312      }
     313      foreach (var op in operators.OfType<ISymbolicDataAnalysisExpressionCrossover<T>>()) {
     314        op.ProblemDataParameter.ActualName = ProblemDataParameter.Name;
     315        op.EvaluationPartitionParameter.ActualName = FitnessCalculationPartitionParameter.Name;
     316        op.RelativeNumberOfEvaluatedSamplesParameter.ActualName = RelativeNumberOfEvaluatedSamplesParameter.Name;
     317        op.EvaluatorParameter.ActualName = EvaluatorParameter.Name;
     318      }
    309319    }
    310320
Note: See TracChangeset for help on using the changeset viewer.