Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/21/12 11:13:32 (13 years ago)
Author:
sforsten
Message:

#1784: changed the TableFileParser, so that you don't have to determine the file format by yourself. Comments have been added for the different Parse methods.

Location:
trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3

    • Property svn:ignore set to
      Plugin.cs
      obj
  • trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/RegressionInstanceProvider.cs

    r7849 r7851  
    2323using System.Collections;
    2424using System.Collections.Generic;
    25 using System.Globalization;
    2625using System.IO;
    2726using System.Linq;
     
    3332
    3433    public IRegressionProblemData LoadData(string path) {
    35       NumberFormatInfo numberFormat;
    36       DateTimeFormatInfo dateFormat;
    37       char separator;
    38       TableFileParser.DetermineFileFormat(path, out numberFormat, out dateFormat, out separator);
     34      TableFileParser csvFileParser = new TableFileParser();
     35      csvFileParser.Parse(path);
    3936
    40       IRegressionProblemData regData = LoadData(new FileStream(path, FileMode.Open), numberFormat, dateFormat, separator);
     37      Dataset dataset = new Dataset(csvFileParser.VariableNames, csvFileParser.Values);
     38      string targetVar = csvFileParser.VariableNames.Last();
     39      IEnumerable<string> allowedInputVars = csvFileParser.VariableNames.Where(x => !x.Equals(targetVar));
     40
     41      IRegressionProblemData regData = new RegressionProblemData(dataset, allowedInputVars, targetVar);
     42
     43      int trainingPartEnd = csvFileParser.Rows * 2 / 3;
     44      regData.TrainingPartition.Start = 0;
     45      regData.TrainingPartition.End = trainingPartEnd;
     46      regData.TestPartition.Start = trainingPartEnd;
     47      regData.TestPartition.End = csvFileParser.Rows;
    4148
    4249      int pos = path.LastIndexOf('\\');
     
    4754        regData.Name = path.Substring(pos, path.Length - pos);
    4855      }
    49       return regData;
    50     }
    51 
    52     protected IRegressionProblemData LoadData(Stream stream, NumberFormatInfo numberFormat, DateTimeFormatInfo dateFormat, char separator) {
    53       TableFileParser csvFileParser = new TableFileParser();
    54 
    55       csvFileParser.Parse(stream, numberFormat, dateFormat, separator);
    56 
    57       Dataset dataset = new Dataset(csvFileParser.VariableNames, csvFileParser.Values);
    58       string targetVar = csvFileParser.VariableNames.Last();
    59       IEnumerable<string> allowedInputVars = csvFileParser.VariableNames.Where(x => !x.Equals(targetVar));
    60 
    61       RegressionProblemData regData = new RegressionProblemData(dataset, allowedInputVars, targetVar);
    62 
    63       int trainingPartEnd = csvFileParser.Rows * 2 / 3;
    64       regData.TrainingPartition.Start = 0;
    65       regData.TrainingPartition.End = trainingPartEnd;
    66       regData.TestPartition.Start = trainingPartEnd;
    67       regData.TestPartition.End = csvFileParser.Rows;
    68 
    6956      return regData;
    7057    }
  • trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/ResourceRegressionInstanceProvider.cs

    r7849 r7851  
    6464        }
    6565
    66         IRegressionProblemData regData;
     66        TableFileParser csvFileParser = new TableFileParser();
    6767        using (Stream stream = instancesZipFile.GetInputStream(entry)) {
    68           regData = LoadData(stream, numberFormat, dateFormat, separator);
     68          csvFileParser.Parse(stream, numberFormat, dateFormat, separator);
    6969        }
     70
     71        Dataset dataset = new Dataset(csvFileParser.VariableNames, csvFileParser.Values);
     72        string targetVar = csvFileParser.VariableNames.Last();
     73        IEnumerable<string> allowedInputVars = csvFileParser.VariableNames.Where(x => !x.Equals(targetVar));
     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;
    7082
    7183        regData.Name = descriptor.Name;
Note: See TracChangeset for help on using the changeset viewer.