Changeset 9133
- Timestamp:
- 01/09/13 14:56:57 (12 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3
- Files:
-
- 3 added
- 2 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/HeuristicLab.Problems.Instances.DataAnalysis-3.3.csproj
r9131 r9133 185 185 <Compile Include="Regression\Nguyen\NguyenFunctionTwo.cs" /> 186 186 <Compile Include="Regression\Nguyen\NguyenInstanceProvider.cs" /> 187 <Compile Include="Regression\RealWorld\IRealWorldRegressionDataDescriptor.cs" /> 187 <Compile Include="Regression\RealWorld\ChemicalOne.cs" /> 188 <Compile Include="Regression\RealWorld\Housing.cs" /> 188 189 <Compile Include="Regression\RealWorld\RealWorldRegressionInstanceProvider.cs" /> 189 <Compile Include="Regression\RealWorld\RealWorldResourceRegressionDataDescriptor.cs" />190 190 <Compile Include="Regression\RealWorld\Tower.cs" /> 191 <Compile Include="Regression\RegressionDataDescriptor.cs" /> 191 192 <Compile Include="Regression\RegressionImportType.cs" /> 192 193 <Compile Include="Regression\RegressionInstanceProvider.cs" /> -
trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/ArtificialRegressionDataDescriptor.cs
r8825 r9133 24 24 25 25 namespace HeuristicLab.Problems.Instances.DataAnalysis { 26 public abstract class ArtificialRegressionDataDescriptor : IDataDescriptor { 27 public abstract string Name { get; } 28 public abstract string Description { get; } 29 30 protected abstract string TargetVariable { get; } 31 protected abstract string[] VariableNames { get; } 32 protected abstract string[] AllowedInputVariables { get; } 33 protected abstract int TrainingPartitionStart { get; } 34 protected abstract int TrainingPartitionEnd { get; } 35 protected abstract int TestPartitionStart { get; } 36 protected abstract int TestPartitionEnd { get; } 37 26 public abstract class ArtificialRegressionDataDescriptor : RegressionDataDescriptor { 38 27 public IRegressionProblemData GenerateRegressionData() { 39 28 Dataset dataset = new Dataset(VariableNames, this.GenerateValues()); 40 41 RegressionProblemData regData = new RegressionProblemData(dataset, AllowedInputVariables, TargetVariable); 42 regData.Name = this.Name; 43 regData.Description = this.Description; 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 return regData; 29 return GenerateRegressionData(dataset); 49 30 } 50 31 -
trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/RealWorld/RealWorldRegressionInstanceProvider.cs
r9131 r9133 24 24 using System.IO; 25 25 using System.Linq; 26 using HeuristicLab.Problems.DataAnalysis;27 26 using ICSharpCode.SharpZipLib.Zip; 28 27 … … 47 46 48 47 public override IEnumerable<IDataDescriptor> GetDataDescriptors() { 49 List<IRealWorldRegressionDataDescriptor> descriptorList = new List<IRealWorldRegressionDataDescriptor>(); 48 List<ResourceRegressionDataDescriptor> descriptorList = new List<ResourceRegressionDataDescriptor>(); 49 descriptorList.Add(new ChemicalOne()); 50 descriptorList.Add(new Housing()); 50 51 descriptorList.Add(new Tower()); 51 52 var solutionsArchiveName = GetResourceName(FileName + @"\.zip"); … … 59 60 foreach (var entry in entries.OrderBy(x => x)) { 60 61 string prettyName = Path.GetFileNameWithoutExtension(entry); 61 IRealWorldRegressionDataDescriptor desc = descriptorList.Where(x => x.Name.Equals(prettyName)).FirstOrDefault();62 ResourceRegressionDataDescriptor desc = descriptorList.Where(x => x.Name.Equals(prettyName)).FirstOrDefault(); 62 63 if (desc != null) { 63 yield return new RealWorldResourceRegressionDataDescriptor(prettyName, desc.Description, entry, desc.Training, desc.Test); 64 desc.ResourceName = entry; 65 yield return desc; 64 66 } else 65 yield return new ResourceRegressionDataDescriptor(prettyName, Description, entry);67 throw new ArgumentNullException("No Descriptor could be found for this entry."); 66 68 } 67 69 } 68 70 } 69 71 } 70 71 public override IRegressionProblemData LoadData(IDataDescriptor id) {72 var problem = base.LoadData(id);73 74 var descriptor = id as RealWorldResourceRegressionDataDescriptor;75 76 if (descriptor == null) {77 return problem;78 }79 80 problem.TrainingPartition.Start = descriptor.Training.Start;81 problem.TrainingPartition.End = descriptor.Training.End;82 problem.TestPartition.Start = descriptor.Test.Start;83 problem.TestPartition.End = descriptor.Test.End;84 85 return problem;86 }87 72 } 88 73 } -
trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/RealWorld/Tower.cs
r9131 r9133 20 20 #endregion 21 21 22 using System; 22 23 23 using System;24 using HeuristicLab.Data;25 24 namespace HeuristicLab.Problems.Instances.DataAnalysis { 26 public class Tower : IRealWorldRegressionDataDescriptor {27 public string Name { get { return "Tower"; } }28 public string Description {25 public class Tower : ResourceRegressionDataDescriptor { 26 public override string Name { get { return "Tower"; } } 27 public override string Description { 29 28 get { 30 29 return "Publication: Order of Nonlinearity as a Complexity Measure for Models " + … … 33 32 } 34 33 } 35 public IntRange Training { get { return new IntRange(0, 3135); } } 36 public IntRange Test { get { return new IntRange(3135, 4999); } } 34 protected override string TargetVariable { get { return "towerResponse"; } } 35 protected override string[] VariableNames { 36 get { return new string[] { "x1", "x2", "x3", "x4", "x5", "x6", "x7", "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23", "x24", "x25", "towerResponse" }; } 37 } 38 protected override string[] AllowedInputVariables { 39 get { return new string[] { "x1", "x2", "x3", "x4", "x5", "x6", "x7", "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23", "x24", "x25" }; } 40 } 41 protected override int TrainingPartitionStart { get { return 0; } } 42 protected override int TrainingPartitionEnd { get { return 3135; } } 43 protected override int TestPartitionStart { get { return 3135; } } 44 protected override int TestPartitionEnd { get { return 4999; } } 37 45 } 38 46 } -
trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/ResourceRegressionDataDescriptor.cs
r7849 r9133 20 20 #endregion 21 21 22 using System.Collections.Generic; 23 using System.Linq; 22 24 23 25 namespace HeuristicLab.Problems.Instances.DataAnalysis { 24 internal class ResourceRegressionDataDescriptor : IDataDescriptor { 25 public string Name { get; internal set; } 26 public string Description { get; internal set; } 26 public abstract class ResourceRegressionDataDescriptor : RegressionDataDescriptor { 27 internal string ResourceName { get; set; } 27 28 28 internal string ResourceName { get; set; } 29 internal ResourceRegressionDataDescriptor(string name, string description, string resourceName) { 30 Name = name; 31 Description = description; 32 ResourceName = resourceName; 29 public bool CheckVariableNames(IEnumerable<string> VariableNames) { 30 return this.VariableNames.All(x => VariableNames.Contains(x)); 33 31 } 34 32 } -
trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/ResourceRegressionInstanceProvider.cs
r7965 r9133 21 21 22 22 using System; 23 using System.Collections.Generic;24 23 using System.Globalization; 25 24 using System.IO; … … 35 34 protected abstract string FileName { get; } 36 35 37 public override IEnumerable<IDataDescriptor> GetDataDescriptors() {38 var solutionsArchiveName = GetResourceName(FileName + @"\.zip");39 if (!String.IsNullOrEmpty(solutionsArchiveName)) {40 using (var solutionsZipFile = new ZipInputStream(GetType().Assembly.GetManifestResourceStream(solutionsArchiveName))) {41 IList<string> entries = new List<string>();42 ZipEntry curEntry;43 while ((curEntry = solutionsZipFile.GetNextEntry()) != null) {44 entries.Add(curEntry.Name);45 }46 foreach (var entry in entries.OrderBy(x => x)) {47 yield return new ResourceRegressionDataDescriptor(Path.GetFileNameWithoutExtension(entry), Description, entry);48 }49 }50 }51 }36 //public override IEnumerable<IDataDescriptor> GetDataDescriptors() { 37 // var solutionsArchiveName = GetResourceName(FileName + @"\.zip"); 38 // if (!String.IsNullOrEmpty(solutionsArchiveName)) { 39 // using (var solutionsZipFile = new ZipInputStream(GetType().Assembly.GetManifestResourceStream(solutionsArchiveName))) { 40 // IList<string> entries = new List<string>(); 41 // ZipEntry curEntry; 42 // while ((curEntry = solutionsZipFile.GetNextEntry()) != null) { 43 // entries.Add(curEntry.Name); 44 // } 45 // foreach (var entry in entries.OrderBy(x => x)) { 46 // yield return new ResourceRegressionDataDescriptor(Path.GetFileNameWithoutExtension(entry), Description, entry); 47 // } 48 // } 49 // } 50 //} 52 51 53 52 public override IRegressionProblemData LoadData(IDataDescriptor id) { … … 70 69 71 70 Dataset dataset = new Dataset(csvFileParser.VariableNames, csvFileParser.Values); 72 string targetVar = csvFileParser.VariableNames.Where(x => dataset.DoubleVariables.Contains(x)).Last(); 73 IEnumerable<string> allowedInputVars = dataset.DoubleVariables.Where(x => !x.Equals(targetVar)); 71 if (!descriptor.CheckVariableNames(csvFileParser.VariableNames)) { 72 throw new ArgumentException("Parsed file contains variables which are not in the descriptor."); 73 } 74 74 75 IRegressionProblemData regData = new RegressionProblemData(dataset, allowedInputVars, targetVar); 76 77 int trainingPartEnd = csvFileParser.Rows * 2 / 3; 78 regData.TrainingPartition.Start = 0; 79 regData.TrainingPartition.End = trainingPartEnd; 80 regData.TestPartition.Start = trainingPartEnd; 81 regData.TestPartition.End = csvFileParser.Rows; 82 83 regData.Name = descriptor.Name; 84 regData.Description = descriptor.Description; 85 return regData; 75 return descriptor.GenerateRegressionData(dataset); 86 76 } 87 77 }
Note: See TracChangeset
for help on using the changeset viewer.