Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/24/12 16:37:40 (13 years ago)
Author:
sforsten
Message:

#1784:

  • deleted ClassificationData and RegressionData. RegressionProblemData and ClassificationProblemData are used instead
  • deleted not needed Transformer
  • ValueGenerator is now a static class and yield return is used return IEnumerable
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Classification/3.4/ClassificationInstanceProvider.cs

    r7685 r7759  
    2626using System.Linq;
    2727using System.Text;
     28using HeuristicLab.Problems.DataAnalysis;
    2829
    2930namespace HeuristicLab.Problems.Instances.Classification {
    30   public abstract class ClassificationInstanceProvider : IProblemInstanceProvider<ClassificationData> {
    31     public ClassificationData LoadData(string path) {
     31  public abstract class ClassificationInstanceProvider : IProblemInstanceProvider<ClassificationProblemData> {
     32    public ClassificationProblemData LoadData(string path) {
    3233      TableFileParser csvFileParser = new TableFileParser();
    3334      csvFileParser.Parse(path);
    3435
    35       ClassificationData claData = new ClassificationData();
     36      Dataset dataset = new Dataset(csvFileParser.VariableNames, csvFileParser.Values);
     37      string targetVar = csvFileParser.VariableNames.Last();
     38      IEnumerable<string> allowedInputVars = csvFileParser.VariableNames.Where(x => !x.Equals(targetVar));
     39
     40      ClassificationProblemData claData = new ClassificationProblemData(dataset, allowedInputVars, targetVar);
    3641      int pos = path.LastIndexOf('\\');
    3742      if (pos < 0)
     
    4146        claData.Name = path.Substring(pos, path.Length - pos);
    4247      }
    43       claData.InputVariables = new List<string>(csvFileParser.VariableNames).ToArray();
    44       claData.TargetVariable = csvFileParser.VariableNames.Last();
    45       claData.AllowedInputVariables = claData.InputVariables.Where(x => !x.Equals(claData.TargetVariable)).ToArray();
    46       //convert to multidimensional array
    47       List<IList> values = csvFileParser.Values;
    48       claData.Values = new double[values.First().Count, values.Count];
    49       for (int i = 0; i < values.Count; i++) {
    50         for (int j = 0; j < values.First().Count; j++) {
    51           claData.Values[j, i] = (double)values[i][j];
    52         }
    53       }
    5448
    5549      int trainingPartEnd = csvFileParser.Rows * 2 / 3;
    56       claData.TrainingPartitionStart = 0;
    57       claData.TrainingPartitionEnd = trainingPartEnd;
    58       claData.TestPartitionStart = trainingPartEnd;
    59       claData.TestPartitionEnd = csvFileParser.Rows;
     50      claData.TrainingPartition.Start = 0;
     51      claData.TrainingPartition.End = trainingPartEnd;
     52      claData.TestPartition.Start = trainingPartEnd;
     53      claData.TestPartition.End = csvFileParser.Rows;
    6054      return claData;
    6155    }
    6256
    63     public void SaveData(ClassificationData instance, string path) {
     57    public void SaveData(ClassificationProblemData instance, string path) {
    6458      StringBuilder strBuilder = new StringBuilder();
    6559
     
    7064      strBuilder.AppendLine();
    7165
    72       double[,] values = instance.Values;
     66      Dataset dataset = instance.Dataset;
    7367
    74       for (int i = 0; i < values.GetLength(0); i++) {
    75         for (int j = 0; j < values.GetLength(1); j++) {
    76           strBuilder.Append(values[i, j] + ";");
     68      for (int i = 0; i < dataset.Rows; i++) {
     69        for (int j = 0; j < dataset.Columns; j++) {
     70          strBuilder.Append(dataset.GetValue(i, j) + ";");
    7771        }
    7872        strBuilder.Remove(strBuilder.Length - 1, 1);
     
    8680
    8781    public abstract IEnumerable<IDataDescriptor> GetDataDescriptors();
    88     public abstract ClassificationData LoadData(IDataDescriptor descriptor);
     82    public abstract ClassificationProblemData LoadData(IDataDescriptor descriptor);
    8983
    9084    public abstract string Name { get; }
     
    9286    public abstract Uri WebLink { get; }
    9387    public abstract string ReferencePublication { get; }
    94 
    95     public IProblemInstanceConsumer<ClassificationData> Consumer { get; set; }
    9688  }
    9789}
Note: See TracChangeset for help on using the changeset viewer.