Changeset 7759 for branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Regression
- Timestamp:
- 04/24/12 16:37:40 (13 years ago)
- Location:
- branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Regression/3.4
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note: See TracChangeset
for help on using the changeset viewer.