Changeset 7682 for branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis
- Timestamp:
- 04/02/12 10:55:26 (13 years ago)
- 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 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; 24 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 using HeuristicLab.Problems.Instances; 25 29 26 30 namespace HeuristicLab.Problems.DataAnalysis { … … 28 32 [Item("Classification Problem", "A general classification problem.")] 29 33 [Creatable("Problems")] 30 public class ClassificationProblem : DataAnalysisProblem<IClassificationProblemData>, IClassificationProblem, IStorableContent { 34 public class ClassificationProblem : DataAnalysisProblem<IClassificationProblemData>, IClassificationProblem, IStorableContent, 35 IProblemInstanceConsumer<ClassificationData>, IProblemInstanceExporter<ClassificationData>, IProblemInstanceConsumer { 31 36 public string Filename { get; set; } 32 37 … … 45 50 ProblemData = problemData; 46 51 } 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 } 47 88 } 48 89 } -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblem.cs
r7664 r7682 71 71 regData.Description = Description; 72 72 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(); 75 75 regData.TrainingPartitionStart = ProblemData.TrainingPartition.Start; 76 76 regData.TrainingPartitionEnd = ProblemData.TrainingPartition.End; … … 82 82 data.Add(ProblemData.Dataset.GetDoubleValues(variable).ToList()); 83 83 } 84 regData.Values = Transform ation(data);84 regData.Values = Transformer.Transformation(data); 85 85 86 86 return regData; 87 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 }100 88 } 101 89 }
Note: See TracChangeset
for help on using the changeset viewer.