- Timestamp:
- 04/24/12 16:37:40 (13 years ago)
- Location:
- branches/ProblemInstancesRegressionAndClassification
- Files:
-
- 3 deleted
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification-3.4.csproj
r7758 r7759 196 196 <Project>{3D28463F-EC96-4D82-AFEE-38BE91A0CA00}</Project> 197 197 <Name>HeuristicLab.Problems.DataAnalysis.Symbolic-3.4</Name> 198 <Private>False</Private> 198 199 </ProjectReference> 199 200 <ProjectReference Include="..\..\HeuristicLab.Problems.DataAnalysis\3.4\HeuristicLab.Problems.DataAnalysis-3.4.csproj"> -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveProblem.cs
r7758 r7759 19 19 */ 20 20 #endregion 21 using System;22 using System.Collections.Generic;23 21 using System.Linq; 24 22 using HeuristicLab.Common; … … 33 31 [Creatable("Problems")] 34 32 public class SymbolicClassificationSingleObjectiveProblem : SymbolicDataAnalysisSingleObjectiveProblem<IClassificationProblemData, ISymbolicClassificationSingleObjectiveEvaluator, ISymbolicDataAnalysisSolutionCreator>, IClassificationProblem, 35 IProblemInstanceConsumer<Classification Data>, IProblemInstanceExporter<ClassificationData> {33 IProblemInstanceConsumer<ClassificationProblemData>, IProblemInstanceExporter<ClassificationProblemData> { 36 34 private const double PunishmentFactor = 10; 37 35 private const int InitialMaximumTreeDepth = 8; … … 113 111 } 114 112 115 public void Load(Classification Data data) {113 public void Load(ClassificationProblemData data) { 116 114 Name = data.Name; 117 115 Description = data.Description; 118 Dataset dataset = new Dataset(data.InputVariables, data.Values); 119 ProblemData = new ClassificationProblemData(dataset, data.AllowedInputVariables, data.TargetVariable); 120 ProblemData.TrainingPartition.Start = data.TrainingPartitionStart; 121 ProblemData.TrainingPartition.End = data.TrainingPartitionEnd; 122 ProblemData.TestPartition.Start = data.TestPartitionStart; 123 ProblemData.TestPartition.End = data.TestPartitionEnd; 116 ProblemData = new ClassificationProblemData(data.Dataset, data.AllowedInputVariables, data.TargetVariable); 117 ProblemData.TrainingPartition.Start = data.TrainingPartition.Start; 118 ProblemData.TrainingPartition.End = data.TrainingPartition.End; 119 ProblemData.TestPartition.Start = data.TestPartition.Start; 120 ProblemData.TestPartition.End = data.TestPartition.End; 124 121 OnReset(); 125 122 } 126 123 127 public ClassificationData Export() { 128 if (!ProblemData.InputVariables.Count.Equals(ProblemData.Dataset.DoubleVariables.Count())) 129 throw new ArgumentException("Not all input variables are double variables! (Export only works with double variables)"); 130 131 ClassificationData claData = new ClassificationData(); 124 public ClassificationProblemData Export() { 125 ClassificationProblemData claData = new ClassificationProblemData(ProblemData.Dataset, ProblemData.AllowedInputVariables, ProblemData.TargetVariable); 132 126 claData.Name = Name; 133 127 claData.Description = Description; 134 claData.TargetVariable = ProblemData.TargetVariable; 135 claData.InputVariables = ProblemData.InputVariables.Select(x => x.Value).ToArray(); 136 claData.AllowedInputVariables = ProblemData.AllowedInputVariables.ToArray(); 137 claData.TrainingPartitionStart = ProblemData.TrainingPartition.Start; 138 claData.TrainingPartitionEnd = ProblemData.TrainingPartition.End; 139 claData.TestPartitionStart = ProblemData.TestPartition.Start; 140 claData.TestPartitionEnd = ProblemData.TestPartition.End; 141 142 List<List<double>> data = new List<List<double>>(); 143 foreach (var variable in ProblemData.Dataset.DoubleVariables) { 144 data.Add(ProblemData.Dataset.GetDoubleValues(variable).ToList()); 145 } 146 claData.Values = Transformer.Transformation(data); 147 128 claData.TrainingPartition.Start = ProblemData.TrainingPartition.Start; 129 claData.TrainingPartition.End = ProblemData.TrainingPartition.End; 130 claData.TestPartition.Start = ProblemData.TestPartition.Start; 131 claData.TestPartition.End = ProblemData.TestPartition.End; 148 132 return claData; 149 133 } -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4.csproj
r7758 r7759 191 191 <Project>{3D28463F-EC96-4D82-AFEE-38BE91A0CA00}</Project> 192 192 <Name>HeuristicLab.Problems.DataAnalysis.Symbolic-3.4</Name> 193 <Private>False</Private> 193 194 </ProjectReference> 194 195 <ProjectReference Include="..\..\HeuristicLab.Problems.DataAnalysis\3.4\HeuristicLab.Problems.DataAnalysis-3.4.csproj"> -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveProblem.cs
r7758 r7759 20 20 #endregion 21 21 22 using System;23 using System.Collections.Generic;24 22 using System.Linq; 25 23 using HeuristicLab.Common; … … 34 32 [Creatable("Problems")] 35 33 public class SymbolicRegressionSingleObjectiveProblem : SymbolicDataAnalysisSingleObjectiveProblem<IRegressionProblemData, ISymbolicRegressionSingleObjectiveEvaluator, ISymbolicDataAnalysisSolutionCreator>, IRegressionProblem, 36 IProblemInstanceConsumer<Regression Data>, IProblemInstanceExporter<RegressionData> {34 IProblemInstanceConsumer<RegressionProblemData>, IProblemInstanceExporter<RegressionProblemData> { 37 35 private const double PunishmentFactor = 10; 38 36 private const int InitialMaximumTreeDepth = 8; … … 116 114 } 117 115 118 public void Load(Regression Data data) {116 public void Load(RegressionProblemData data) { 119 117 Name = data.Name; 120 118 Description = data.Description; 121 Dataset dataset = new Dataset(data.InputVariables, data.Values); 122 ProblemData = new RegressionProblemData(dataset, data.AllowedInputVariables, data.TargetVariable); 123 ProblemData.TrainingPartition.Start = data.TrainingPartitionStart; 124 ProblemData.TrainingPartition.End = data.TrainingPartitionEnd; 125 ProblemData.TestPartition.Start = data.TestPartitionStart; 126 ProblemData.TestPartition.End = data.TestPartitionEnd; 119 ProblemData = new RegressionProblemData(data.Dataset, data.AllowedInputVariables, data.TargetVariable); 120 ProblemData.TrainingPartition.Start = data.TrainingPartition.Start; 121 ProblemData.TrainingPartition.End = data.TrainingPartition.End; 122 ProblemData.TestPartition.Start = data.TestPartition.Start; 123 ProblemData.TestPartition.End = data.TestPartition.End; 127 124 OnReset(); 128 125 } 129 126 130 public RegressionData Export() { 131 if (!ProblemData.InputVariables.Count.Equals(ProblemData.Dataset.DoubleVariables.Count())) 132 throw new ArgumentException("Not all input variables are double variables! (Export only works with double variables)"); 133 134 RegressionData regData = new RegressionData(); 127 public RegressionProblemData Export() { 128 RegressionProblemData regData = new RegressionProblemData(ProblemData.Dataset, ProblemData.AllowedInputVariables, ProblemData.TargetVariable); 135 129 regData.Name = Name; 136 130 regData.Description = Description; 137 regData.TargetVariable = ProblemData.TargetVariable; 138 regData.InputVariables = ProblemData.InputVariables.Select(x => x.Value).ToArray(); 139 regData.AllowedInputVariables = ProblemData.AllowedInputVariables.ToArray(); 140 regData.TrainingPartitionStart = ProblemData.TrainingPartition.Start; 141 regData.TrainingPartitionEnd = ProblemData.TrainingPartition.End; 142 regData.TestPartitionStart = ProblemData.TestPartition.Start; 143 regData.TestPartitionEnd = ProblemData.TestPartition.End; 144 145 List<List<double>> data = new List<List<double>>(); 146 foreach (var variable in ProblemData.Dataset.DoubleVariables) { 147 data.Add(ProblemData.Dataset.GetDoubleValues(variable).ToList()); 148 } 149 regData.Values = Transformer.Transformation(data); 150 131 regData.TrainingPartition.Start = ProblemData.TrainingPartition.Start; 132 regData.TrainingPartition.End = ProblemData.TrainingPartition.End; 133 regData.TestPartition.Start = ProblemData.TestPartition.Start; 134 regData.TestPartition.End = ProblemData.TestPartition.End; 151 135 return regData; 152 136 } -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationProblem.cs
r7758 r7759 20 20 #endregion 21 21 22 using System;23 using System.Collections.Generic;24 using System.Linq;25 22 using HeuristicLab.Common; 26 23 using HeuristicLab.Core; … … 33 30 [Creatable("Problems")] 34 31 public class ClassificationProblem : DataAnalysisProblem<IClassificationProblemData>, IClassificationProblem, IStorableContent, 35 IProblemInstanceConsumer<Classification Data>, IProblemInstanceExporter<ClassificationData> {32 IProblemInstanceConsumer<ClassificationProblemData>, IProblemInstanceExporter<ClassificationProblemData> { 36 33 public string Filename { get; set; } 37 34 … … 46 43 } 47 44 48 public void Load(Classification Data data) {45 public void Load(ClassificationProblemData data) { 49 46 Name = data.Name; 50 47 Description = data.Description; 51 Dataset dataset = new Dataset(data.InputVariables, data.Values); 52 ProblemData = new ClassificationProblemData(dataset, data.AllowedInputVariables, data.TargetVariable); 53 ProblemData.TrainingPartition.Start = data.TrainingPartitionStart; 54 ProblemData.TrainingPartition.End = data.TrainingPartitionEnd; 55 ProblemData.TestPartition.Start = data.TestPartitionStart; 56 ProblemData.TestPartition.End = data.TestPartitionEnd; 48 ProblemData = new ClassificationProblemData(data.Dataset, data.AllowedInputVariables, data.TargetVariable); 49 ProblemData.TrainingPartition.Start = data.TrainingPartition.Start; 50 ProblemData.TrainingPartition.End = data.TrainingPartition.End; 51 ProblemData.TestPartition.Start = data.TestPartition.Start; 52 ProblemData.TestPartition.End = data.TestPartition.End; 57 53 OnReset(); 58 54 } 59 55 60 public ClassificationData Export() { 61 if (!ProblemData.InputVariables.Count.Equals(ProblemData.Dataset.DoubleVariables.Count())) 62 throw new ArgumentException("Not all input variables are double variables! (Export only works with double variables)"); 63 64 ClassificationData claData = new ClassificationData(); 56 public ClassificationProblemData Export() { 57 ClassificationProblemData claData = new ClassificationProblemData(ProblemData.Dataset, ProblemData.AllowedInputVariables, ProblemData.TargetVariable); 65 58 claData.Name = Name; 66 59 claData.Description = Description; 67 claData.TargetVariable = ProblemData.TargetVariable; 68 claData.InputVariables = ProblemData.InputVariables.Select(x => x.Value).ToArray(); 69 claData.AllowedInputVariables = ProblemData.AllowedInputVariables.ToArray(); 70 claData.TrainingPartitionStart = ProblemData.TrainingPartition.Start; 71 claData.TrainingPartitionEnd = ProblemData.TrainingPartition.End; 72 claData.TestPartitionStart = ProblemData.TestPartition.Start; 73 claData.TestPartitionEnd = ProblemData.TestPartition.End; 74 75 List<List<double>> data = new List<List<double>>(); 76 foreach (var variable in ProblemData.Dataset.DoubleVariables) { 77 data.Add(ProblemData.Dataset.GetDoubleValues(variable).ToList()); 78 } 79 claData.Values = Transformer.Transformation(data); 80 60 claData.TrainingPartition.Start = ProblemData.TrainingPartition.Start; 61 claData.TrainingPartition.End = ProblemData.TrainingPartition.End; 62 claData.TestPartition.Start = ProblemData.TestPartition.Start; 63 claData.TestPartition.End = ProblemData.TestPartition.End; 81 64 return claData; 82 65 } -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblem.cs
r7758 r7759 20 20 #endregion 21 21 22 using System;23 using System.Collections.Generic;24 using System.Linq;25 22 using HeuristicLab.Common; 26 23 using HeuristicLab.Core; … … 33 30 [Creatable("Problems")] 34 31 public class RegressionProblem : DataAnalysisProblem<IRegressionProblemData>, IRegressionProblem, IStorableContent, 35 IProblemInstanceConsumer<Regression Data>, IProblemInstanceExporter<RegressionData> {32 IProblemInstanceConsumer<RegressionProblemData>, IProblemInstanceExporter<RegressionProblemData> { 36 33 public string Filename { get; set; } 37 34 … … 46 43 } 47 44 48 public void Load(Regression Data data) {45 public void Load(RegressionProblemData data) { 49 46 Name = data.Name; 50 47 Description = data.Description; 51 Dataset dataset = new Dataset(data.InputVariables, data.Values); 52 ProblemData = new RegressionProblemData(dataset, data.AllowedInputVariables, data.TargetVariable); 53 ProblemData.TrainingPartition.Start = data.TrainingPartitionStart; 54 ProblemData.TrainingPartition.End = data.TrainingPartitionEnd; 55 ProblemData.TestPartition.Start = data.TestPartitionStart; 56 ProblemData.TestPartition.End = data.TestPartitionEnd; 48 ProblemData = new RegressionProblemData(data.Dataset, data.AllowedInputVariables, data.TargetVariable); 49 ProblemData.TrainingPartition.Start = data.TrainingPartition.Start; 50 ProblemData.TrainingPartition.End = data.TrainingPartition.End; 51 ProblemData.TestPartition.Start = data.TestPartition.Start; 52 ProblemData.TestPartition.End = data.TestPartition.End; 57 53 OnReset(); 58 54 } 59 55 60 public RegressionData Export() { 61 if (!ProblemData.InputVariables.Count.Equals(ProblemData.Dataset.DoubleVariables.Count())) 62 throw new ArgumentException("Not all input variables are double variables! (Export only works with double variables)"); 63 64 RegressionData regData = new RegressionData(); 56 public RegressionProblemData Export() { 57 RegressionProblemData regData = new RegressionProblemData(ProblemData.Dataset, ProblemData.AllowedInputVariables, ProblemData.TargetVariable); 65 58 regData.Name = Name; 66 59 regData.Description = Description; 67 regData.TargetVariable = ProblemData.TargetVariable; 68 regData.InputVariables = ProblemData.InputVariables.Select(x => x.Value).ToArray(); 69 regData.AllowedInputVariables = ProblemData.AllowedInputVariables.ToArray(); 70 regData.TrainingPartitionStart = ProblemData.TrainingPartition.Start; 71 regData.TrainingPartitionEnd = ProblemData.TrainingPartition.End; 72 regData.TestPartitionStart = ProblemData.TestPartition.Start; 73 regData.TestPartitionEnd = ProblemData.TestPartition.End; 74 75 List<List<double>> data = new List<List<double>>(); 76 foreach (var variable in ProblemData.Dataset.DoubleVariables) { 77 data.Add(ProblemData.Dataset.GetDoubleValues(variable).ToList()); 78 } 79 regData.Values = Transformer.Transformation(data); 80 60 regData.TrainingPartition.Start = ProblemData.TrainingPartition.Start; 61 regData.TrainingPartition.End = ProblemData.TrainingPartition.End; 62 regData.TestPartition.Start = ProblemData.TestPartition.Start; 63 regData.TestPartition.End = ProblemData.TestPartition.End; 81 64 return regData; 82 65 } -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Classification/3.4/ArtificialClassificationDataDescriptor.cs
r7685 r7759 20 20 #endregion 21 21 22 using System.Collections.Generic; 23 using HeuristicLab.Problems.DataAnalysis; 22 24 23 using System.Collections.Generic;24 25 namespace HeuristicLab.Problems.Instances.Classification { 25 26 public abstract class ArtificialClassificationDataDescriptor : IDataDescriptor { … … 35 36 protected abstract int TestPartitionEnd { get; } 36 37 37 public ClassificationData GenerateClassificationData() { 38 ClassificationData claData = new ClassificationData(); 38 public ClassificationProblemData GenerateClassificationData() { 39 Dataset dataset = new Dataset(InputVariables, this.GenerateValues()); 40 41 ClassificationProblemData claData = new ClassificationProblemData(dataset, AllowedInputVariables, TargetVariable); 39 42 claData.Name = this.Name; 40 43 claData.Description = this.Description; 41 claData.InputVariables = this.InputVariables; 42 claData.AllowedInputVariables = this.AllowedInputVariables; 43 claData.TargetVariable = this.TargetVariable; 44 claData.Values = Transformer.Transformation(this.GenerateValues()); 45 claData.TrainingPartitionStart = this.TrainingPartitionStart; 46 claData.TrainingPartitionEnd = this.TrainingPartitionEnd; 47 claData.TestPartitionStart = this.TestPartitionStart; 48 claData.TestPartitionEnd = this.TestPartitionEnd; 44 claData.TrainingPartition.Start = this.TrainingPartitionStart; 45 claData.TrainingPartition.End = this.TrainingPartitionEnd; 46 claData.TestPartition.Start = this.TestPartitionStart; 47 claData.TestPartition.End = this.TestPartitionEnd; 49 48 return claData; 50 49 } -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Classification/3.4/ArtificialClassificationInstanceProvider.cs
r7685 r7759 20 20 #endregion 21 21 22 using HeuristicLab.Problems.DataAnalysis; 22 23 23 24 namespace HeuristicLab.Problems.Instances.Classification { 24 25 public abstract class ArtificialClassificationInstanceProvider : ClassificationInstanceProvider { 25 public override Classification Data LoadData(IDataDescriptor descriptor) {26 public override ClassificationProblemData LoadData(IDataDescriptor descriptor) { 26 27 return ((ArtificialClassificationDataDescriptor)descriptor).GenerateClassificationData(); 27 28 } -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Classification/3.4/ClassificationInstanceProvider.cs
r7685 r7759 26 26 using System.Linq; 27 27 using System.Text; 28 using HeuristicLab.Problems.DataAnalysis; 28 29 29 30 namespace HeuristicLab.Problems.Instances.Classification { 30 public abstract class ClassificationInstanceProvider : IProblemInstanceProvider<Classification Data> {31 public Classification Data LoadData(string path) {31 public abstract class ClassificationInstanceProvider : IProblemInstanceProvider<ClassificationProblemData> { 32 public ClassificationProblemData LoadData(string path) { 32 33 TableFileParser csvFileParser = new TableFileParser(); 33 34 csvFileParser.Parse(path); 34 35 35 ClassificationData claData = new ClassificationData(); 36 Dataset dataset = new Dataset(csvFileParser.VariableNames, csvFileParser.Values); 37 string targetVar = csvFileParser.VariableNames.Last(); 38 IEnumerable<string> allowedInputVars = csvFileParser.VariableNames.Where(x => !x.Equals(targetVar)); 39 40 ClassificationProblemData claData = new ClassificationProblemData(dataset, allowedInputVars, targetVar); 36 41 int pos = path.LastIndexOf('\\'); 37 42 if (pos < 0) … … 41 46 claData.Name = path.Substring(pos, path.Length - pos); 42 47 } 43 claData.InputVariables = new List<string>(csvFileParser.VariableNames).ToArray();44 claData.TargetVariable = csvFileParser.VariableNames.Last();45 claData.AllowedInputVariables = claData.InputVariables.Where(x => !x.Equals(claData.TargetVariable)).ToArray();46 //convert to multidimensional array47 List<IList> values = csvFileParser.Values;48 claData.Values = new double[values.First().Count, values.Count];49 for (int i = 0; i < values.Count; i++) {50 for (int j = 0; j < values.First().Count; j++) {51 claData.Values[j, i] = (double)values[i][j];52 }53 }54 48 55 49 int trainingPartEnd = csvFileParser.Rows * 2 / 3; 56 claData.TrainingPartition Start = 0;57 claData.TrainingPartition End = trainingPartEnd;58 claData.TestPartition Start = trainingPartEnd;59 claData.TestPartition End = csvFileParser.Rows;50 claData.TrainingPartition.Start = 0; 51 claData.TrainingPartition.End = trainingPartEnd; 52 claData.TestPartition.Start = trainingPartEnd; 53 claData.TestPartition.End = csvFileParser.Rows; 60 54 return claData; 61 55 } 62 56 63 public void SaveData(Classification Data instance, string path) {57 public void SaveData(ClassificationProblemData instance, string path) { 64 58 StringBuilder strBuilder = new StringBuilder(); 65 59 … … 70 64 strBuilder.AppendLine(); 71 65 72 double[,] values = instance.Values;66 Dataset dataset = instance.Dataset; 73 67 74 for (int i = 0; i < values.GetLength(0); i++) {75 for (int j = 0; j < values.GetLength(1); j++) {76 strBuilder.Append( values[i, j]+ ";");68 for (int i = 0; i < dataset.Rows; i++) { 69 for (int j = 0; j < dataset.Columns; j++) { 70 strBuilder.Append(dataset.GetValue(i, j) + ";"); 77 71 } 78 72 strBuilder.Remove(strBuilder.Length - 1, 1); … … 86 80 87 81 public abstract IEnumerable<IDataDescriptor> GetDataDescriptors(); 88 public abstract Classification Data LoadData(IDataDescriptor descriptor);82 public abstract ClassificationProblemData LoadData(IDataDescriptor descriptor); 89 83 90 84 public abstract string Name { get; } … … 92 86 public abstract Uri WebLink { get; } 93 87 public abstract string ReferencePublication { get; } 94 95 public IProblemInstanceConsumer<ClassificationData> Consumer { get; set; }96 88 } 97 89 } -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Classification/3.4/HeuristicLab.Problems.Instances.Classification-3.4.csproj
r7687 r7759 38 38 </PropertyGroup> 39 39 <ItemGroup> 40 <Reference Include="HeuristicLab.Collections-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 41 <Private>False</Private> 42 </Reference> 40 43 <Reference Include="HeuristicLab.Common-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 41 44 <Private>False</Private> 42 45 </Reference> 43 46 <Reference Include="HeuristicLab.Core-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 47 <Private>False</Private> 48 </Reference> 49 <Reference Include="HeuristicLab.Data-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 44 50 <Private>False</Private> 45 51 </Reference> -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Classification/3.4/ResourceClassificationInstanceProvider.cs
r7758 r7759 26 26 using System.Reflection; 27 27 using System.Text.RegularExpressions; 28 using HeuristicLab.Problems.DataAnalysis; 28 29 using ICSharpCode.SharpZipLib.Zip; 29 30 … … 43 44 } 44 45 45 public override Classification Data LoadData(IDataDescriptor id) {46 public override ClassificationProblemData LoadData(IDataDescriptor id) { 46 47 var descriptor = (ResourceClassificationDataDescriptor)id; 47 48 48 Classification Data claData = LoadData(GetTempFileForResource(descriptor.ResourceName));49 ClassificationProblemData claData = LoadData(GetTempFileForResource(descriptor.ResourceName)); 49 50 claData.Name = descriptor.Name; 50 51 claData.Description = descriptor.Description; -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Regression/3.4/ArtificialRegressionDataDescriptor.cs
r7682 r7759 21 21 22 22 using System.Collections.Generic; 23 using HeuristicLab.Problems.DataAnalysis; 24 23 25 namespace HeuristicLab.Problems.Instances.Regression { 24 26 public abstract class ArtificialRegressionDataDescriptor : IDataDescriptor { … … 34 36 protected abstract int TestPartitionEnd { get; } 35 37 36 public RegressionData GenerateRegressionData() { 37 RegressionData regData = new RegressionData(); 38 public RegressionProblemData GenerateRegressionData() { 39 Dataset dataset = new Dataset(InputVariables, this.GenerateValues()); 40 41 RegressionProblemData regData = new RegressionProblemData(dataset, AllowedInputVariables, TargetVariable); 38 42 regData.Name = this.Name; 39 43 regData.Description = this.Description; 40 regData.InputVariables = this.InputVariables; 41 regData.AllowedInputVariables = this.AllowedInputVariables; 42 regData.TargetVariable = this.TargetVariable; 43 regData.Values = Transformer.Transformation(this.GenerateValues()); 44 regData.TrainingPartitionStart = this.TrainingPartitionStart; 45 regData.TrainingPartitionEnd = this.TrainingPartitionEnd; 46 regData.TestPartitionStart = this.TestPartitionStart; 47 regData.TestPartitionEnd = this.TestPartitionEnd; 44 regData.TrainingPartition.Start = this.TrainingPartitionStart; 45 regData.TrainingPartition.End = this.TrainingPartitionEnd; 46 regData.TestPartition.Start = this.TestPartitionStart; 47 regData.TestPartition.End = this.TestPartitionEnd; 48 48 return regData; 49 49 } -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Regression/3.4/ArtificialRegressionInstanceProvider.cs
r7664 r7759 20 20 #endregion 21 21 22 using HeuristicLab.Problems.DataAnalysis; 22 23 23 24 namespace HeuristicLab.Problems.Instances.Regression { 24 25 public abstract class ArtificialRegressionInstanceProvider : RegressionInstanceProvider { 25 public override Regression Data LoadData(IDataDescriptor descriptor) {26 public override RegressionProblemData LoadData(IDataDescriptor descriptor) { 26 27 return ((ArtificialRegressionDataDescriptor)descriptor).GenerateRegressionData(); 27 28 } -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Regression/3.4/HeuristicLab.Problems.Instances.Regression-3.4.csproj
r7687 r7759 38 38 </PropertyGroup> 39 39 <ItemGroup> 40 <Reference Include="HeuristicLab.Collections-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 41 <Private>False</Private> 42 </Reference> 40 43 <Reference Include="HeuristicLab.Common-3.3"> 41 44 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Common-3.3.dll</HintPath> … … 44 47 <Reference Include="HeuristicLab.Core-3.3"> 45 48 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Core-3.3.dll</HintPath> 49 <Private>False</Private> 50 </Reference> 51 <Reference Include="HeuristicLab.Data-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 46 52 <Private>False</Private> 47 53 </Reference> -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Regression/3.4/RealWorld/RealWorldInstanceProvider.cs
r7758 r7759 39 39 } 40 40 41 protected override string File Name{ get { return "RealWorld"; } }41 protected override string FileExtension { get { return "RealWorld"; } } 42 42 } 43 43 } -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Regression/3.4/RegressionInstanceProvider.cs
r7682 r7759 26 26 using System.Linq; 27 27 using System.Text; 28 using HeuristicLab.Problems.DataAnalysis; 28 29 29 30 namespace HeuristicLab.Problems.Instances.Regression { 30 public abstract class RegressionInstanceProvider : IProblemInstanceProvider<Regression Data> {31 public Regression Data LoadData(string path) {31 public abstract class RegressionInstanceProvider : IProblemInstanceProvider<RegressionProblemData> { 32 public RegressionProblemData LoadData(string path) { 32 33 TableFileParser csvFileParser = new TableFileParser(); 33 34 csvFileParser.Parse(path); 34 35 35 RegressionData regData = new RegressionData(); 36 Dataset dataset = new Dataset(csvFileParser.VariableNames, csvFileParser.Values); 37 string targetVar = csvFileParser.VariableNames.Last(); 38 IEnumerable<string> allowedInputVars = csvFileParser.VariableNames.Where(x => !x.Equals(targetVar)); 39 40 RegressionProblemData regData = new RegressionProblemData(dataset, allowedInputVars, targetVar); 36 41 int pos = path.LastIndexOf('\\'); 37 42 if (pos < 0) … … 41 46 regData.Name = path.Substring(pos, path.Length - pos); 42 47 } 43 regData.InputVariables = new List<string>(csvFileParser.VariableNames).ToArray();44 regData.TargetVariable = csvFileParser.VariableNames.Last();45 regData.AllowedInputVariables = regData.InputVariables.Where(x => !x.Equals(regData.TargetVariable)).ToArray();46 //convert to multidimensional array47 List<IList> values = csvFileParser.Values;48 regData.Values = new double[values.First().Count, values.Count];49 for (int i = 0; i < values.Count; i++) {50 for (int j = 0; j < values.First().Count; j++) {51 regData.Values[j, i] = (double)values[i][j];52 }53 }54 48 55 49 int trainingPartEnd = csvFileParser.Rows * 2 / 3; 56 regData.TrainingPartition Start = 0;57 regData.TrainingPartition End = trainingPartEnd;58 regData.TestPartition Start = trainingPartEnd;59 regData.TestPartition End = csvFileParser.Rows;50 regData.TrainingPartition.Start = 0; 51 regData.TrainingPartition.End = trainingPartEnd; 52 regData.TestPartition.Start = trainingPartEnd; 53 regData.TestPartition.End = csvFileParser.Rows; 60 54 return regData; 61 55 } 62 56 63 public void SaveData(Regression Data instance, string path) {57 public void SaveData(RegressionProblemData instance, string path) { 64 58 StringBuilder strBuilder = new StringBuilder(); 65 59 … … 70 64 strBuilder.AppendLine(); 71 65 72 double[,] values = instance.Values;66 Dataset dataset = instance.Dataset; 73 67 74 for (int i = 0; i < values.GetLength(0); i++) {75 for (int j = 0; j < values.GetLength(1); j++) {76 strBuilder.Append( values[i, j]+ ";");68 for (int i = 0; i < dataset.Rows; i++) { 69 for (int j = 0; j < dataset.Columns; j++) { 70 strBuilder.Append(dataset.GetValue(i, j) + ";"); 77 71 } 78 72 strBuilder.Remove(strBuilder.Length - 1, 1); … … 86 80 87 81 public abstract IEnumerable<IDataDescriptor> GetDataDescriptors(); 88 public abstract Regression Data LoadData(IDataDescriptor descriptor);82 public abstract RegressionProblemData LoadData(IDataDescriptor descriptor); 89 83 90 84 public abstract string Name { get; } … … 92 86 public abstract Uri WebLink { get; } 93 87 public abstract string ReferencePublication { get; } 94 95 public IProblemInstanceConsumer<RegressionData> Consumer { get; set; }96 88 } 97 89 } -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Regression/3.4/ResourceRegressionInstanceProvider.cs
r7758 r7759 26 26 using System.Reflection; 27 27 using System.Text.RegularExpressions; 28 using HeuristicLab.Problems.DataAnalysis; 28 29 using ICSharpCode.SharpZipLib.Zip; 29 30 … … 31 32 public abstract class ResourceRegressionInstanceProvider : RegressionInstanceProvider { 32 33 33 protected abstract string File Name{ get; }34 protected abstract string FileExtension { get; } 34 35 35 36 public override IEnumerable<IDataDescriptor> GetDataDescriptors() { 36 var solutionsArchiveName = GetResourceName(File Name+ @"\.zip");37 var solutionsArchiveName = GetResourceName(FileExtension + @"\.zip"); 37 38 if (!String.IsNullOrEmpty(solutionsArchiveName)) { 38 39 using (var solutionsZipFile = new ZipInputStream(GetType().Assembly.GetManifestResourceStream(solutionsArchiveName))) { … … 43 44 } 44 45 45 public override Regression Data LoadData(IDataDescriptor id) {46 public override RegressionProblemData LoadData(IDataDescriptor id) { 46 47 var descriptor = (ResourceRegressionDataDescriptor)id; 47 48 48 Regression Data regData = LoadData(GetTempFileForResource(descriptor.ResourceName));49 RegressionProblemData regData = LoadData(GetTempFileForResource(descriptor.ResourceName)); 49 50 regData.Name = descriptor.Name; 50 51 regData.Description = descriptor.Description; … … 66 67 67 68 private string GetTempFileForResource(string resourceName) { 68 var instanceArchiveName = GetResourceName(File Name+ @"\.zip");69 var instanceArchiveName = GetResourceName(FileExtension + @"\.zip"); 69 70 using (var instancesZipFile = new ZipFile(GetType().Assembly.GetManifestResourceStream(instanceArchiveName))) { 70 71 var entry = instancesZipFile.GetEntry(resourceName); -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Regression/3.4/TrentMcConaghy/TrentMcConaghyInstanceProvider.cs
r7758 r7759 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using System.Linq; 25 using HeuristicLab.Problems.DataAnalysis; 24 26 25 27 namespace HeuristicLab.Problems.Instances.Regression { … … 43 45 } 44 46 45 protected override string File Name{ get { return "TrentMcConaghy"; } }47 protected override string FileExtension { get { return "TrentMcConaghy"; } } 46 48 47 public override Regression Data LoadData(IDataDescriptor id) {48 Regression Data regData = base.LoadData(id);49 50 regData.TargetVariable = regData.InputVariables.First();51 regData.AllowedInputVariables = regData.InputVariables.Where(x => !x.Equals(regData.TargetVariable)).ToArray();49 public override RegressionProblemData LoadData(IDataDescriptor id) { 50 RegressionProblemData regData = base.LoadData(id); 51 string targetVar = regData.InputVariables.First().Value; 52 IEnumerable<string> allowedInputVars = regData.InputVariables.Where(x => !x.Equals(regData.TargetVariable)).Select(x => x.Value); 53 RegressionProblemData newRegData = new RegressionProblemData(regData.Dataset, allowedInputVars, targetVar); 52 54 53 55 return regData; -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Regression/3.4/ValueGenerator.cs
r7698 r7759 26 26 using HeuristicLab.Random; 27 27 namespace HeuristicLab.Problems.Instances.Regression { 28 public class ValueGenerator {29 pr otectedstatic FastRandom rand = new FastRandom();28 public static class ValueGenerator { 29 private static FastRandom rand = new FastRandom(); 30 30 31 31 public static IEnumerable<double> GenerateSteps(double start, double end, double stepWidth) { 32 return Enumerable.Range(0, (int)Math.Round(((end - start) / stepWidth) + 1)) 33 .Select(i => (start + i * stepWidth)); 32 int steps = (int)Math.Round(((end - start) / stepWidth) + 1); 33 for (int i = 0; i < steps; i++) 34 yield return start + i * stepWidth; 34 35 } 35 36 36 37 public static IEnumerable<double> GenerateUniformDistributedValues(int amount, double start, double end) { 37 List<double> values = new List<double>(); 38 for (int i = 0; i < amount; i++) { 39 values.Add(rand.NextDouble() * (end - start) + start); 40 } 41 return values; 38 for (int i = 0; i < amount; i++) 39 yield return rand.NextDouble() * (end - start) + start; 42 40 } 43 41 44 42 public static IEnumerable<double> GenerateNormalDistributedValues(int amount, double mu, double sigma) { 45 List<double> values = new List<double>(); 46 for (int i = 0; i < amount; i++) { 47 values.Add(NormalDistributedRandom.NextDouble(rand, mu, sigma)); 48 } 49 return values; 43 for (int i = 0; i < amount; i++) 44 yield return NormalDistributedRandom.NextDouble(rand, mu, sigma); 50 45 } 51 46 -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances/3.3/HeuristicLab.Problems.Instances-3.3.csproj
r7754 r7759 119 119 <Compile Include="IProblemInstanceExporter.cs" /> 120 120 <Compile Include="TableFileParser.cs" /> 121 <Compile Include="Transformer.cs" />122 121 <Compile Include="Types\ATSPData.cs" /> 123 <Compile Include="Types\ClassificationData.cs" />124 <Compile Include="Types\RegressionData.cs" />125 122 <Compile Include="Types\CTAPData.cs" /> 126 123 <Compile Include="IDataDescriptor.cs" />
Note: See TracChangeset
for help on using the changeset viewer.