Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/27/12 10:05:59 (13 years ago)
Author:
sforsten
Message:

#1784:

  • added Keijzer, Korns, Vladislavleva und Nguyen regression problem instances
  • changes have been made in the ProblemView. Some parts have been replaced with views from Problems.Instances.Views
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblem.cs

    r7610 r7664  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
     24using System.Linq;
    2225using HeuristicLab.Common;
    2326using HeuristicLab.Core;
     
    3033  [Creatable("Problems")]
    3134  public class RegressionProblem : DataAnalysisProblem<IRegressionProblemData>, IRegressionProblem, IStorableContent,
    32     IProblemInstanceConsumer<RegressionData> {
     35    IProblemInstanceConsumer<RegressionData>, IProblemInstanceExporter<RegressionData>, IProblemInstanceConsumer {
    3336    public string Filename { get; set; }
    3437
     
    5962      OnReset();
    6063    }
     64
     65    public RegressionData Export() {
     66      if (!ProblemData.InputVariables.Count.Equals(ProblemData.Dataset.DoubleVariables.Count()))
     67        throw new ArgumentException("Not all input variables are double variables! (Export only works with double variables)");
     68
     69      RegressionData regData = new RegressionData();
     70      regData.Name = Name;
     71      regData.Description = Description;
     72      regData.TargetVariable = ProblemData.TargetVariable;
     73      regData.InputVariables = ProblemData.InputVariables.Select(x => x.Value);
     74      regData.AllowedInputVariables = ProblemData.AllowedInputVariables;
     75      regData.TrainingPartitionStart = ProblemData.TrainingPartition.Start;
     76      regData.TrainingPartitionEnd = ProblemData.TrainingPartition.End;
     77      regData.TestPartitionStart = ProblemData.TestPartition.Start;
     78      regData.TestPartitionEnd = ProblemData.TestPartition.End;
     79
     80      List<List<double>> data = new List<List<double>>();
     81      foreach (var variable in ProblemData.Dataset.DoubleVariables) {
     82        data.Add(ProblemData.Dataset.GetDoubleValues(variable).ToList());
     83      }
     84      regData.Values = Transformation(data);
     85
     86      return regData;
     87    }
     88
     89    public static double[,] Transformation(List<List<double>> data) {
     90      if (!data.All(x => x.Count.Equals(data.First().Count)))
     91        throw new ArgumentException("Can't create jagged array.");
     92      double[,] values = new double[data.First().Count, data.Count];
     93      for (int i = 0; i < values.GetLength(0); i++) {
     94        for (int j = 0; j < values.GetLength(1); j++) {
     95          values[i, j] = data[j][i];
     96        }
     97      }
     98      return values;
     99    }
    61100  }
    62101}
Note: See TracChangeset for help on using the changeset viewer.