Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationProblem.cs @ 7758

Last change on this file since 7758 was 7758, checked in by sforsten, 12 years ago

#1784:

  • deleted not needed Consumer in ProblemInstanceProvider and IProblemInstanceProvider
  • changed protection level of exporter and consumer in ProblemInstanceProviderViewGeneric
  • renamed property FileExtension to FileName in ResourceClassificationInstanceProvider and ResourceRegressionInstanceProvider
  • deleted ImportProblemDataFromFile method from IDataAnalysisProblem and all classes and interfaces, which implement this method
  • removed unnecessary yield return in GetDoubleValues in the Dataset. Now it's a normal return statement
File size: 3.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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;
23using System.Collections.Generic;
24using System.Linq;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28using HeuristicLab.Problems.Instances;
29
30namespace HeuristicLab.Problems.DataAnalysis {
31  [StorableClass]
32  [Item("Classification Problem", "A general classification problem.")]
33  [Creatable("Problems")]
34  public class ClassificationProblem : DataAnalysisProblem<IClassificationProblemData>, IClassificationProblem, IStorableContent,
35    IProblemInstanceConsumer<ClassificationData>, IProblemInstanceExporter<ClassificationData> {
36    public string Filename { get; set; }
37
38    [StorableConstructor]
39    protected ClassificationProblem(bool deserializing) : base(deserializing) { }
40    protected ClassificationProblem(ClassificationProblem original, Cloner cloner) : base(original, cloner) { }
41    public override IDeepCloneable Clone(Cloner cloner) { return new ClassificationProblem(this, cloner); }
42
43    public ClassificationProblem()
44      : base() {
45      ProblemData = new ClassificationProblemData();
46    }
47
48    public void Load(ClassificationData data) {
49      Name = data.Name;
50      Description = data.Description;
51      Dataset dataset = new Dataset(data.InputVariables, data.Values);
52      ProblemData = new ClassificationProblemData(dataset, data.AllowedInputVariables, data.TargetVariable);
53      ProblemData.TrainingPartition.Start = data.TrainingPartitionStart;
54      ProblemData.TrainingPartition.End = data.TrainingPartitionEnd;
55      ProblemData.TestPartition.Start = data.TestPartitionStart;
56      ProblemData.TestPartition.End = data.TestPartitionEnd;
57      OnReset();
58    }
59
60    public ClassificationData Export() {
61      if (!ProblemData.InputVariables.Count.Equals(ProblemData.Dataset.DoubleVariables.Count()))
62        throw new ArgumentException("Not all input variables are double variables! (Export only works with double variables)");
63
64      ClassificationData claData = new ClassificationData();
65      claData.Name = Name;
66      claData.Description = Description;
67      claData.TargetVariable = ProblemData.TargetVariable;
68      claData.InputVariables = ProblemData.InputVariables.Select(x => x.Value).ToArray();
69      claData.AllowedInputVariables = ProblemData.AllowedInputVariables.ToArray();
70      claData.TrainingPartitionStart = ProblemData.TrainingPartition.Start;
71      claData.TrainingPartitionEnd = ProblemData.TrainingPartition.End;
72      claData.TestPartitionStart = ProblemData.TestPartition.Start;
73      claData.TestPartitionEnd = ProblemData.TestPartition.End;
74
75      List<List<double>> data = new List<List<double>>();
76      foreach (var variable in ProblemData.Dataset.DoubleVariables) {
77        data.Add(ProblemData.Dataset.GetDoubleValues(variable).ToList());
78      }
79      claData.Values = Transformer.Transformation(data);
80
81      return claData;
82    }
83  }
84}
Note: See TracBrowser for help on using the repository browser.