Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Scheduling/HeuristicLab.Problems.DataAnalysis.Regression/3.3/SupportVectorRegression/BestSupportVectorRegressionSolutionAnalyzer.cs @ 6274

Last change on this file since 6274 was 5863, checked in by mkommend, 14 years ago

#1418: Added NonDiscoverableType attribute to outdated analyzers.

File size: 4.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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.PluginInfrastructure;
31using HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Analyzers;
32using HeuristicLab.Problems.DataAnalysis.SupportVectorMachine;
33
34namespace HeuristicLab.Problems.DataAnalysis.Regression.SupportVectorRegression {
35  [Item("BestSupportVectorRegressionSolutionAnalyzer", "An operator for analyzing the best solution of support vector regression problems.")]
36  [StorableClass]
37  [NonDiscoverableType]
38  public sealed class BestSupportVectorRegressionSolutionAnalyzer : RegressionSolutionAnalyzer {
39    private const string SupportVectorRegressionModelParameterName = "SupportVectorRegressionModel";
40    private const string BestSolutionInputvariableCountResultName = "Variables used by best solution";
41    private const string BestSolutionParameterName = "BestSolution";
42
43    #region parameter properties
44    public ScopeTreeLookupParameter<SupportVectorMachineModel> SupportVectorRegressionModelParameter {
45      get { return (ScopeTreeLookupParameter<SupportVectorMachineModel>)Parameters[SupportVectorRegressionModelParameterName]; }
46    }
47    public ILookupParameter<SupportVectorRegressionSolution> BestSolutionParameter {
48      get { return (ILookupParameter<SupportVectorRegressionSolution>)Parameters[BestSolutionParameterName]; }
49    }
50    #endregion
51    #region properties
52    public ItemArray<SupportVectorMachineModel> SupportVectorMachineModel {
53      get { return SupportVectorRegressionModelParameter.ActualValue; }
54    }
55    #endregion
56
57    [StorableConstructor]
58    private BestSupportVectorRegressionSolutionAnalyzer(bool deserializing) : base(deserializing) { }
59    private BestSupportVectorRegressionSolutionAnalyzer(BestSupportVectorRegressionSolutionAnalyzer original, Cloner cloner) : base(original, cloner) { }
60    public BestSupportVectorRegressionSolutionAnalyzer()
61      : base() {
62      Parameters.Add(new ScopeTreeLookupParameter<SupportVectorMachineModel>(SupportVectorRegressionModelParameterName, "The support vector regression models to analyze."));
63      Parameters.Add(new LookupParameter<SupportVectorRegressionSolution>(BestSolutionParameterName, "The best support vector regression solution."));
64    }
65
66    public override IDeepCloneable Clone(Cloner cloner) {
67      return new BestSupportVectorRegressionSolutionAnalyzer(this, cloner);
68    }
69
70    protected override DataAnalysisSolution UpdateBestSolution() {
71      double upperEstimationLimit = UpperEstimationLimit != null ? UpperEstimationLimit.Value : double.PositiveInfinity;
72      double lowerEstimationLimit = LowerEstimationLimit != null ? LowerEstimationLimit.Value : double.NegativeInfinity;
73
74      int i = Quality.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
75
76      if (BestSolutionQualityParameter.ActualValue == null || BestSolutionQualityParameter.ActualValue.Value > Quality[i].Value) {
77        IEnumerable<string> inputVariables = from var in ProblemData.InputVariables
78                                             where ProblemData.InputVariables.ItemChecked(var)
79                                             select var.Value;
80        var solution = new SupportVectorRegressionSolution((DataAnalysisProblemData)ProblemData.Clone(), SupportVectorMachineModel[i], inputVariables, lowerEstimationLimit, upperEstimationLimit);
81
82        BestSolutionParameter.ActualValue = solution;
83        BestSolutionQualityParameter.ActualValue = Quality[i];
84
85        if (Results.ContainsKey(BestSolutionInputvariableCountResultName)) {
86          Results[BestSolutionInputvariableCountResultName].Value = new IntValue(inputVariables.Count());
87        } else {
88          Results.Add(new Result(BestSolutionInputvariableCountResultName, new IntValue(inputVariables.Count())));
89        }
90      }
91      return BestSolutionParameter.ActualValue;
92    }
93  }
94}
Note: See TracBrowser for help on using the repository browser.