Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3892


Ignore:
Timestamp:
06/02/10 19:10:35 (14 years ago)
Author:
gkronber
Message:

Improved code for analyzers for SVR and symbolic regression. #1009

Location:
trunk/sources
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.3/LinearRegression.cs

    r3886 r3892  
    120120
    121121    protected override void Problem_Reset(object sender, EventArgs e) {
    122       TrainingSamplesStartParameter.ActualValue = Problem.DataAnalysisProblemData.TrainingSamplesStart;
    123       TrainingSamplesEndParameter.ActualValue = Problem.DataAnalysisProblemData.TrainingSamplesEnd;     
     122      UpdateAlgorithmParameterValues();
    124123      base.Problem_Reset(sender, e);
    125124    }
     
    129128      solutionCreator.DataAnalysisProblemDataParameter.ActualName = Problem.DataAnalysisProblemDataParameter.Name;
    130129      evaluator.RegressionProblemDataParameter.ActualName = Problem.DataAnalysisProblemDataParameter.Name;
    131       analyzer.ProblemDataParameter.ActualName = Problem.DataAnalysisProblemDataParameter.Name;
    132       TrainingSamplesStartParameter.ActualValue = Problem.DataAnalysisProblemData.TrainingSamplesStart;
    133       TrainingSamplesEndParameter.ActualValue = Problem.DataAnalysisProblemData.TrainingSamplesEnd;
     130      analyzer.ProblemDataParameter.ActualName = Problem.DataAnalysisProblemDataParameter.Name;
     131      UpdateAlgorithmParameterValues();
    134132      Problem.Reset += new EventHandler(Problem_Reset);
    135133      base.OnProblemChanged();
    136134    }
     135
    137136
    138137    #endregion
     
    145144      solutionCreator.SymbolicExpressionTreeParameter.ActualName = LinearRegressionModelParameterName;
    146145
    147       evaluator.LowerEstimationLimitParameter.Value = new DoubleValue(double.NegativeInfinity);
    148       evaluator.UpperEstimationLimitParameter.Value = new DoubleValue(double.PositiveInfinity);
    149146      evaluator.SymbolicExpressionTreeParameter.ActualName = solutionCreator.SymbolicExpressionTreeParameter.ActualName;
    150147      evaluator.SymbolicExpressionTreeInterpreterParameter.ActualName = ModelInterpreterParameter.Name;
     
    161158      analyzer.QualityParameter.Depth = 0;
    162159      analyzer.SymbolicExpressionTreeInterpreterParameter.ActualName = ModelInterpreterParameter.Name;
    163       analyzer.LowerEstimationLimitParameter.Value = new DoubleValue(double.NegativeInfinity);
    164       analyzer.UpperEstimationLimitParameter.Value = new DoubleValue(double.PositiveInfinity);
    165160
    166161      if (Problem != null) {
     
    171166      }
    172167    }
     168
     169    private void UpdateAlgorithmParameterValues() {
     170      TrainingSamplesStartParameter.ActualValue = Problem.DataAnalysisProblemData.TrainingSamplesStart;
     171      TrainingSamplesEndParameter.ActualValue = Problem.DataAnalysisProblemData.TrainingSamplesEnd;
     172      //var targetValues =
     173      //  Problem.DataAnalysisProblemData.Dataset.GetVariableValues(Problem.DataAnalysisProblemData.TargetVariable.Value,
     174      //  TrainingSamplesStartParameter.Value.Value, TrainingSamplesEndParameter.Value.Value);
     175      //double range = targetValues.Max() - targetValues.Min();
     176      //double lowerEstimationLimit = targetValues.Average() - 10.0 * range;
     177      //double upperEstimationLimit = targetValues.Average() + 10.0 * range;
     178      //evaluator.LowerEstimationLimitParameter.Value = new DoubleValue(lowerEstimationLimit);
     179      //evaluator.UpperEstimationLimitParameter.Value = new DoubleValue(upperEstimationLimit);
     180      //analyzer.LowerEstimationLimitParameter.Value = new DoubleValue(lowerEstimationLimit);
     181      //analyzer.UpperEstimationLimitParameter.Value = new DoubleValue(upperEstimationLimit);
     182    }
    173183    #endregion
    174184  }
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.3/SupportVectorMachine.cs

    r3884 r3892  
    169169
    170170    protected override void Problem_Reset(object sender, EventArgs e) {
    171       TrainingSamplesStartParameter.ActualValue = Problem.DataAnalysisProblemData.TrainingSamplesStart;
    172       TrainingSamplesEndParameter.ActualValue = Problem.DataAnalysisProblemData.TrainingSamplesEnd;
     171      UpdateAlgorithmParameters();
    173172      base.Problem_Reset(sender, e);
    174173    }
     
    179178      evaluator.DataAnalysisProblemDataParameter.ActualName = Problem.DataAnalysisProblemDataParameter.Name;
    180179      analyzer.ProblemDataParameter.ActualName = Problem.DataAnalysisProblemDataParameter.Name;
    181       TrainingSamplesStartParameter.ActualValue = Problem.DataAnalysisProblemData.TrainingSamplesStart;
    182       TrainingSamplesEndParameter.ActualValue = Problem.DataAnalysisProblemData.TrainingSamplesEnd;
     180      UpdateAlgorithmParameters();
    183181      Problem.Reset += new EventHandler(Problem_Reset);
    184182      base.OnProblemChanged();
     
    210208      analyzer.QualityParameter.ActualName = mseEvaluator.MeanSquaredErrorParameter.ActualName;
    211209      analyzer.QualityParameter.Depth = 0;
    212       analyzer.LowerEstimationLimitParameter.Value = new DoubleValue(double.NegativeInfinity);
    213       analyzer.UpperEstimationLimitParameter.Value = new DoubleValue(double.PositiveInfinity);
    214210
    215211      if (Problem != null) {
     
    220216      }
    221217    }
     218
     219    private void UpdateAlgorithmParameters() {
     220      TrainingSamplesStartParameter.ActualValue = Problem.DataAnalysisProblemData.TrainingSamplesStart;
     221      TrainingSamplesEndParameter.ActualValue = Problem.DataAnalysisProblemData.TrainingSamplesEnd;
     222    }
    222223    #endregion
    223224  }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/HeuristicLab.Problems.DataAnalysis.Regression-3.3.csproj

    r3853 r3892  
    8484    <None Include="HeuristicLabProblemsDataAnalysisRegressionPlugin.cs.frame" />
    8585    <None Include="Properties\AssemblyInfo.frame" />
     86    <Compile Include="Analyzers\RegressionSolutionAnalyzer.cs">
     87      <SubType>Code</SubType>
     88    </Compile>
    8689    <Compile Include="HeuristicLabProblemsDataAnalysisRegressionPlugin.cs" />
    8790    <Compile Include="LinearRegression\LinearRegressionSolutionCreator.cs" />
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/SupportVectorRegression/BestSupportVectorRegressionSolutionAnalyzer.cs

    r3884 r3892  
    3636using HeuristicLab.Problems.DataAnalysis.Evaluators;
    3737using HeuristicLab.Problems.DataAnalysis.SupportVectorMachine;
     38using HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Analyzers;
    3839
    3940namespace HeuristicLab.Problems.DataAnalysis.Regression.SupportVectorRegression {
    40   [Item("BestSupportVectorRegressionSolutionAnalyzer", "An operator for analyzing the best support vector solution of regression problems.")]
     41  [Item("BestSupportVectorRegressionSolutionAnalyzer", "An operator for analyzing the best solution of support vector regression problems.")]
    4142  [StorableClass]
    42   public sealed class BestSupportVectorRegressionSolutionAnalyzer : SingleSuccessorOperator, IAnalyzer {
     43  public sealed class BestSupportVectorRegressionSolutionAnalyzer : RegressionSolutionAnalyzer {
    4344    private const string SupportVectorRegressionModelParameterName = "SupportVectorRegressionModel";
    44     private const string ProblemDataParameterName = "ProblemData";
    45     private const string QualityParameterName = "Quality";
    46     private const string UpperEstimationLimitParameterName = "UpperEstimationLimit";
    47     private const string LowerEstimationLimitParameterName = "LowerEstimationLimit";
     45    private const string BestSolutionInputvariableCountResultName = "Variables used by best solution";
    4846    private const string BestSolutionParameterName = "BestSolution";
    49     private const string BestSolutionQualityParameterName = "BestSolutionQuality";
    50     private const string ResultsParameterName = "Results";
    51     private const string BestSolutionResultName = "Best solution (on validiation set)";
    52     private const string BestSolutionInputvariableCountResultName = "Variables used by best solution";
    53     private const string BestSolutionTrainingRSquared = "Best solution R² (training)";
    54     private const string BestSolutionTestRSquared = "Best solution R² (test)";
    55     private const string BestSolutionTrainingMse = "Best solution mean squared error (training)";
    56     private const string BestSolutionTestMse = "Best solution mean squared error (test)";
    57     private const string BestSolutionTrainingRelativeError = "Best solution average relative error (training)";
    58     private const string BestSolutionTestRelativeError = "Best solution average relative error (test)";
    5947
     48    #region parameter properties
    6049    public ScopeTreeLookupParameter<SupportVectorMachineModel> SupportVectorRegressionModelParameter {
    6150      get { return (ScopeTreeLookupParameter<SupportVectorMachineModel>)Parameters[SupportVectorRegressionModelParameterName]; }
    62     }
    63     public IValueLookupParameter<DataAnalysisProblemData> ProblemDataParameter {
    64       get { return (IValueLookupParameter<DataAnalysisProblemData>)Parameters[ProblemDataParameterName]; }
    65     }
    66     public ScopeTreeLookupParameter<DoubleValue> QualityParameter {
    67       get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters[QualityParameterName]; }
    68     }
    69     public IValueLookupParameter<DoubleValue> UpperEstimationLimitParameter {
    70       get { return (IValueLookupParameter<DoubleValue>)Parameters[UpperEstimationLimitParameterName]; }
    71     }
    72     public IValueLookupParameter<DoubleValue> LowerEstimationLimitParameter {
    73       get { return (IValueLookupParameter<DoubleValue>)Parameters[LowerEstimationLimitParameterName]; }
    7451    }
    7552    public ILookupParameter<SupportVectorRegressionSolution> BestSolutionParameter {
    7653      get { return (ILookupParameter<SupportVectorRegressionSolution>)Parameters[BestSolutionParameterName]; }
    7754    }
    78     public ILookupParameter<DoubleValue> BestSolutionQualityParameter {
    79       get { return (ILookupParameter<DoubleValue>)Parameters[BestSolutionQualityParameterName]; }
     55    #endregion
     56    #region properties
     57    public ItemArray<SupportVectorMachineModel> SupportVectorMachineModel {
     58      get { return SupportVectorRegressionModelParameter.ActualValue; }
    8059    }
    81     public ILookupParameter<ResultCollection> ResultsParameter {
    82       get { return (ILookupParameter<ResultCollection>)Parameters[ResultsParameterName]; }
    83     }
     60    #endregion
    8461
    8562    public BestSupportVectorRegressionSolutionAnalyzer()
    8663      : base() {
    8764      Parameters.Add(new ScopeTreeLookupParameter<SupportVectorMachineModel>(SupportVectorRegressionModelParameterName, "The support vector regression models to analyze."));
    88       Parameters.Add(new ValueLookupParameter<DataAnalysisProblemData>(ProblemDataParameterName, "The problem data for which the support vector model is a solution."));
    89       Parameters.Add(new ValueLookupParameter<DoubleValue>(UpperEstimationLimitParameterName, "The upper estimation limit that was set for the evaluation of the support vector model."));
    90       Parameters.Add(new ValueLookupParameter<DoubleValue>(LowerEstimationLimitParameterName, "The lower estimation limit that was set for the evaluation of the support vector model."));
    91       Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>(QualityParameterName, "The qualities of the support vector models which should be analyzed."));
    92       Parameters.Add(new LookupParameter<SupportVectorRegressionSolution>(BestSolutionParameterName, "The best support vector solution."));
    93       Parameters.Add(new LookupParameter<DoubleValue>(BestSolutionQualityParameterName, "The quality of the best support vector solution."));
    94       Parameters.Add(new LookupParameter<ResultCollection>(ResultsParameterName, "The result collection where the best support vector solution should be stored."));
     65      Parameters.Add(new LookupParameter<SupportVectorRegressionSolution>(BestSolutionParameterName, "The best support vector regression solution."));
    9566    }
    9667
    97     public override IOperation Apply() {
    98       ItemArray<DoubleValue> qualities = QualityParameter.ActualValue;
    99       ResultCollection results = ResultsParameter.ActualValue;
    100       ItemArray<SupportVectorMachineModel> models = SupportVectorRegressionModelParameter.ActualValue;
    101       DataAnalysisProblemData problemData = ProblemDataParameter.ActualValue;
    102       DoubleValue upperEstimationLimit = UpperEstimationLimitParameter.ActualValue;
    103       DoubleValue lowerEstimationLimit = LowerEstimationLimitParameter.ActualValue;
    104       var inputVariables = ProblemDataParameter.ActualValue.InputVariables.Select(x => x.Value);
     68    protected override DataAnalysisSolution UpdateBestSolution() {
     69      double upperEstimationLimit = UpperEstimationLimit != null ? UpperEstimationLimit.Value : double.PositiveInfinity;
     70      double lowerEstimationLimit = LowerEstimationLimit != null ? LowerEstimationLimit.Value : double.NegativeInfinity;
    10571
    106       int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
     72      int i = Quality.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
    10773
    108       SupportVectorRegressionSolution solution = BestSolutionParameter.ActualValue;
    109       if (solution == null) {
    110         solution = new SupportVectorRegressionSolution(problemData, models[i], inputVariables, lowerEstimationLimit.Value, upperEstimationLimit.Value);
     74      if (BestSolutionQualityParameter.ActualValue == null || BestSolutionQualityParameter.ActualValue.Value > Quality[i].Value) {
     75        IEnumerable<string> inputVariables = from var in ProblemData.InputVariables
     76                                             where ProblemData.InputVariables.ItemChecked(var)
     77                                             select var.Value;
     78        var solution = new SupportVectorRegressionSolution(ProblemData, SupportVectorMachineModel[i], inputVariables, lowerEstimationLimit, upperEstimationLimit);
     79
    11180        BestSolutionParameter.ActualValue = solution;
    112         BestSolutionQualityParameter.ActualValue = qualities[i];
    113         results.Add(new Result(BestSolutionResultName, solution));
    114         results.Add(new Result(BestSolutionInputvariableCountResultName, new IntValue(inputVariables.Count())));
    115         #region calculate R2,MSE,Rel Error
    116         double[] trainingValues = problemData.Dataset.GetVariableValues(
    117           problemData.TargetVariable.Value,
    118           problemData.TrainingSamplesStart.Value,
    119           problemData.TrainingSamplesEnd.Value);
    120         double[] testValues = problemData.Dataset.GetVariableValues(
    121           problemData.TargetVariable.Value,
    122           problemData.TestSamplesStart.Value,
    123           problemData.TestSamplesEnd.Value);
    124         double trainingR2 = SimpleRSquaredEvaluator.Calculate(trainingValues, solution.EstimatedTrainingValues);
    125         double testR2 = SimpleRSquaredEvaluator.Calculate(testValues, solution.EstimatedTestValues);
    126         double trainingMse = SimpleMSEEvaluator.Calculate(trainingValues, solution.EstimatedTrainingValues);
    127         double testMse = SimpleMSEEvaluator.Calculate(testValues, solution.EstimatedTestValues);
    128         double trainingRelError = SimpleMeanAbsolutePercentageErrorEvaluator.Calculate(trainingValues, solution.EstimatedTrainingValues);
    129         double testRelError = SimpleMeanAbsolutePercentageErrorEvaluator.Calculate(testValues, solution.EstimatedTestValues);
    130         results.Add(new Result(BestSolutionTrainingRSquared, new DoubleValue(trainingR2)));
    131         results.Add(new Result(BestSolutionTestRSquared, new DoubleValue(testR2)));
    132         results.Add(new Result(BestSolutionTrainingMse, new DoubleValue(trainingMse)));
    133         results.Add(new Result(BestSolutionTestMse, new DoubleValue(testMse)));
    134         results.Add(new Result(BestSolutionTrainingRelativeError, new DoubleValue(trainingRelError)));
    135         results.Add(new Result(BestSolutionTestRelativeError, new DoubleValue(testRelError)));
    136         #endregion
    137       } else {
    138         if (BestSolutionQualityParameter.ActualValue.Value > qualities[i].Value) {
    139           solution = new SupportVectorRegressionSolution(problemData, models[i], inputVariables, lowerEstimationLimit.Value, upperEstimationLimit.Value);
    140           BestSolutionParameter.ActualValue = solution;
    141           BestSolutionQualityParameter.ActualValue = qualities[i];
    142           results[BestSolutionResultName].Value = solution;
    143           results[BestSolutionInputvariableCountResultName].Value = new IntValue(inputVariables.Count());
    144           #region update R2,MSE, Rel Error
    145           double[] trainingValues = problemData.Dataset.GetVariableValues(
    146             problemData.TargetVariable.Value,
    147             problemData.TrainingSamplesStart.Value,
    148             problemData.TrainingSamplesEnd.Value);
    149           double[] testValues = problemData.Dataset.GetVariableValues(
    150             problemData.TargetVariable.Value,
    151             problemData.TestSamplesStart.Value,
    152             problemData.TestSamplesEnd.Value);
    153           double trainingR2 = SimpleRSquaredEvaluator.Calculate(trainingValues, solution.EstimatedTrainingValues);
    154           double testR2 = SimpleRSquaredEvaluator.Calculate(testValues, solution.EstimatedTestValues);
    155           double trainingMse = SimpleMSEEvaluator.Calculate(trainingValues, solution.EstimatedTrainingValues);
    156           double testMse = SimpleMSEEvaluator.Calculate(testValues, solution.EstimatedTestValues);
    157           double trainingRelError = SimpleMeanAbsolutePercentageErrorEvaluator.Calculate(trainingValues, solution.EstimatedTrainingValues);
    158           double testRelError = SimpleMeanAbsolutePercentageErrorEvaluator.Calculate(testValues, solution.EstimatedTestValues);
    159           results[BestSolutionTrainingRSquared].Value = new DoubleValue(trainingR2);
    160           results[BestSolutionTestRSquared].Value = new DoubleValue(testR2);
    161           results[BestSolutionTrainingMse].Value = new DoubleValue(trainingMse);
    162           results[BestSolutionTestMse].Value = new DoubleValue(testMse);
    163           results[BestSolutionTrainingRelativeError].Value = new DoubleValue(trainingRelError);
    164           results[BestSolutionTestRelativeError].Value = new DoubleValue(testRelError);
    165           #endregion
     81        BestSolutionQualityParameter.ActualValue = Quality[i];
     82
     83        if (Results.ContainsKey(BestSolutionInputvariableCountResultName)) {
     84          Results[BestSolutionInputvariableCountResultName].Value = new IntValue(inputVariables.Count());
     85        } else {
     86          Results.Add(new Result(BestSolutionInputvariableCountResultName, new IntValue(inputVariables.Count())));
    16687        }
    16788      }
    168 
    169       return base.Apply();
     89      return BestSolutionParameter.ActualValue;
    17090    }
    17191  }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers/BestSymbolicRegressionSolutionAnalyzer.cs

    r3710 r3892  
    3939  [Item("BestSymbolicRegressionSolutionAnalyzer", "An operator for analyzing the best solution of symbolic regression problems given in symbolic expression tree encoding.")]
    4040  [StorableClass]
    41   public sealed class BestSymbolicRegressionSolutionAnalyzer : SingleSuccessorOperator, ISymbolicRegressionAnalyzer {
     41  public sealed class BestSymbolicRegressionSolutionAnalyzer : RegressionSolutionAnalyzer, ISymbolicRegressionAnalyzer {
    4242    private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
    4343    private const string SymbolicExpressionTreeInterpreterParameterName = "SymbolicExpressionTreeInterpreter";
    44     private const string ProblemDataParameterName = "ProblemData";
    45     private const string QualityParameterName = "Quality";
    46     private const string UpperEstimationLimitParameterName = "UpperEstimationLimit";
    47     private const string LowerEstimationLimitParameterName = "LowerEstimationLimit";
     44    private const string BestSolutionInputvariableCountResultName = "Variables used by best solution";
    4845    private const string BestSolutionParameterName = "BestSolution";
    49     private const string BestSolutionQualityParameterName = "BestSolutionQuality";
    50     private const string ResultsParameterName = "Results";
    51     private const string BestSolutionResultName = "Best solution (on validiation set)";
    52     private const string BestSolutionInputvariableCountResultName = "Variables used by best solution";
    53     private const string BestSolutionTrainingRSquared = "Best solution R² (training)";
    54     private const string BestSolutionTestRSquared = "Best solution R² (test)";
    55     private const string BestSolutionTrainingMse = "Best solution mean squared error (training)";
    56     private const string BestSolutionTestMse = "Best solution mean squared error (test)";
    57     private const string BestSolutionTrainingRelativeError = "Best solution average relative error (training)";
    58     private const string BestSolutionTestRelativeError = "Best solution average relative error (test)";
    5946
     47    #region parameter properties
    6048    public ScopeTreeLookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter {
    6149      get { return (ScopeTreeLookupParameter<SymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }
     
    6452      get { return (IValueLookupParameter<ISymbolicExpressionTreeInterpreter>)Parameters[SymbolicExpressionTreeInterpreterParameterName]; }
    6553    }
    66     public IValueLookupParameter<DataAnalysisProblemData> ProblemDataParameter {
    67       get { return (IValueLookupParameter<DataAnalysisProblemData>)Parameters[ProblemDataParameterName]; }
    68     }
    69     public ScopeTreeLookupParameter<DoubleValue> QualityParameter {
    70       get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters[QualityParameterName]; }
    71     }
    72     public IValueLookupParameter<DoubleValue> UpperEstimationLimitParameter {
    73       get { return (IValueLookupParameter<DoubleValue>)Parameters[UpperEstimationLimitParameterName]; }
    74     }
    75     public IValueLookupParameter<DoubleValue> LowerEstimationLimitParameter {
    76       get { return (IValueLookupParameter<DoubleValue>)Parameters[LowerEstimationLimitParameterName]; }
    77     }
    7854    public ILookupParameter<SymbolicRegressionSolution> BestSolutionParameter {
    7955      get { return (ILookupParameter<SymbolicRegressionSolution>)Parameters[BestSolutionParameterName]; }
    8056    }
    81     public ILookupParameter<DoubleValue> BestSolutionQualityParameter {
    82       get { return (ILookupParameter<DoubleValue>)Parameters[BestSolutionQualityParameterName]; }
     57    #endregion
     58    #region properties
     59    public ISymbolicExpressionTreeInterpreter SymbolicExpressionTreeInterpreter {
     60      get { return SymbolicExpressionTreeInterpreterParameter.ActualValue; }
    8361    }
    84     public ILookupParameter<ResultCollection> ResultsParameter {
    85       get { return (ILookupParameter<ResultCollection>)Parameters[ResultsParameterName]; }
     62    public ItemArray<SymbolicExpressionTree> SymbolicExpressionTree {
     63      get { return SymbolicExpressionTreeParameter.ActualValue; }
    8664    }
     65    #endregion
    8766
    8867    public BestSymbolicRegressionSolutionAnalyzer()
     
    9069      Parameters.Add(new ScopeTreeLookupParameter<SymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression trees to analyze."));
    9170      Parameters.Add(new ValueLookupParameter<ISymbolicExpressionTreeInterpreter>(SymbolicExpressionTreeInterpreterParameterName, "The interpreter that should be used for the analysis of symbolic expression trees."));
    92       Parameters.Add(new ValueLookupParameter<DataAnalysisProblemData>(ProblemDataParameterName, "The problem data for which the symbolic expression tree is a solution."));
    93       Parameters.Add(new ValueLookupParameter<DoubleValue>(UpperEstimationLimitParameterName, "The upper estimation limit that was set for the evaluation of the symbolic expression trees."));
    94       Parameters.Add(new ValueLookupParameter<DoubleValue>(LowerEstimationLimitParameterName, "The lower estimation limit that was set for the evaluation of the symbolic expression trees."));
    95       Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>(QualityParameterName, "The qualities of the symbolic regression trees which should be analyzed."));
    9671      Parameters.Add(new LookupParameter<SymbolicRegressionSolution>(BestSolutionParameterName, "The best symbolic regression solution."));
    97       Parameters.Add(new LookupParameter<DoubleValue>(BestSolutionQualityParameterName, "The quality of the best symbolic regression solution."));
    98       Parameters.Add(new LookupParameter<ResultCollection>(ResultsParameterName, "The result collection where the best symbolic regression solution should be stored."));
    9972    }
    10073
    101     public override IOperation Apply() {
    102       ItemArray<DoubleValue> qualities = QualityParameter.ActualValue;
    103       ResultCollection results = ResultsParameter.ActualValue;
    104       ISymbolicExpressionTreeInterpreter interpreter = SymbolicExpressionTreeInterpreterParameter.ActualValue;
    105       ItemArray<SymbolicExpressionTree> expressions = SymbolicExpressionTreeParameter.ActualValue;
    106       DataAnalysisProblemData problemData = ProblemDataParameter.ActualValue;
    107       DoubleValue upperEstimationLimit = UpperEstimationLimitParameter.ActualValue;
    108       DoubleValue lowerEstimationLimit = LowerEstimationLimitParameter.ActualValue;
     74    protected override DataAnalysisSolution UpdateBestSolution() {
     75      double upperEstimationLimit = UpperEstimationLimit != null ? UpperEstimationLimit.Value : double.PositiveInfinity;
     76      double lowerEstimationLimit = LowerEstimationLimit != null ? LowerEstimationLimit.Value : double.NegativeInfinity;
    10977
    110       int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
     78      int i = Quality.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
    11179
    112       SymbolicRegressionSolution solution = BestSolutionParameter.ActualValue;
    113       if (solution == null) {
    114         var model = new SymbolicRegressionModel((ISymbolicExpressionTreeInterpreter)interpreter.Clone(), expressions[i], GetInputVariables(expressions[i]));
    115         solution = new SymbolicRegressionSolution(problemData, model, lowerEstimationLimit.Value, upperEstimationLimit.Value);
     80      if (BestSolutionQualityParameter.ActualValue == null || BestSolutionQualityParameter.ActualValue.Value > Quality[i].Value) {
     81        var model = new SymbolicRegressionModel((ISymbolicExpressionTreeInterpreter)SymbolicExpressionTreeInterpreter.Clone(),
     82          SymbolicExpressionTree[i],
     83          GetInputVariables(SymbolicExpressionTree[i]));
     84        var solution = new SymbolicRegressionSolution(ProblemData, model, lowerEstimationLimit, upperEstimationLimit);
     85
    11686        BestSolutionParameter.ActualValue = solution;
    117         BestSolutionQualityParameter.ActualValue = qualities[i];
    118         results.Add(new Result(BestSolutionResultName, solution));
    119         results.Add(new Result(BestSolutionInputvariableCountResultName, new IntValue(model.InputVariables.Count())));
    120         #region calculate R2,MSE,Rel Error
    121         double[] trainingValues = problemData.Dataset.GetVariableValues(
    122           problemData.TargetVariable.Value,
    123           problemData.TrainingSamplesStart.Value,
    124           problemData.TrainingSamplesEnd.Value);
    125         double[] testValues = problemData.Dataset.GetVariableValues(
    126           problemData.TargetVariable.Value,
    127           problemData.TestSamplesStart.Value,
    128           problemData.TestSamplesEnd.Value);
    129         double trainingR2 = SimpleRSquaredEvaluator.Calculate(trainingValues, solution.EstimatedTrainingValues);
    130         double testR2 = SimpleRSquaredEvaluator.Calculate(testValues, solution.EstimatedTestValues);
    131         double trainingMse = SimpleMSEEvaluator.Calculate(trainingValues, solution.EstimatedTrainingValues);
    132         double testMse = SimpleMSEEvaluator.Calculate(testValues, solution.EstimatedTestValues);
    133         double trainingRelError = SimpleMeanAbsolutePercentageErrorEvaluator.Calculate(trainingValues, solution.EstimatedTrainingValues);
    134         double testRelError = SimpleMeanAbsolutePercentageErrorEvaluator.Calculate(testValues, solution.EstimatedTestValues);
    135         results.Add(new Result(BestSolutionTrainingRSquared, new DoubleValue(trainingR2)));
    136         results.Add(new Result(BestSolutionTestRSquared, new DoubleValue(testR2)));
    137         results.Add(new Result(BestSolutionTrainingMse, new DoubleValue(trainingMse)));
    138         results.Add(new Result(BestSolutionTestMse, new DoubleValue(testMse)));
    139         results.Add(new Result(BestSolutionTrainingRelativeError, new DoubleValue(trainingRelError)));
    140         results.Add(new Result(BestSolutionTestRelativeError, new DoubleValue(testRelError)));
    141         #endregion
    142       } else {
    143         if (BestSolutionQualityParameter.ActualValue.Value > qualities[i].Value) {
    144           var model = new SymbolicRegressionModel((ISymbolicExpressionTreeInterpreter)interpreter.Clone(), expressions[i], GetInputVariables(expressions[i]));
    145           solution = new SymbolicRegressionSolution(problemData, model, lowerEstimationLimit.Value, upperEstimationLimit.Value);
    146           BestSolutionParameter.ActualValue = solution;
    147           BestSolutionQualityParameter.ActualValue = qualities[i];
    148           results[BestSolutionResultName].Value = solution;
    149           results[BestSolutionInputvariableCountResultName].Value = new IntValue(model.InputVariables.Count());
    150           #region update R2,MSE, Rel Error
    151           double[] trainingValues = problemData.Dataset.GetVariableValues(
    152             problemData.TargetVariable.Value,
    153             problemData.TrainingSamplesStart.Value,
    154             problemData.TrainingSamplesEnd.Value);
    155           double[] testValues = problemData.Dataset.GetVariableValues(
    156             problemData.TargetVariable.Value,
    157             problemData.TestSamplesStart.Value,
    158             problemData.TestSamplesEnd.Value);
    159           double trainingR2 = SimpleRSquaredEvaluator.Calculate(trainingValues, solution.EstimatedTrainingValues);
    160           double testR2 = SimpleRSquaredEvaluator.Calculate(testValues, solution.EstimatedTestValues);
    161           double trainingMse = SimpleMSEEvaluator.Calculate(trainingValues, solution.EstimatedTrainingValues);
    162           double testMse = SimpleMSEEvaluator.Calculate(testValues, solution.EstimatedTestValues);
    163           double trainingRelError = SimpleMeanAbsolutePercentageErrorEvaluator.Calculate(trainingValues, solution.EstimatedTrainingValues);
    164           double testRelError = SimpleMeanAbsolutePercentageErrorEvaluator.Calculate(testValues, solution.EstimatedTestValues);
    165           results[BestSolutionTrainingRSquared].Value = new DoubleValue(trainingR2);
    166           results[BestSolutionTestRSquared].Value = new DoubleValue(testR2);
    167           results[BestSolutionTrainingMse].Value = new DoubleValue(trainingMse);
    168           results[BestSolutionTestMse].Value = new DoubleValue(testMse);
    169           results[BestSolutionTrainingRelativeError].Value = new DoubleValue(trainingRelError);
    170           results[BestSolutionTestRelativeError].Value = new DoubleValue(testRelError);
    171           #endregion
     87        BestSolutionQualityParameter.ActualValue = Quality[i];
     88
     89        if (Results.ContainsKey(BestSolutionInputvariableCountResultName)) {
     90          Results[BestSolutionInputvariableCountResultName].Value = new IntValue(model.InputVariables.Count());
     91        } else {
     92          Results.Add(new Result(BestSolutionInputvariableCountResultName, new IntValue(model.InputVariables.Count())));
    17293        }
    17394      }
    174 
    175       return base.Apply();
     95      return BestSolutionParameter.ActualValue;
    17696    }
    17797
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SimpleSymbolicRegressionEvaluator.cs

    r3652 r3892  
    125125      int start = SamplesStart.Value;
    126126      int end = SamplesEnd.Value;
    127       double lowerEstimationLimit = LowerEstimationLimit.Value;
    128       double upperEstimationLimit = UpperEstimationLimit.Value;
     127      double lowerEstimationLimit = LowerEstimationLimit != null ? LowerEstimationLimit.Value : double.NegativeInfinity;
     128      double upperEstimationLimit = UpperEstimationLimit != null ? UpperEstimationLimit.Value : double.PositiveInfinity;
    129129      int targetVariableIndex = dataset.GetVariableIndex(targetVariable);
    130130      var estimatedValues = from x in interpreter.GetSymbolicExpressionTreeValues(tree, dataset, Enumerable.Range(start, end - start))
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Dataset.cs

    r3839 r3892  
    231231    public override IDeepCloneable Clone(Cloner cloner) {
    232232      Dataset clone = (Dataset)base.Clone(cloner);
    233       clone.data = data;
     233      clone.data = (double[,])data.Clone();
    234234      clone.variableNames = (string[])variableNames.Clone();
    235235      return clone;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/SupportVectorMachine/ParameterAdjustmentProblem/SupportVectorMachineParameterAdjustmentBestSolutionAnalyzer.cs

    r3884 r3892  
    8181      get { return KernelTypeParameter.Value; }
    8282    }
    83     public ILookupParameter<SupportVectorMachineModel> BestSolutionParameter {
    84       get { return (ILookupParameter<SupportVectorMachineModel>)Parameters[BestSolutionParameterName]; }
     83    public ILookupParameter<DataAnalysisSolution> BestSolutionParameter {
     84      get { return (ILookupParameter<DataAnalysisSolution>)Parameters[BestSolutionParameterName]; }
    8585    }
    8686    public ILookupParameter<DoubleValue> BestSolutionQualityParameter {
     
    102102      Parameters.Add(new ValueLookupParameter<StringValue>(KernelTypeParameterName, "The kernel type to use for the SVM.", rbfKernelType));
    103103      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>(QualityParameterName, "The cross validation quality reached with the given parameters."));
    104       Parameters.Add(new LookupParameter<SupportVectorMachineModel>(BestSolutionParameterName, "The best support vector solution."));
     104      Parameters.Add(new LookupParameter<DataAnalysisSolution>(BestSolutionParameterName, "The best support vector solution."));
    105105      Parameters.Add(new LookupParameter<DoubleValue>(BestSolutionQualityParameterName, "The quality of the best support vector model."));
    106106      Parameters.Add(new LookupParameter<ResultCollection>(ResultsParameterName, "The result collection where the best support vector solution should be stored."));
     
    124124      DataAnalysisProblemData problemData = DataAnalysisProblemData;
    125125
    126       SupportVectorMachineModel bestModel = BestSolutionParameter.ActualValue;
     126      DataAnalysisSolution bestSolution = BestSolutionParameter.ActualValue;
    127127      if (bestModel == null) {
    128128        bestModel = SupportVectorMachineModelCreator.TrainModel(DataAnalysisProblemData,
Note: See TracChangeset for help on using the changeset viewer.