Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/02/12 10:55:26 (13 years ago)
Author:
sforsten
Message:

#1784:

  • added Problem.Instances.Classification project
  • added classification problem instances
  • added a class Transformer to Problem.Instances
Location:
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis/3.4/Implementation
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationProblem.cs

    r7259 r7682  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
     24using System.Linq;
    2225using HeuristicLab.Common;
    2326using HeuristicLab.Core;
    2427using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     28using HeuristicLab.Problems.Instances;
    2529
    2630namespace HeuristicLab.Problems.DataAnalysis {
     
    2832  [Item("Classification Problem", "A general classification problem.")]
    2933  [Creatable("Problems")]
    30   public class ClassificationProblem : DataAnalysisProblem<IClassificationProblemData>, IClassificationProblem, IStorableContent {
     34  public class ClassificationProblem : DataAnalysisProblem<IClassificationProblemData>, IClassificationProblem, IStorableContent,
     35    IProblemInstanceConsumer<ClassificationData>, IProblemInstanceExporter<ClassificationData>, IProblemInstanceConsumer {
    3136    public string Filename { get; set; }
    3237
     
    4550      ProblemData = problemData;
    4651    }
     52
     53    public void Load(ClassificationData data) {
     54      Name = data.Name;
     55      Description = data.Description;
     56      Dataset dataset = new Dataset(data.InputVariables, data.Values);
     57      ProblemData = new ClassificationProblemData(dataset, data.AllowedInputVariables, data.TargetVariable);
     58      ProblemData.TrainingPartition.Start = data.TrainingPartitionStart;
     59      ProblemData.TrainingPartition.End = data.TrainingPartitionEnd;
     60      ProblemData.TestPartition.Start = data.TestPartitionStart;
     61      ProblemData.TestPartition.End = data.TestPartitionEnd;
     62      OnReset();
     63    }
     64
     65    public ClassificationData 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      ClassificationData claData = new ClassificationData();
     70      claData.Name = Name;
     71      claData.Description = Description;
     72      claData.TargetVariable = ProblemData.TargetVariable;
     73      claData.InputVariables = ProblemData.InputVariables.Select(x => x.Value).ToArray();
     74      claData.AllowedInputVariables = ProblemData.AllowedInputVariables.ToArray();
     75      claData.TrainingPartitionStart = ProblemData.TrainingPartition.Start;
     76      claData.TrainingPartitionEnd = ProblemData.TrainingPartition.End;
     77      claData.TestPartitionStart = ProblemData.TestPartition.Start;
     78      claData.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      claData.Values = Transformer.Transformation(data);
     85
     86      return claData;
     87    }
    4788  }
    4889}
  • branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblem.cs

    r7664 r7682  
    7171      regData.Description = Description;
    7272      regData.TargetVariable = ProblemData.TargetVariable;
    73       regData.InputVariables = ProblemData.InputVariables.Select(x => x.Value);
    74       regData.AllowedInputVariables = ProblemData.AllowedInputVariables;
     73      regData.InputVariables = ProblemData.InputVariables.Select(x => x.Value).ToArray();
     74      regData.AllowedInputVariables = ProblemData.AllowedInputVariables.ToArray();
    7575      regData.TrainingPartitionStart = ProblemData.TrainingPartition.Start;
    7676      regData.TrainingPartitionEnd = ProblemData.TrainingPartition.End;
     
    8282        data.Add(ProblemData.Dataset.GetDoubleValues(variable).ToList());
    8383      }
    84       regData.Values = Transformation(data);
     84      regData.Values = Transformer.Transformation(data);
    8585
    8686      return regData;
    8787    }
    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     }
    10088  }
    10189}
Note: See TracChangeset for help on using the changeset viewer.