Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 4350 was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

File size: 4.3 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.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Optimization;
27using HeuristicLab.Parameters;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29using HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Analyzers;
30using HeuristicLab.Problems.DataAnalysis.SupportVectorMachine;
31
32namespace HeuristicLab.Problems.DataAnalysis.Regression.SupportVectorRegression {
33  [Item("BestSupportVectorRegressionSolutionAnalyzer", "An operator for analyzing the best solution of support vector regression problems.")]
34  [StorableClass]
35  public sealed class BestSupportVectorRegressionSolutionAnalyzer : RegressionSolutionAnalyzer {
36    private const string SupportVectorRegressionModelParameterName = "SupportVectorRegressionModel";
37    private const string BestSolutionInputvariableCountResultName = "Variables used by best solution";
38    private const string BestSolutionParameterName = "BestSolution";
39
40    #region parameter properties
41    public ScopeTreeLookupParameter<SupportVectorMachineModel> SupportVectorRegressionModelParameter {
42      get { return (ScopeTreeLookupParameter<SupportVectorMachineModel>)Parameters[SupportVectorRegressionModelParameterName]; }
43    }
44    public ILookupParameter<SupportVectorRegressionSolution> BestSolutionParameter {
45      get { return (ILookupParameter<SupportVectorRegressionSolution>)Parameters[BestSolutionParameterName]; }
46    }
47    #endregion
48    #region properties
49    public ItemArray<SupportVectorMachineModel> SupportVectorMachineModel {
50      get { return SupportVectorRegressionModelParameter.ActualValue; }
51    }
52    #endregion
53
54    public BestSupportVectorRegressionSolutionAnalyzer()
55      : base() {
56      Parameters.Add(new ScopeTreeLookupParameter<SupportVectorMachineModel>(SupportVectorRegressionModelParameterName, "The support vector regression models to analyze."));
57      Parameters.Add(new LookupParameter<SupportVectorRegressionSolution>(BestSolutionParameterName, "The best support vector regression solution."));
58    }
59
60    protected override DataAnalysisSolution UpdateBestSolution() {
61      double upperEstimationLimit = UpperEstimationLimit != null ? UpperEstimationLimit.Value : double.PositiveInfinity;
62      double lowerEstimationLimit = LowerEstimationLimit != null ? LowerEstimationLimit.Value : double.NegativeInfinity;
63
64      int i = Quality.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
65
66      if (BestSolutionQualityParameter.ActualValue == null || BestSolutionQualityParameter.ActualValue.Value > Quality[i].Value) {
67        IEnumerable<string> inputVariables = from var in ProblemData.InputVariables
68                                             where ProblemData.InputVariables.ItemChecked(var)
69                                             select var.Value;
70        var solution = new SupportVectorRegressionSolution(ProblemData, SupportVectorMachineModel[i], inputVariables, lowerEstimationLimit, upperEstimationLimit);
71
72        BestSolutionParameter.ActualValue = solution;
73        BestSolutionQualityParameter.ActualValue = Quality[i];
74
75        if (Results.ContainsKey(BestSolutionInputvariableCountResultName)) {
76          Results[BestSolutionInputvariableCountResultName].Value = new IntValue(inputVariables.Count());
77        } else {
78          Results.Add(new Result(BestSolutionInputvariableCountResultName, new IntValue(inputVariables.Count())));
79        }
80      }
81      return BestSolutionParameter.ActualValue;
82    }
83  }
84}
Note: See TracBrowser for help on using the repository browser.