Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/23/12 16:50:08 (13 years ago)
Author:
sforsten
Message:

#1784:

  • merged Problems.DataAnalysis r7273:7748 from trunk
  • prepared SymbolicClassificationSingleObjectiveProblem and SymbolicRegressionSingleObjectiveProblem to load and export problem instances
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveProblem.cs

    r7734 r7750  
    1919 */
    2020#endregion
     21using System;
     22using System.Collections.Generic;
    2123using System.Linq;
    2224using HeuristicLab.Common;
     
    2426using HeuristicLab.Parameters;
    2527using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     28using HeuristicLab.Problems.Instances;
    2629
    2730namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification {
     
    2932  [StorableClass]
    3033  [Creatable("Problems")]
    31   public class SymbolicClassificationSingleObjectiveProblem : SymbolicDataAnalysisSingleObjectiveProblem<IClassificationProblemData, ISymbolicClassificationSingleObjectiveEvaluator, ISymbolicDataAnalysisSolutionCreator>, IClassificationProblem {
     34  public class SymbolicClassificationSingleObjectiveProblem : SymbolicDataAnalysisSingleObjectiveProblem<IClassificationProblemData, ISymbolicClassificationSingleObjectiveEvaluator, ISymbolicDataAnalysisSolutionCreator>, IClassificationProblem,
     35    IProblemInstanceConsumer<ClassificationData>, IProblemInstanceExporter<ClassificationData> {
    3236    private const double PunishmentFactor = 10;
    3337    private const int InitialMaximumTreeDepth = 8;
     
    113117      ProblemData = problemData;
    114118    }
     119
     120    public void Load(ClassificationData data) {
     121      Name = data.Name;
     122      Description = data.Description;
     123      Dataset dataset = new Dataset(data.InputVariables, data.Values);
     124      ProblemData = new ClassificationProblemData(dataset, data.AllowedInputVariables, data.TargetVariable);
     125      ProblemData.TrainingPartition.Start = data.TrainingPartitionStart;
     126      ProblemData.TrainingPartition.End = data.TrainingPartitionEnd;
     127      ProblemData.TestPartition.Start = data.TestPartitionStart;
     128      ProblemData.TestPartition.End = data.TestPartitionEnd;
     129      OnReset();
     130    }
     131
     132    public ClassificationData Export() {
     133      if (!ProblemData.InputVariables.Count.Equals(ProblemData.Dataset.DoubleVariables.Count()))
     134        throw new ArgumentException("Not all input variables are double variables! (Export only works with double variables)");
     135
     136      ClassificationData claData = new ClassificationData();
     137      claData.Name = Name;
     138      claData.Description = Description;
     139      claData.TargetVariable = ProblemData.TargetVariable;
     140      claData.InputVariables = ProblemData.InputVariables.Select(x => x.Value).ToArray();
     141      claData.AllowedInputVariables = ProblemData.AllowedInputVariables.ToArray();
     142      claData.TrainingPartitionStart = ProblemData.TrainingPartition.Start;
     143      claData.TrainingPartitionEnd = ProblemData.TrainingPartition.End;
     144      claData.TestPartitionStart = ProblemData.TestPartition.Start;
     145      claData.TestPartitionEnd = ProblemData.TestPartition.End;
     146
     147      List<List<double>> data = new List<List<double>>();
     148      foreach (var variable in ProblemData.Dataset.DoubleVariables) {
     149        data.Add(ProblemData.Dataset.GetDoubleValues(variable).ToList());
     150      }
     151      claData.Values = Transformer.Transformation(data);
     152
     153      return claData;
     154    }
    115155  }
    116156}
Note: See TracChangeset for help on using the changeset viewer.