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.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveProblem.cs

    r7734 r7750  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
    2224using System.Linq;
    2325using HeuristicLab.Common;
     
    2527using HeuristicLab.Parameters;
    2628using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     29using HeuristicLab.Problems.Instances;
    2730
    2831namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
     
    3033  [StorableClass]
    3134  [Creatable("Problems")]
    32   public class SymbolicRegressionSingleObjectiveProblem : SymbolicDataAnalysisSingleObjectiveProblem<IRegressionProblemData, ISymbolicRegressionSingleObjectiveEvaluator, ISymbolicDataAnalysisSolutionCreator>, IRegressionProblem {
     35  public class SymbolicRegressionSingleObjectiveProblem : SymbolicDataAnalysisSingleObjectiveProblem<IRegressionProblemData, ISymbolicRegressionSingleObjectiveEvaluator, ISymbolicDataAnalysisSolutionCreator>, IRegressionProblem,
     36    IProblemInstanceConsumer<RegressionData>, IProblemInstanceExporter<RegressionData> {
    3337    private const double PunishmentFactor = 10;
    3438    private const int InitialMaximumTreeDepth = 8;
     
    116120      ProblemData = problemData;
    117121    }
     122
     123    public void Load(RegressionData data) {
     124      Name = data.Name;
     125      Description = data.Description;
     126      Dataset dataset = new Dataset(data.InputVariables, data.Values);
     127      ProblemData = new RegressionProblemData(dataset, data.AllowedInputVariables, data.TargetVariable);
     128      ProblemData.TrainingPartition.Start = data.TrainingPartitionStart;
     129      ProblemData.TrainingPartition.End = data.TrainingPartitionEnd;
     130      ProblemData.TestPartition.Start = data.TestPartitionStart;
     131      ProblemData.TestPartition.End = data.TestPartitionEnd;
     132      OnReset();
     133    }
     134
     135    public RegressionData Export() {
     136      if (!ProblemData.InputVariables.Count.Equals(ProblemData.Dataset.DoubleVariables.Count()))
     137        throw new ArgumentException("Not all input variables are double variables! (Export only works with double variables)");
     138
     139      RegressionData regData = new RegressionData();
     140      regData.Name = Name;
     141      regData.Description = Description;
     142      regData.TargetVariable = ProblemData.TargetVariable;
     143      regData.InputVariables = ProblemData.InputVariables.Select(x => x.Value).ToArray();
     144      regData.AllowedInputVariables = ProblemData.AllowedInputVariables.ToArray();
     145      regData.TrainingPartitionStart = ProblemData.TrainingPartition.Start;
     146      regData.TrainingPartitionEnd = ProblemData.TrainingPartition.End;
     147      regData.TestPartitionStart = ProblemData.TestPartition.Start;
     148      regData.TestPartitionEnd = ProblemData.TestPartition.End;
     149
     150      List<List<double>> data = new List<List<double>>();
     151      foreach (var variable in ProblemData.Dataset.DoubleVariables) {
     152        data.Add(ProblemData.Dataset.GetDoubleValues(variable).ToList());
     153      }
     154      regData.Values = Transformer.Transformation(data);
     155
     156      return regData;
     157    }
    118158  }
    119159}
Note: See TracChangeset for help on using the changeset viewer.