Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/08/16 14:40:02 (8 years ago)
Author:
gkronber
Message:

#2434: merged trunk changes r12934:14026 from trunk to branch

Location:
branches/crossvalidation-2434
Files:
1 deleted
23 edited
6 copied

Legend:

Unmodified
Added
Removed
  • branches/crossvalidation-2434

  • branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Symbolic

  • branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisMultiObjectiveTrainingBestSolutionAnalyzer.cs

    r12012 r14029  
    2020#endregion
    2121
    22 using System;
    2322using System.Collections.Generic;
    2423using System.Linq;
     
    4241    private const string TrainingBestSolutionQualitiesParameterName = "Best training solution qualities";
    4342    private const string UpdateAlwaysParameterName = "Always update best solutions";
     43    private const string TrainingBestSolutionParameterName = "Best training solution";
    4444
    4545    #region parameter properties
     
    5555    #endregion
    5656    #region properties
    57     public ItemList<T> TrainingBestSolutions {
     57    private ItemList<T> TrainingBestSolutions {
    5858      get { return TrainingBestSolutionsParameter.ActualValue; }
    5959      set { TrainingBestSolutionsParameter.ActualValue = value; }
    6060    }
    61     public ItemList<DoubleArray> TrainingBestSolutionQualities {
     61    private ItemList<DoubleArray> TrainingBestSolutionQualities {
    6262      get { return TrainingBestSolutionQualitiesParameter.ActualValue; }
    6363      set { TrainingBestSolutionQualitiesParameter.ActualValue = value; }
    6464    }
    65     public BoolValue UpdateAlways {
    66       get { return UpdateAlwaysParameter.Value; }
     65    public bool UpdateAlways {
     66      get { return UpdateAlwaysParameter.Value.Value; }
     67      set { UpdateAlwaysParameter.Value.Value = value; }
    6768    }
    6869    #endregion
     
    9798      }
    9899
     100      if (!results.ContainsKey(TrainingBestSolutionParameterName)) {
     101        results.Add(new Result(TrainingBestSolutionParameterName, "", typeof(ISymbolicDataAnalysisSolution)));
     102      }
     103
    99104      //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) {
     105      List<double[]> trainingBestQualities;
     106      if (UpdateAlways) {
    102107        trainingBestQualities = new List<double[]>();
    103108      } else {
     
    105110      }
    106111
    107       #region find best trees
    108       IList<int> nonDominatedIndexes = new List<int>();
    109       ISymbolicExpressionTree[] tree = SymbolicExpressionTree.ToArray();
     112      ISymbolicExpressionTree[] trees = SymbolicExpressionTree.ToArray();
    110113      List<double[]> qualities = Qualities.Select(x => x.ToArray()).ToList();
    111114      bool[] maximization = Maximization.ToArray();
    112       List<double[]> newNonDominatedQualities = new List<double[]>();
    113       for (int i = 0; i < tree.Length; i++) {
    114         if (IsNonDominated(qualities[i], trainingBestQualities, maximization) &&
    115           IsNonDominated(qualities[i], qualities, maximization)) {
    116           if (!newNonDominatedQualities.Contains(qualities[i], new DoubleArrayComparer())) {
    117             newNonDominatedQualities.Add(qualities[i]);
    118             nonDominatedIndexes.Add(i);
     115
     116      var nonDominatedIndividuals = new[] { new { Tree = default(ISymbolicExpressionTree), Qualities = default(double[]) } }.ToList();
     117      nonDominatedIndividuals.Clear();
     118
     119      // build list of new non-dominated solutions
     120      for (int i = 0; i < trees.Length; i++) {
     121        if (IsNonDominated(qualities[i], nonDominatedIndividuals.Select(ind => ind.Qualities), maximization) &&
     122            IsNonDominated(qualities[i], trainingBestQualities, maximization)) {
     123          for (int j = nonDominatedIndividuals.Count - 1; j >= 0; j--) {
     124            if (IsBetterOrEqual(qualities[i], nonDominatedIndividuals[j].Qualities, maximization)) {
     125              nonDominatedIndividuals.RemoveAt(j);
     126            }
    119127          }
     128          nonDominatedIndividuals.Add(new { Tree = trees[i], Qualities = qualities[i] });
    120129        }
    121130      }
    122       #endregion
     131
     132      var nonDominatedSolutions = nonDominatedIndividuals.Select(x => new { Solution = CreateSolution(x.Tree, x.Qualities), Qualities = x.Qualities }).ToList();
     133      nonDominatedSolutions.ForEach(s => s.Solution.Name = string.Join(",", s.Qualities.Select(q => q.ToString())));
     134
    123135      #region update Pareto-optimal solution archive
    124       if (nonDominatedIndexes.Count > 0) {
    125         ItemList<DoubleArray> nonDominatedQualities = new ItemList<DoubleArray>();
    126         ItemList<T> nonDominatedSolutions = new ItemList<T>();
    127         // add all new non-dominated solutions to the archive
    128         foreach (var index in nonDominatedIndexes) {
    129           T solution = CreateSolution(tree[index], qualities[index]);
    130           nonDominatedSolutions.Add(solution);
    131           nonDominatedQualities.Add(new DoubleArray(qualities[index]));
    132         }
    133         // add old non-dominated solutions only if they are not dominated by one of the new solutions
     136      if (nonDominatedSolutions.Count > 0) {
     137        //add old non-dominated solutions only if they are not dominated by one of the new solutions
    134138        for (int i = 0; i < trainingBestQualities.Count; i++) {
    135           if (IsNonDominated(trainingBestQualities[i], newNonDominatedQualities, maximization)) {
    136             if (!newNonDominatedQualities.Contains(trainingBestQualities[i], new DoubleArrayComparer())) {
    137               nonDominatedSolutions.Add(TrainingBestSolutions[i]);
    138               nonDominatedQualities.Add(TrainingBestSolutionQualities[i]);
    139             }
     139          if (IsNonDominated(trainingBestQualities[i], nonDominatedSolutions.Select(x => x.Qualities), maximization)) {
     140            nonDominatedSolutions.Add(new { Solution = TrainingBestSolutions[i], Qualities = TrainingBestSolutionQualities[i].ToArray() });
    140141          }
    141142        }
    142143
    143         results[TrainingBestSolutionsParameter.Name].Value = nonDominatedSolutions;
    144         results[TrainingBestSolutionQualitiesParameter.Name].Value = nonDominatedQualities;
     144        //assumes the the first objective is always the accuracy
     145        var sortedNonDominatedSolutions = maximization[0]
     146          ? nonDominatedSolutions.OrderByDescending(x => x.Qualities[0])
     147          : nonDominatedSolutions.OrderBy(x => x.Qualities[0]);
     148        var trainingBestSolution = sortedNonDominatedSolutions.Select(s => s.Solution).First();
     149        results[TrainingBestSolutionParameterName].Value = trainingBestSolution;
     150        TrainingBestSolutions = new ItemList<T>(sortedNonDominatedSolutions.Select(x => x.Solution));
     151        results[TrainingBestSolutionsParameter.Name].Value = TrainingBestSolutions;
     152        TrainingBestSolutionQualities = new ItemList<DoubleArray>(sortedNonDominatedSolutions.Select(x => new DoubleArray(x.Qualities)));
     153        results[TrainingBestSolutionQualitiesParameter.Name].Value = TrainingBestSolutionQualities;
    145154      }
    146155      #endregion
     
    148157    }
    149158
    150     private class DoubleArrayComparer : IEqualityComparer<double[]> {
    151       public bool Equals(double[] x, double[] y) {
    152         if (y.Length != x.Length) throw new ArgumentException();
    153         for (int i = 0; i < x.Length; i++) {
    154           if (!x[i].IsAlmost(y[i])) return false;
    155         }
    156         return true;
    157       }
    158 
    159       public int GetHashCode(double[] obj) {
    160         int c = obj.Length;
    161         for (int i = 0; i < obj.Length; i++)
    162           c ^= obj[i].GetHashCode();
    163         return c;
    164       }
    165     }
    166 
    167159    protected abstract T CreateSolution(ISymbolicExpressionTree bestTree, double[] bestQuality);
    168160
    169     private bool IsNonDominated(double[] point, IList<double[]> points, bool[] maximization) {
     161    private bool IsNonDominated(double[] point, IEnumerable<double[]> points, bool[] maximization) {
    170162      foreach (var refPoint in points) {
    171         bool refPointDominatesPoint = true;
    172         for (int i = 0; i < point.Length; i++) {
    173           refPointDominatesPoint &= IsBetterOrEqual(refPoint[i], point[i], maximization[i]);
    174         }
     163        bool refPointDominatesPoint = IsBetterOrEqual(refPoint, point, maximization);
    175164        if (refPointDominatesPoint) return false;
    176165      }
    177166      return true;
    178167    }
     168
     169    private bool IsBetterOrEqual(double[] lhs, double[] rhs, bool[] maximization) {
     170      for (int i = 0; i < lhs.Length; i++) {
     171        var result = IsBetterOrEqual(lhs[i], rhs[i], maximization[i]);
     172        if (!result) return false;
     173      }
     174      return true;
     175    }
     176
    179177    private bool IsBetterOrEqual(double lhs, double rhs, bool maximization) {
    180       if (maximization) return lhs > rhs;
    181       else return lhs < rhs;
     178      if (maximization) return lhs >= rhs;
     179      else return lhs <= rhs;
    182180    }
    183181  }
  • branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Creators/MultiSymbolicDataAnalysisExpressionCreator.cs

    r12108 r14029  
    3535
    3636namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Creators {
     37  [StorableClass]
    3738  public class MultiSymbolicDataAnalysisExpressionCreator : StochasticMultiBranch<ISymbolicDataAnalysisSolutionCreator>,
    3839    ISymbolicDataAnalysisSolutionCreator,
  • branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionContextAwareCrossover.cs

    r12422 r14029  
    3434                                 "- Randomly choose a node N from P1\n" +
    3535                                 "- Test all crossover points from P0 to determine the best location for N to be inserted")]
     36  [StorableClass]
    3637  public sealed class SymbolicDataAnalysisExpressionContextAwareCrossover<T> : SymbolicDataAnalysisExpressionCrossover<T> where T : class, IDataAnalysisProblemData {
    3738    [StorableConstructor]
  • branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionCrossover.cs

    r12012 r14029  
    3232
    3333namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     34  [StorableClass]
    3435  public abstract class SymbolicDataAnalysisExpressionCrossover<T> : SymbolicExpressionTreeCrossover, ISymbolicDataAnalysisExpressionCrossover<T> where T : class, IDataAnalysisProblemData {
    3536    private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicExpressionTreeInterpreter";
  • branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionDepthConstrainedCrossover.cs

    r12422 r14029  
    3636                                     "- Standard (mid 50% of the tree)\n" +
    3737                                     "- LowLevel (lower 25% of the tree)")]
     38  [StorableClass]
    3839  public sealed class SymbolicDataAnalysisExpressionDepthConstrainedCrossover<T> :
    3940    SymbolicDataAnalysisExpressionCrossover<T> where T : class, IDataAnalysisProblemData {
  • branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionDeterministicBestCrossover.cs

    r12422 r14029  
    3434                                      "- Randomly choose a crossover point C from P0\n" +
    3535                                      "- Test all nodes from P1 to determine the one that produces the best child when inserted at place C in P0")]
     36  [StorableClass]
    3637  public sealed class SymbolicDataAnalysisExpressionDeterministicBestCrossover<T> : SymbolicDataAnalysisExpressionCrossover<T> where T : class, IDataAnalysisProblemData {
    3738    [StorableConstructor]
  • branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionProbabilisticFunctionalCrossover.cs

    r12422 r14029  
    3636                                            "\t\tD(N,M) = 0.5 * ( abs(max(N) - max(M)) + abs(min(N) - min(M)) )\n" +
    3737                                            "- Make a probabilistic weighted choice of node M from P1, based on the inversed and normalized behavioral distance")]
     38  [StorableClass]
    3839  public sealed class SymbolicDataAnalysisExpressionProbabilisticFunctionalCrossover<T> : SymbolicDataAnalysisExpressionCrossover<T> where T : class, IDataAnalysisProblemData {
    3940    [StorableConstructor]
  • branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionSemanticSimilarityCrossover.cs

    r12422 r14029  
    3737                                       "- Find the first node M that satisfies the semantic similarity criteria\n" +
    3838                                       "- Swap N for M and return P0")]
     39  [StorableClass]
    3940  public sealed class SymbolicDataAnalysisExpressionSemanticSimilarityCrossover<T> : SymbolicDataAnalysisExpressionCrossover<T> where T : class, IDataAnalysisProblemData {
    4041    private const string SemanticSimilarityRangeParameterName = "SemanticSimilarityRange";
  • branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Evaluators/SymbolicDataAnalysisEvaluator.cs

    r12012 r14029  
    9393    public SymbolicDataAnalysisEvaluator()
    9494      : base() {
    95       Parameters.Add(new ValueLookupParameter<IRandom>(RandomParameterName, "The random generator to use."));
    96       Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The interpreter that should be used to calculate the output values of the symbolic data analysis tree."));
    97       Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic data analysis solution encoded as a symbolic expression tree."));
    98       Parameters.Add(new ValueLookupParameter<T>(ProblemDataParameterName, "The problem data on which the symbolic data analysis solution should be evaluated."));
    99       Parameters.Add(new ValueLookupParameter<IntRange>(EvaluationPartitionParameterName, "The start index of the dataset partition on which the symbolic data analysis solution should be evaluated."));
    100       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."));
    101       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)."));
     95      Parameters.Add(new ValueLookupParameter<IRandom>(RandomParameterName, "The random generator to use.") { Hidden = true });
     96      Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The interpreter that should be used to calculate the output values of the symbolic data analysis tree.") { Hidden = true });
     97      Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic data analysis solution encoded as a symbolic expression tree.") { Hidden = true });
     98      Parameters.Add(new ValueLookupParameter<T>(ProblemDataParameterName, "The problem data on which the symbolic data analysis solution should be evaluated.") { Hidden = true });
     99      Parameters.Add(new ValueLookupParameter<IntRange>(EvaluationPartitionParameterName, "The start index of the dataset partition on which the symbolic data analysis solution should be evaluated.") { Hidden = true });
     100      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.") { Hidden = true });
     101      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.") { Hidden = true });
     102      Parameters.Add(new LookupParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the individual should be linearly scaled before evaluating.") { Hidden = true });
     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).") { Hidden = true });
    104104    }
    105105
  • branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Evaluators/SymbolicDataAnalysisMultiObjectiveEvaluator.cs

    r12012 r14029  
    2424using HeuristicLab.Core;
    2525using HeuristicLab.Data;
     26using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2627using HeuristicLab.Parameters;
    2728using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2929
    3030namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     31  [StorableClass]
    3132  public abstract class SymbolicDataAnalysisMultiObjectiveEvaluator<T> : SymbolicDataAnalysisEvaluator<T>, ISymbolicDataAnalysisMultiObjectiveEvaluator<T>
    3233   where T : class, IDataAnalysisProblemData {
  • branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionCSharpFormatter.cs

    r12645 r14029  
    5656
    5757    private void FormatRecursively(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) {
     58      // TODO: adapt to interpreter semantics. The HL interpreter also allows Boolean operations on reals
    5859      if (node.Subtrees.Any()) {
    5960        if (node.Symbol is Addition) {
     
    8384        } else if (node.Symbol is Or) {
    8485          FormatOperator(node, "||", strBuilder);
     86        } else if (node.Symbol is Xor) {
     87          FormatOperator(node, "^", strBuilder);
    8588        } else if (node.Symbol is Sine) {
    8689          FormatFunction(node, "Math.Sin", strBuilder);
    8790        } else if (node.Symbol is Subtraction) {
    88           FormatOperator(node, "-", strBuilder);
     91          FormatSubtraction(node, strBuilder);
    8992        } else if (node.Symbol is Tangent) {
    9093          FormatFunction(node, "Math.Tan", strBuilder);
     
    142145    }
    143146
     147    private void FormatSubtraction(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) {
     148      if (node.SubtreeCount == 1) {
     149        strBuilder.Append("-");
     150        FormatRecursively(node.GetSubtree(0), strBuilder);
     151        return;
     152      }
     153      //Default case: more than 1 child
     154      FormatOperator(node, "-", strBuilder);
     155    }
     156
    144157    private void FormatOperator(ISymbolicExpressionTreeNode node, string symbol, StringBuilder strBuilder) {
    145158      strBuilder.Append("(");
     
    176189      }
    177190
    178       var orderedNames = varNames.OrderBy(n => n, new NaturalStringComparer()).Select(n=> "double " + n);
     191      var orderedNames = varNames.OrderBy(n => n, new NaturalStringComparer()).Select(n => "double " + n);
    179192      strBuilder.Append(string.Join(", ", orderedNames));
    180193
  • branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionLatexFormatter.cs

    r12012 r14029  
    403403            var constStr = string.Format(System.Globalization.NumberFormatInfo.InvariantInfo, "{0:G5}", constant);
    404404            if (!constStr.Contains(".")) constStr = constStr + ".0";
    405             constStr = constStr.Replace(".", "\\negthickspace&.");  // fix problem in rendering of aligned expressions
     405            constStr = constStr.Replace(".", "&.");  // fix problem in rendering of aligned expressions
    406406            strBuilder.Append("c_{" + i + "}& = & " + constStr);
    407407            strBuilder.Append(@"\\");
  • branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj

    r12434 r14029  
    133133      <SubType>Code</SubType>
    134134    </Compile>
     135    <Compile Include="Formatters\InfixExpressionFormatter.cs" />
     136    <Compile Include="Formatters\SymbolicDataAnalysisExpressionMathematicaFormatter.cs" />
    135137    <Compile Include="Formatters\SymbolicDataAnalysisExpressionCSharpFormatter.cs" />
     138    <Compile Include="Importer\InfixExpressionParser.cs" />
    136139    <Compile Include="Importer\SymbolicExpressionImporter.cs" />
    137140    <Compile Include="Importer\Token.cs" />
    138141    <Compile Include="Interfaces\IModelBacktransformator.cs" />
     142    <Compile Include="Interpreter\SymbolicDataAnalysisExpressionCompiledTreeInterpreter.cs" />
     143    <Compile Include="SymbolicDataAnalysisExpressionTreeSimplificationOperator.cs" />
     144    <Compile Include="SymbolicDataAnalysisModelComplexityCalculator.cs" />
    139145    <Compile Include="SymbolicExpressionTreeBacktransformator.cs" />
    140146    <Compile Include="SymbolicDataAnalysisExpressionPruningOperator.cs" />
  • branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interfaces/ISymbolicDataAnalysisExpressionTreeInterpreter.cs

    r12509 r14029  
    2222using System.Collections.Generic;
    2323using HeuristicLab.Core;
    24 using HeuristicLab.Data;
    2524using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2625
     
    2827  public interface ISymbolicDataAnalysisExpressionTreeInterpreter : INamedItem, IStatefulItem {
    2928    IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, IDataset dataset, IEnumerable<int> rows);
    30     IntValue EvaluatedSolutions { get; set; }
     29    int EvaluatedSolutions { get; set; }
    3130  }
    3231}
  • branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeILEmittingInterpreter.cs

    r12509 r14029  
    6969
    7070    private const string CheckExpressionsWithIntervalArithmeticParameterName = "CheckExpressionsWithIntervalArithmetic";
     71    private const string CheckExpressionsWithIntervalArithmeticParameterDescription = "Switch that determines if the interpreter checks the validity of expressions with interval arithmetic before evaluating the expression.";
    7172    private const string EvaluatedSolutionsParameterName = "EvaluatedSolutions";
    7273
     
    8081
    8182    #region parameter properties
    82 
    83     public IValueParameter<BoolValue> CheckExpressionsWithIntervalArithmeticParameter {
    84       get { return (IValueParameter<BoolValue>)Parameters[CheckExpressionsWithIntervalArithmeticParameterName]; }
    85     }
    86 
    87     public IValueParameter<IntValue> EvaluatedSolutionsParameter {
    88       get { return (IValueParameter<IntValue>)Parameters[EvaluatedSolutionsParameterName]; }
    89     }
    90 
     83    public IFixedValueParameter<BoolValue> CheckExpressionsWithIntervalArithmeticParameter {
     84      get { return (IFixedValueParameter<BoolValue>)Parameters[CheckExpressionsWithIntervalArithmeticParameterName]; }
     85    }
     86
     87    public IFixedValueParameter<IntValue> EvaluatedSolutionsParameter {
     88      get { return (IFixedValueParameter<IntValue>)Parameters[EvaluatedSolutionsParameterName]; }
     89    }
    9190    #endregion
    9291
    9392    #region properties
    94 
    95     public BoolValue CheckExpressionsWithIntervalArithmetic {
    96       get { return CheckExpressionsWithIntervalArithmeticParameter.Value; }
    97       set { CheckExpressionsWithIntervalArithmeticParameter.Value = value; }
    98     }
    99 
    100     public IntValue EvaluatedSolutions {
    101       get { return EvaluatedSolutionsParameter.Value; }
    102       set { EvaluatedSolutionsParameter.Value = value; }
    103     }
    104 
     93    public bool CheckExpressionsWithIntervalArithmetic {
     94      get { return CheckExpressionsWithIntervalArithmeticParameter.Value.Value; }
     95      set { CheckExpressionsWithIntervalArithmeticParameter.Value.Value = value; }
     96    }
     97    public int EvaluatedSolutions {
     98      get { return EvaluatedSolutionsParameter.Value.Value; }
     99      set { EvaluatedSolutionsParameter.Value.Value = value; }
     100    }
    105101    #endregion
    106 
    107102
    108103    [StorableConstructor]
     
    116111    public SymbolicDataAnalysisExpressionTreeILEmittingInterpreter()
    117112      : base("SymbolicDataAnalysisExpressionTreeILEmittingInterpreter", "Interpreter for symbolic expression trees.") {
    118       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)));
    119       Parameters.Add(new ValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0)));
     113      Parameters.Add(new FixedValueParameter<BoolValue>(CheckExpressionsWithIntervalArithmeticParameterName,
     114        "Switch that determines if the interpreter checks the validity of expressions with interval arithmetic before evaluating the expression.", new BoolValue(false)));
     115      Parameters.Add(new FixedValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0)));
     116    }
     117
     118    public SymbolicDataAnalysisExpressionTreeILEmittingInterpreter(string name, string description)
     119      : base(name, description) {
     120      Parameters.Add(new FixedValueParameter<BoolValue>(CheckExpressionsWithIntervalArithmeticParameterName,
     121        "Switch that determines if the interpreter checks the validity of expressions with interval arithmetic before evaluating the expression.", new BoolValue(false)));
     122      Parameters.Add(new FixedValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0)));
    120123    }
    121124
    122125    [StorableHook(HookType.AfterDeserialization)]
    123126    private void AfterDeserialization() {
    124       if (!Parameters.ContainsKey(EvaluatedSolutionsParameterName))
    125         Parameters.Add(new ValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0)));
     127      var evaluatedSolutions = new IntValue(0);
     128      var checkExpressionsWithIntervalArithmetic = new BoolValue(false);
     129      if (Parameters.ContainsKey(EvaluatedSolutionsParameterName)) {
     130        var evaluatedSolutionsParameter = (IValueParameter<IntValue>)Parameters[EvaluatedSolutionsParameterName];
     131        evaluatedSolutions = evaluatedSolutionsParameter.Value;
     132        Parameters.Remove(EvaluatedSolutionsParameterName);
     133      }
     134      Parameters.Add(new FixedValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", evaluatedSolutions));
     135      if (Parameters.ContainsKey(CheckExpressionsWithIntervalArithmeticParameterName)) {
     136        var checkExpressionsWithIntervalArithmeticParameter = (IValueParameter<BoolValue>)Parameters[CheckExpressionsWithIntervalArithmeticParameterName];
     137        Parameters.Remove(CheckExpressionsWithIntervalArithmeticParameterName);
     138        checkExpressionsWithIntervalArithmetic = checkExpressionsWithIntervalArithmeticParameter.Value;
     139      }
     140      Parameters.Add(new FixedValueParameter<BoolValue>(CheckExpressionsWithIntervalArithmeticParameterName, CheckExpressionsWithIntervalArithmeticParameterDescription, checkExpressionsWithIntervalArithmetic));
    126141    }
    127142
    128143    #region IStatefulItem
    129 
    130144    public void InitializeState() {
    131       EvaluatedSolutions.Value = 0;
     145      EvaluatedSolutions = 0;
    132146    }
    133147
    134148    public void ClearState() {
    135       EvaluatedSolutions.Value = 0;
    136     }
    137 
     149    }
    138150    #endregion
    139151
     152    private readonly object syncRoot = new object();
    140153    public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, IDataset dataset, IEnumerable<int> rows) {
    141       if (CheckExpressionsWithIntervalArithmetic.Value)
     154      if (CheckExpressionsWithIntervalArithmetic)
    142155        throw new NotSupportedException("Interval arithmetic is not yet supported in the symbolic data analysis interpreter.");
    143156
    144       EvaluatedSolutions.Value++; // increment the evaluated solutions counter
     157      lock (syncRoot) {
     158        EvaluatedSolutions++; // increment the evaluated solutions counter
     159      }
    145160      var state = PrepareInterpreterState(tree, dataset);
    146161
  • branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeInterpreter.cs

    r12509 r14029  
    3232  [StorableClass]
    3333  [Item("SymbolicDataAnalysisExpressionTreeInterpreter", "Interpreter for symbolic expression trees including automatically defined functions.")]
    34   public class SymbolicDataAnalysisExpressionTreeInterpreter : ParameterizedNamedItem, ISymbolicDataAnalysisExpressionTreeInterpreter {
     34  public class SymbolicDataAnalysisExpressionTreeInterpreter : ParameterizedNamedItem,
     35    ISymbolicDataAnalysisExpressionTreeInterpreter {
    3536    private const string CheckExpressionsWithIntervalArithmeticParameterName = "CheckExpressionsWithIntervalArithmetic";
     37    private const string CheckExpressionsWithIntervalArithmeticParameterDescription = "Switch that determines if the interpreter checks the validity of expressions with interval arithmetic before evaluating the expression.";
    3638    private const string EvaluatedSolutionsParameterName = "EvaluatedSolutions";
    3739
    38     public override bool CanChangeName { get { return false; } }
    39     public override bool CanChangeDescription { get { return false; } }
     40    public override bool CanChangeName {
     41      get { return false; }
     42    }
     43
     44    public override bool CanChangeDescription {
     45      get { return false; }
     46    }
    4047
    4148    #region parameter properties
    42     public IValueParameter<BoolValue> CheckExpressionsWithIntervalArithmeticParameter {
    43       get { return (IValueParameter<BoolValue>)Parameters[CheckExpressionsWithIntervalArithmeticParameterName]; }
    44     }
    45 
    46     public IValueParameter<IntValue> EvaluatedSolutionsParameter {
    47       get { return (IValueParameter<IntValue>)Parameters[EvaluatedSolutionsParameterName]; }
     49    public IFixedValueParameter<BoolValue> CheckExpressionsWithIntervalArithmeticParameter {
     50      get { return (IFixedValueParameter<BoolValue>)Parameters[CheckExpressionsWithIntervalArithmeticParameterName]; }
     51    }
     52
     53    public IFixedValueParameter<IntValue> EvaluatedSolutionsParameter {
     54      get { return (IFixedValueParameter<IntValue>)Parameters[EvaluatedSolutionsParameterName]; }
    4855    }
    4956    #endregion
    5057
    5158    #region properties
    52     public BoolValue CheckExpressionsWithIntervalArithmetic {
    53       get { return CheckExpressionsWithIntervalArithmeticParameter.Value; }
    54       set { CheckExpressionsWithIntervalArithmeticParameter.Value = value; }
    55     }
    56 
    57     public IntValue EvaluatedSolutions {
    58       get { return EvaluatedSolutionsParameter.Value; }
    59       set { EvaluatedSolutionsParameter.Value = value; }
     59    public bool CheckExpressionsWithIntervalArithmetic {
     60      get { return CheckExpressionsWithIntervalArithmeticParameter.Value.Value; }
     61      set { CheckExpressionsWithIntervalArithmeticParameter.Value.Value = value; }
     62    }
     63
     64    public int EvaluatedSolutions {
     65      get { return EvaluatedSolutionsParameter.Value.Value; }
     66      set { EvaluatedSolutionsParameter.Value.Value = value; }
    6067    }
    6168    #endregion
     
    6370    [StorableConstructor]
    6471    protected SymbolicDataAnalysisExpressionTreeInterpreter(bool deserializing) : base(deserializing) { }
    65     protected SymbolicDataAnalysisExpressionTreeInterpreter(SymbolicDataAnalysisExpressionTreeInterpreter original, Cloner cloner) : base(original, cloner) { }
     72
     73    protected SymbolicDataAnalysisExpressionTreeInterpreter(SymbolicDataAnalysisExpressionTreeInterpreter original,
     74      Cloner cloner)
     75      : base(original, cloner) { }
     76
    6677    public override IDeepCloneable Clone(Cloner cloner) {
    6778      return new SymbolicDataAnalysisExpressionTreeInterpreter(this, cloner);
     
    7081    public SymbolicDataAnalysisExpressionTreeInterpreter()
    7182      : base("SymbolicDataAnalysisExpressionTreeInterpreter", "Interpreter for symbolic expression trees including automatically defined functions.") {
    72       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)));
    73       Parameters.Add(new ValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0)));
     83      Parameters.Add(new FixedValueParameter<BoolValue>(CheckExpressionsWithIntervalArithmeticParameterName, "Switch that determines if the interpreter checks the validity of expressions with interval arithmetic before evaluating the expression.", new BoolValue(false)));
     84      Parameters.Add(new FixedValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0)));
    7485    }
    7586
    7687    protected SymbolicDataAnalysisExpressionTreeInterpreter(string name, string description)
    7788      : base(name, description) {
    78       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)));
    79       Parameters.Add(new ValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0)));
     89      Parameters.Add(new FixedValueParameter<BoolValue>(CheckExpressionsWithIntervalArithmeticParameterName, "Switch that determines if the interpreter checks the validity of expressions with interval arithmetic before evaluating the expression.", new BoolValue(false)));
     90      Parameters.Add(new FixedValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0)));
    8091    }
    8192
    8293    [StorableHook(HookType.AfterDeserialization)]
    8394    private void AfterDeserialization() {
    84       if (!Parameters.ContainsKey(EvaluatedSolutionsParameterName))
    85         Parameters.Add(new ValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0)));
     95      var evaluatedSolutions = new IntValue(0);
     96      var checkExpressionsWithIntervalArithmetic = new BoolValue(false);
     97      if (Parameters.ContainsKey(EvaluatedSolutionsParameterName)) {
     98        var evaluatedSolutionsParameter = (IValueParameter<IntValue>)Parameters[EvaluatedSolutionsParameterName];
     99        evaluatedSolutions = evaluatedSolutionsParameter.Value;
     100        Parameters.Remove(EvaluatedSolutionsParameterName);
     101      }
     102      Parameters.Add(new FixedValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", evaluatedSolutions));
     103      if (Parameters.ContainsKey(CheckExpressionsWithIntervalArithmeticParameterName)) {
     104        var checkExpressionsWithIntervalArithmeticParameter = (IValueParameter<BoolValue>)Parameters[CheckExpressionsWithIntervalArithmeticParameterName];
     105        Parameters.Remove(CheckExpressionsWithIntervalArithmeticParameterName);
     106        checkExpressionsWithIntervalArithmetic = checkExpressionsWithIntervalArithmeticParameter.Value;
     107      }
     108      Parameters.Add(new FixedValueParameter<BoolValue>(CheckExpressionsWithIntervalArithmeticParameterName, CheckExpressionsWithIntervalArithmeticParameterDescription, checkExpressionsWithIntervalArithmetic));
    86109    }
    87110
    88111    #region IStatefulItem
    89112    public void InitializeState() {
    90       EvaluatedSolutions.Value = 0;
    91     }
    92 
    93     public void ClearState() {
    94     }
     113      EvaluatedSolutions = 0;
     114    }
     115
     116    public void ClearState() { }
    95117    #endregion
    96118
    97     public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, IDataset dataset, IEnumerable<int> rows) {
    98       if (CheckExpressionsWithIntervalArithmetic.Value)
     119    private readonly object syncRoot = new object();
     120    public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, IDataset dataset,
     121      IEnumerable<int> rows) {
     122      if (CheckExpressionsWithIntervalArithmetic) {
    99123        throw new NotSupportedException("Interval arithmetic is not yet supported in the symbolic data analysis interpreter.");
    100 
    101       lock (EvaluatedSolutions) {
    102         EvaluatedSolutions.Value++; // increment the evaluated solutions counter
     124      }
     125
     126      lock (syncRoot) {
     127        EvaluatedSolutions++; // increment the evaluated solutions counter
    103128      }
    104129      var state = PrepareInterpreterState(tree, dataset);
     
    131156    }
    132157
    133 
    134158    public virtual double Evaluate(IDataset dataset, ref int row, InterpreterState state) {
    135159      Instruction currentInstr = state.NextInstruction();
     
    147171              s -= Evaluate(dataset, ref row, state);
    148172            }
    149             if (currentInstr.nArguments == 1) s = -s;
     173            if (currentInstr.nArguments == 1) { s = -s; }
    150174            return s;
    151175          }
     
    162186              p /= Evaluate(dataset, ref row, state);
    163187            }
    164             if (currentInstr.nArguments == 1) p = 1.0 / p;
     188            if (currentInstr.nArguments == 1) { p = 1.0 / p; }
    165189            return p;
    166190          }
     
    205229        case OpCodes.Gamma: {
    206230            var x = Evaluate(dataset, ref row, state);
    207             if (double.IsNaN(x)) return double.NaN;
    208             else return alglib.gammafunction(x);
     231            if (double.IsNaN(x)) { return double.NaN; } else { return alglib.gammafunction(x); }
    209232          }
    210233        case OpCodes.Psi: {
     
    216239        case OpCodes.Dawson: {
    217240            var x = Evaluate(dataset, ref row, state);
    218             if (double.IsNaN(x)) return double.NaN;
     241            if (double.IsNaN(x)) { return double.NaN; }
    219242            return alglib.dawsonintegral(x);
    220243          }
    221244        case OpCodes.ExponentialIntegralEi: {
    222245            var x = Evaluate(dataset, ref row, state);
    223             if (double.IsNaN(x)) return double.NaN;
     246            if (double.IsNaN(x)) { return double.NaN; }
    224247            return alglib.exponentialintegralei(x);
    225248          }
     
    349372            int positiveSignals = 0;
    350373            for (int i = 0; i < currentInstr.nArguments; i++) {
    351               if (Evaluate(dataset, ref row, state) > 0.0) positiveSignals++;
     374              if (Evaluate(dataset, ref row, state) > 0.0) { positiveSignals++; }
    352375            }
    353376            return positiveSignals % 2 != 0 ? 1.0 : -1.0;
     
    356379            double x = Evaluate(dataset, ref row, state);
    357380            double y = Evaluate(dataset, ref row, state);
    358             if (x > y) return 1.0;
    359             else return -1.0;
     381            if (x > y) { return 1.0; } else { return -1.0; }
    360382          }
    361383        case OpCodes.LT: {
    362384            double x = Evaluate(dataset, ref row, state);
    363385            double y = Evaluate(dataset, ref row, state);
    364             if (x < y) return 1.0;
    365             else return -1.0;
     386            if (x < y) { return 1.0; } else { return -1.0; }
    366387          }
    367388        case OpCodes.TimeLag: {
     
    437458            var laggedVariableTreeNode = (LaggedVariableTreeNode)currentInstr.dynamicNode;
    438459            int actualRow = row + laggedVariableTreeNode.Lag;
    439             if (actualRow < 0 || actualRow >= dataset.Rows) return double.NaN;
     460            if (actualRow < 0 || actualRow >= dataset.Rows) { return double.NaN; }
    440461            return ((IList<double>)currentInstr.data)[actualRow] * laggedVariableTreeNode.Weight;
    441462          }
     
    459480            return trueBranch * p + falseBranch * (1 - p);
    460481          }
    461         default: throw new NotSupportedException();
     482        default:
     483          throw new NotSupportedException();
    462484      }
    463485    }
  • branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeLinearInterpreter.cs

    r12509 r14029  
    3535  public sealed class SymbolicDataAnalysisExpressionTreeLinearInterpreter : ParameterizedNamedItem, ISymbolicDataAnalysisExpressionTreeInterpreter {
    3636    private const string CheckExpressionsWithIntervalArithmeticParameterName = "CheckExpressionsWithIntervalArithmetic";
     37    private const string CheckExpressionsWithIntervalArithmeticParameterDescription = "Switch that determines if the interpreter checks the validity of expressions with interval arithmetic before evaluating the expression.";
    3738    private const string EvaluatedSolutionsParameterName = "EvaluatedSolutions";
    3839
     
    4849
    4950    #region parameter properties
    50     public IValueParameter<BoolValue> CheckExpressionsWithIntervalArithmeticParameter {
    51       get { return (IValueParameter<BoolValue>)Parameters[CheckExpressionsWithIntervalArithmeticParameterName]; }
    52     }
    53 
    54     public IValueParameter<IntValue> EvaluatedSolutionsParameter {
    55       get { return (IValueParameter<IntValue>)Parameters[EvaluatedSolutionsParameterName]; }
     51    public IFixedValueParameter<BoolValue> CheckExpressionsWithIntervalArithmeticParameter {
     52      get { return (IFixedValueParameter<BoolValue>)Parameters[CheckExpressionsWithIntervalArithmeticParameterName]; }
     53    }
     54
     55    public IFixedValueParameter<IntValue> EvaluatedSolutionsParameter {
     56      get { return (IFixedValueParameter<IntValue>)Parameters[EvaluatedSolutionsParameterName]; }
    5657    }
    5758    #endregion
    5859
    5960    #region properties
    60     public BoolValue CheckExpressionsWithIntervalArithmetic {
    61       get { return CheckExpressionsWithIntervalArithmeticParameter.Value; }
    62       set { CheckExpressionsWithIntervalArithmeticParameter.Value = value; }
    63     }
    64     public IntValue EvaluatedSolutions {
    65       get { return EvaluatedSolutionsParameter.Value; }
    66       set { EvaluatedSolutionsParameter.Value = value; }
     61    public bool CheckExpressionsWithIntervalArithmetic {
     62      get { return CheckExpressionsWithIntervalArithmeticParameter.Value.Value; }
     63      set { CheckExpressionsWithIntervalArithmeticParameter.Value.Value = value; }
     64    }
     65    public int EvaluatedSolutions {
     66      get { return EvaluatedSolutionsParameter.Value.Value; }
     67      set { EvaluatedSolutionsParameter.Value.Value = value; }
    6768    }
    6869    #endregion
     
    8485    public SymbolicDataAnalysisExpressionTreeLinearInterpreter()
    8586      : base("SymbolicDataAnalysisExpressionTreeLinearInterpreter", "Linear (non-recursive) interpreter for symbolic expression trees (does not support ADFs).") {
    86       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)));
    87       Parameters.Add(new ValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0)));
     87      Parameters.Add(new FixedValueParameter<BoolValue>(CheckExpressionsWithIntervalArithmeticParameterName, CheckExpressionsWithIntervalArithmeticParameterDescription, new BoolValue(false)));
     88      Parameters.Add(new FixedValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0)));
     89      interpreter = new SymbolicDataAnalysisExpressionTreeInterpreter();
     90    }
     91
     92    public SymbolicDataAnalysisExpressionTreeLinearInterpreter(string name, string description)
     93      : base(name, description) {
     94      Parameters.Add(new FixedValueParameter<BoolValue>(CheckExpressionsWithIntervalArithmeticParameterName, CheckExpressionsWithIntervalArithmeticParameterDescription, new BoolValue(false)));
     95      Parameters.Add(new FixedValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0)));
    8896      interpreter = new SymbolicDataAnalysisExpressionTreeInterpreter();
    8997    }
     
    9199    [StorableHook(HookType.AfterDeserialization)]
    92100    private void AfterDeserialization() {
    93       if (interpreter == null) interpreter = new SymbolicDataAnalysisExpressionTreeInterpreter();
     101      var evaluatedSolutions = new IntValue(0);
     102      var checkExpressionsWithIntervalArithmetic = new BoolValue(false);
     103      if (Parameters.ContainsKey(EvaluatedSolutionsParameterName)) {
     104        var evaluatedSolutionsParameter = (IValueParameter<IntValue>)Parameters[EvaluatedSolutionsParameterName];
     105        evaluatedSolutions = evaluatedSolutionsParameter.Value;
     106        Parameters.Remove(EvaluatedSolutionsParameterName);
     107      }
     108      Parameters.Add(new FixedValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", evaluatedSolutions));
     109      if (Parameters.ContainsKey(CheckExpressionsWithIntervalArithmeticParameterName)) {
     110        var checkExpressionsWithIntervalArithmeticParameter = (IValueParameter<BoolValue>)Parameters[CheckExpressionsWithIntervalArithmeticParameterName];
     111        Parameters.Remove(CheckExpressionsWithIntervalArithmeticParameterName);
     112        checkExpressionsWithIntervalArithmetic = checkExpressionsWithIntervalArithmeticParameter.Value;
     113      }
     114      Parameters.Add(new FixedValueParameter<BoolValue>(CheckExpressionsWithIntervalArithmeticParameterName, CheckExpressionsWithIntervalArithmeticParameterDescription, checkExpressionsWithIntervalArithmetic));
    94115    }
    95116
    96117    #region IStatefulItem
    97118    public void InitializeState() {
    98       EvaluatedSolutions.Value = 0;
     119      EvaluatedSolutions = 0;
    99120    }
    100121
     
    102123    #endregion
    103124
     125    private readonly object syncRoot = new object();
    104126    public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, IDataset dataset, IEnumerable<int> rows) {
    105       if (CheckExpressionsWithIntervalArithmetic.Value)
     127      if (CheckExpressionsWithIntervalArithmetic)
    106128        throw new NotSupportedException("Interval arithmetic is not yet supported in the symbolic data analysis interpreter.");
    107129
    108       lock (EvaluatedSolutions) {
    109         EvaluatedSolutions.Value++; // increment the evaluated solutions counter
     130      lock (syncRoot) {
     131        EvaluatedSolutions++; // increment the evaluated solutions counter
    110132      }
    111133
     
    122144        if (instr.opCode == OpCodes.Variable) {
    123145          if (row < 0 || row >= dataset.Rows) instr.value = double.NaN;
    124           var variableTreeNode = (VariableTreeNode)instr.dynamicNode;
    125           instr.value = ((IList<double>)instr.data)[row] * variableTreeNode.Weight;
     146          else {
     147            var variableTreeNode = (VariableTreeNode)instr.dynamicNode;
     148            instr.value = ((IList<double>)instr.data)[row] * variableTreeNode.Weight;
     149          }
    126150        } else if (instr.opCode == OpCodes.LagVariable) {
    127151          var laggedVariableTreeNode = (LaggedVariableTreeNode)instr.dynamicNode;
     
    190214        } else if (instr.opCode == OpCodes.Root) {
    191215          double x = code[instr.childIndex].value;
    192           double y = code[instr.childIndex + 1].value;
     216          double y = Math.Round(code[instr.childIndex + 1].value);
    193217          instr.value = Math.Pow(x, 1 / y);
    194218        } else if (instr.opCode == OpCodes.Exp) {
  • branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Plugin.cs.frame

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

    r12753 r14029  
    5353// by using the '*' as shown below:
    5454[assembly: AssemblyVersion("3.4.0.0")]
    55 [assembly: AssemblyFileVersion("3.4.8.$WCREV$")]
     55[assembly: AssemblyFileVersion("3.4.9.$WCREV$")]
  • branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisModel.cs

    r12012 r14029  
    2121
    2222using System;
     23using System.Collections.Generic;
    2324using System.Drawing;
     25using System.Linq;
    2426using HeuristicLab.Common;
    2527using HeuristicLab.Core;
     
    5658      get { return interpreter; }
    5759    }
     60
     61    public IEnumerable<string> VariablesUsedForPrediction {
     62      get {
     63        var variables =
     64          SymbolicExpressionTree.IterateNodesPrefix()
     65            .OfType<VariableTreeNode>()
     66            .Select(x => x.VariableName)
     67            .Distinct();
     68        var variableConditions = SymbolicExpressionTree.IterateNodesPrefix()
     69          .OfType<VariableConditionTreeNode>().Select(x => x.VariableName).Distinct();
     70
     71        return variables.Union(variableConditions).OrderBy(x => x);
     72      }
     73    }
     74
    5875    #endregion
    5976
     
    160177    }
    161178    #endregion
     179
    162180  }
    163181}
  • branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/VariableCondition.cs

    r12012 r14029  
    100100        allVariableNames.Clear();
    101101        allVariableNames.AddRange(value);
    102         VariableNames = value;
    103102      }
    104103    }
     
    149148          OnChanged(EventArgs.Empty);
    150149        }
     150      }
     151    }
     152
     153    public override bool Enabled {
     154      get {
     155        if (variableNames.Count == 0) return false;
     156        return base.Enabled;
     157      }
     158      set {
     159        if (variableNames.Count == 0) base.Enabled = false;
     160        else base.Enabled = value;
    151161      }
    152162    }
Note: See TracChangeset for help on using the changeset viewer.