Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblem.cs @ 7758

Last change on this file since 7758 was 7758, checked in by sforsten, 13 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
RevLine 
[5540]1#region License Information
2/* HeuristicLab
[7259]3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[5540]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
[7664]22using System;
23using System.Collections.Generic;
24using System.Linq;
[5540]25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
[7603]28using HeuristicLab.Problems.Instances;
[5540]29
30namespace HeuristicLab.Problems.DataAnalysis {
31  [StorableClass]
[5804]32  [Item("Regression Problem", "A general regression problem.")]
[5625]33  [Creatable("Problems")]
[7610]34  public class RegressionProblem : DataAnalysisProblem<IRegressionProblemData>, IRegressionProblem, IStorableContent,
[7683]35    IProblemInstanceConsumer<RegressionData>, IProblemInstanceExporter<RegressionData> {
[7017]36    public string Filename { get; set; }
37
[5540]38    [StorableConstructor]
[5697]39    protected RegressionProblem(bool deserializing) : base(deserializing) { }
40    protected RegressionProblem(RegressionProblem original, Cloner cloner) : base(original, cloner) { }
[5579]41    public override IDeepCloneable Clone(Cloner cloner) { return new RegressionProblem(this, cloner); }
42
[5540]43    public RegressionProblem()
44      : base() {
[5579]45      ProblemData = new RegressionProblemData();
[5540]46    }
[5623]47
[7603]48    public void Load(RegressionData data) {
49      Name = data.Name;
50      Description = data.Description;
51      Dataset dataset = new Dataset(data.InputVariables, data.Values);
52      ProblemData = new RegressionProblemData(dataset, data.AllowedInputVariables, data.TargetVariable);
[7610]53      ProblemData.TrainingPartition.Start = data.TrainingPartitionStart;
54      ProblemData.TrainingPartition.End = data.TrainingPartitionEnd;
55      ProblemData.TestPartition.Start = data.TestPartitionStart;
56      ProblemData.TestPartition.End = data.TestPartitionEnd;
[7603]57      OnReset();
58    }
[7664]59
60    public RegressionData 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      RegressionData regData = new RegressionData();
65      regData.Name = Name;
66      regData.Description = Description;
67      regData.TargetVariable = ProblemData.TargetVariable;
[7682]68      regData.InputVariables = ProblemData.InputVariables.Select(x => x.Value).ToArray();
69      regData.AllowedInputVariables = ProblemData.AllowedInputVariables.ToArray();
[7664]70      regData.TrainingPartitionStart = ProblemData.TrainingPartition.Start;
71      regData.TrainingPartitionEnd = ProblemData.TrainingPartition.End;
72      regData.TestPartitionStart = ProblemData.TestPartition.Start;
73      regData.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      }
[7682]79      regData.Values = Transformer.Transformation(data);
[7664]80
81      return regData;
82    }
[5540]83  }
84}
Note: See TracBrowser for help on using the repository browser.