Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/07/12 16:28:33 (12 years ago)
Author:
mkommend
Message:

#1942: Reintegrated branch for CSV import.

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

Legend:

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

  • trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/CSV/RegressionCSVInstanceProvider.cs

    r8685 r8877  
    2323using System.Collections;
    2424using System.Collections.Generic;
    25 using System.Globalization;
    2625using System.IO;
    2726using System.Linq;
    28 using System.Text;
    2927using HeuristicLab.Common;
    3028using HeuristicLab.Problems.DataAnalysis;
     
    6765      var allowedInputVars = new List<string>();
    6866      var trainingIndizes = Enumerable.Range(0, (csvFileParser.Rows * 2) / 3);
    69       foreach (var variableName in dataset.DoubleVariables) {
    70         if (trainingIndizes.Count() >= 2 && dataset.GetDoubleValues(variableName, trainingIndizes).Range() > 0 &&
    71           variableName != targetVar)
    72           allowedInputVars.Add(variableName);
     67      if (trainingIndizes.Count() >= 2) {
     68        foreach (var variableName in dataset.DoubleVariables) {
     69          if (dataset.GetDoubleValues(variableName, trainingIndizes).Range() > 0 &&
     70            variableName != targetVar)
     71            allowedInputVars.Add(variableName);
     72        }
     73      } else {
     74        allowedInputVars.AddRange(dataset.DoubleVariables.Where(x => !x.Equals(targetVar)));
    7375      }
    7476
     
    8688    }
    8789
    88     public override IRegressionProblemData ImportData(string path, DataAnalysisImportType type) {
    89       TableFileParser csvFileParser = new TableFileParser();
    90       csvFileParser.Parse(path);
    91 
     90    protected override IRegressionProblemData ImportData(string path, RegressionImportType type, TableFileParser csvFileParser) {
    9291      List<IList> values = csvFileParser.Values;
    9392      if (type.Shuffle) {
     
    9594      }
    9695      Dataset dataset = new Dataset(csvFileParser.VariableNames, values);
    97       string targetVar = dataset.DoubleVariables.Last();
    9896
    9997      // turn of input variables that are constant in the training partition
     
    105103        foreach (var variableName in dataset.DoubleVariables) {
    106104          if (dataset.GetDoubleValues(variableName, trainingIndizes).Range() > 0 &&
    107             variableName != targetVar)
     105            variableName != type.TargetVariable)
    108106            allowedInputVars.Add(variableName);
    109107        }
    110108      } else {
    111         allowedInputVars.AddRange(dataset.DoubleVariables.Where(x => x.Equals(targetVar)));
     109        allowedInputVars.AddRange(dataset.DoubleVariables.Where(x => !x.Equals(type.TargetVariable)));
    112110      }
    113111
    114       RegressionProblemData regressionData = new RegressionProblemData(dataset, allowedInputVars, targetVar);
     112      RegressionProblemData regressionData = new RegressionProblemData(dataset, allowedInputVars, type.TargetVariable);
    115113
    116114      regressionData.TrainingPartition.Start = 0;
     
    123121      return regressionData;
    124122    }
    125 
    126     public override bool CanExportData {
    127       get { return true; }
    128     }
    129     public override void ExportData(IRegressionProblemData instance, string path) {
    130       var strBuilder = new StringBuilder();
    131       var colSep = CultureInfo.CurrentCulture.TextInfo.ListSeparator;
    132       foreach (var variable in instance.Dataset.VariableNames) {
    133         strBuilder.Append(variable.Replace(colSep, String.Empty) + colSep);
    134       }
    135       strBuilder.Remove(strBuilder.Length - colSep.Length, colSep.Length);
    136       strBuilder.AppendLine();
    137 
    138       var dataset = instance.Dataset;
    139 
    140       for (int i = 0; i < dataset.Rows; i++) {
    141         for (int j = 0; j < dataset.Columns; j++) {
    142           if (j > 0) strBuilder.Append(colSep);
    143           strBuilder.Append(dataset.GetValue(i, j));
    144         }
    145         strBuilder.AppendLine();
    146       }
    147 
    148       using (var writer = new StreamWriter(path)) {
    149         writer.Write(strBuilder);
    150       }
    151     }
    152123  }
    153124}
  • trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/RegressionInstanceProvider.cs

    r8598 r8877  
    2323
    2424namespace HeuristicLab.Problems.Instances.DataAnalysis {
    25   public abstract class RegressionInstanceProvider : DataAnalysisInstanceProvider<IRegressionProblemData> {
     25  public abstract class RegressionInstanceProvider : DataAnalysisInstanceProvider<IRegressionProblemData, RegressionImportType> {
    2626  }
    2727}
Note: See TracChangeset for help on using the changeset viewer.