Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Nca/SolutionCreation/NcaSolutionCreator.cs @ 15583

Last change on this file since 15583 was 15583, checked in by swagner, 6 years ago

#2640: Updated year of copyrights in license headers

File size: 4.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2018 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 HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Data;
25using HeuristicLab.Operators;
26using HeuristicLab.Optimization;
27using HeuristicLab.Parameters;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29using HeuristicLab.Problems.DataAnalysis;
30
31namespace HeuristicLab.Algorithms.DataAnalysis {
32  [Item("NcaSolutionCreator", "Creates an NCA solution with a given model and some given data.")]
33  [StorableClass]
34  public class NcaSolutionCreator : SingleSuccessorOperator, INcaSolutionCreator {
35
36    public ILookupParameter<IClassificationProblemData> ProblemDataParameter {
37      get { return (ILookupParameter<IClassificationProblemData>)Parameters["ProblemData"]; }
38    }
39
40    public ILookupParameter<INcaModel> NcaModelParameter {
41      get { return (ILookupParameter<INcaModel>)Parameters["NcaModel"]; }
42    }
43
44    public ILookupParameter<INcaClassificationSolution> NcaSolutionParameter {
45      get { return (ILookupParameter<INcaClassificationSolution>)Parameters["NcaSolution"]; }
46    }
47
48    public ILookupParameter<ResultCollection> ResultsParameter {
49      get { return (ILookupParameter<ResultCollection>)Parameters["Results"]; }
50    }
51
52    [StorableConstructor]
53    protected NcaSolutionCreator(bool deserializing) : base(deserializing) { }
54    protected NcaSolutionCreator(NcaSolutionCreator original, Cloner cloner) : base(original, cloner) { }
55    public NcaSolutionCreator()
56      : base() {
57      Parameters.Add(new LookupParameter<IClassificationProblemData>("ProblemData", "The classification problem data."));
58      Parameters.Add(new LookupParameter<INcaModel>("NcaModel", "The NCA model that should be created."));
59      Parameters.Add(new LookupParameter<INcaClassificationSolution>("NcaSolution", "The created NCA solution."));
60      Parameters.Add(new LookupParameter<ResultCollection>("Results", "The results collection to store the results."));
61    }
62
63    public override IDeepCloneable Clone(Cloner cloner) {
64      return new NcaSolutionCreator(this, cloner);
65    }
66
67    public override IOperation Apply() {
68      var problemData = ProblemDataParameter.ActualValue;
69      var model = NcaModelParameter.ActualValue;
70      var results = ResultsParameter.ActualValue;
71
72      var s = model.CreateClassificationSolution(problemData);
73      NcaSolutionParameter.ActualValue = s;
74
75      if (!results.ContainsKey("Solution")) {
76        results.Add(new Result("Solution", "The NCA classification solution", s));
77        results.Add(new Result("Accuracy (training)",
78                               "The accuracy of the NCA solution on the training partition.",
79                               new DoubleValue(s.TrainingAccuracy)));
80        results.Add(new Result("Accuracy (test)",
81                               "The accuracy of the NCA solution on the test partition.",
82                               new DoubleValue(s.TestAccuracy)));
83      } else {
84        results["Solution"].Value = s;
85        results["Accuracy (training)"].Value = new DoubleValue(s.TrainingAccuracy);
86        results["Accuracy (test)"].Value = new DoubleValue(s.TestAccuracy);
87      }
88      return base.Apply();
89    }
90  }
91}
Note: See TracBrowser for help on using the repository browser.