Changeset 7664 for branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis
- Timestamp:
- 03/27/12 10:05:59 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblem.cs
r7610 r7664 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 24 using System.Linq; 22 25 using HeuristicLab.Common; 23 26 using HeuristicLab.Core; … … 30 33 [Creatable("Problems")] 31 34 public class RegressionProblem : DataAnalysisProblem<IRegressionProblemData>, IRegressionProblem, IStorableContent, 32 IProblemInstanceConsumer<RegressionData> {35 IProblemInstanceConsumer<RegressionData>, IProblemInstanceExporter<RegressionData>, IProblemInstanceConsumer { 33 36 public string Filename { get; set; } 34 37 … … 59 62 OnReset(); 60 63 } 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 } 61 100 } 62 101 }
Note: See TracChangeset
for help on using the changeset viewer.