Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ParameterBinding/HeuristicLab.Problems.DataAnalysis.Regression/3.3/SupportVectorRegression/BestSupportVectorRegressionSolutionAnalyzer.cs @ 5955

Last change on this file since 5955 was 4722, checked in by swagner, 14 years ago

Merged cloning refactoring branch back into trunk (#922)

File size: 4.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System.Collections.Generic;
23using System.Linq;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27using HeuristicLab.Optimization;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30using HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Analyzers;
31using HeuristicLab.Problems.DataAnalysis.SupportVectorMachine;
32
33namespace HeuristicLab.Problems.DataAnalysis.Regression.SupportVectorRegression {
34  [Item("BestSupportVectorRegressionSolutionAnalyzer", "An operator for analyzing the best solution of support vector regression problems.")]
35  [StorableClass]
36  public sealed class BestSupportVectorRegressionSolutionAnalyzer : RegressionSolutionAnalyzer {
37    private const string SupportVectorRegressionModelParameterName = "SupportVectorRegressionModel";
38    private const string BestSolutionInputvariableCountResultName = "Variables used by best solution";
39    private const string BestSolutionParameterName = "BestSolution";
40
41    #region parameter properties
42    public ScopeTreeLookupParameter<SupportVectorMachineModel> SupportVectorRegressionModelParameter {
43      get { return (ScopeTreeLookupParameter<SupportVectorMachineModel>)Parameters[SupportVectorRegressionModelParameterName]; }
44    }
45    public ILookupParameter<SupportVectorRegressionSolution> BestSolutionParameter {
46      get { return (ILookupParameter<SupportVectorRegressionSolution>)Parameters[BestSolutionParameterName]; }
47    }
48    #endregion
49    #region properties
50    public ItemArray<SupportVectorMachineModel> SupportVectorMachineModel {
51      get { return SupportVectorRegressionModelParameter.ActualValue; }
52    }
53    #endregion
54
55    [StorableConstructor]
56    private BestSupportVectorRegressionSolutionAnalyzer(bool deserializing) : base(deserializing) { }
57    private BestSupportVectorRegressionSolutionAnalyzer(BestSupportVectorRegressionSolutionAnalyzer original, Cloner cloner) : base(original, cloner) { }
58    public BestSupportVectorRegressionSolutionAnalyzer()
59      : base() {
60      Parameters.Add(new ScopeTreeLookupParameter<SupportVectorMachineModel>(SupportVectorRegressionModelParameterName, "The support vector regression models to analyze."));
61      Parameters.Add(new LookupParameter<SupportVectorRegressionSolution>(BestSolutionParameterName, "The best support vector regression solution."));
62    }
63
64    public override IDeepCloneable Clone(Cloner cloner) {
65      return new BestSupportVectorRegressionSolutionAnalyzer(this, cloner);
66    }
67
68    protected override DataAnalysisSolution UpdateBestSolution() {
69      double upperEstimationLimit = UpperEstimationLimit != null ? UpperEstimationLimit.Value : double.PositiveInfinity;
70      double lowerEstimationLimit = LowerEstimationLimit != null ? LowerEstimationLimit.Value : double.NegativeInfinity;
71
72      int i = Quality.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
73
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((DataAnalysisProblemData)ProblemData.Clone(), SupportVectorMachineModel[i], inputVariables, lowerEstimationLimit, upperEstimationLimit);
79
80        BestSolutionParameter.ActualValue = solution;
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())));
87        }
88      }
89      return BestSolutionParameter.ActualValue;
90    }
91  }
92}
Note: See TracBrowser for help on using the repository browser.