Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/03/12 13:41:36 (12 years ago)
Author:
sforsten
Message:

#1782:

  • renamed CanSave to CanExportData and SaveData to ExportData
  • added the same functionality for importing problem instance as we implemented for exporting
  • some special changes had to be made in Problems.Instances.VehicleRouting
File:
1 edited

Legend:

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

    r8180 r8192  
    2020#endregion
    2121
    22 
    2322using System;
    2423using System.Collections.Generic;
    2524using System.IO;
     25using System.Linq;
    2626using System.Text;
    2727using HeuristicLab.Problems.DataAnalysis;
     28
    2829namespace HeuristicLab.Problems.Instances.DataAnalysis {
    2930  public class RegressionCSVInstanceProvider : RegressionInstanceProvider {
     
    4344    }
    4445
    45     public override bool CanSaveData {
    46       get { return true; }
    47     }
    48 
    4946    public override IEnumerable<IDataDescriptor> GetDataDescriptors() {
    5047      return new List<IDataDescriptor>();
    5148    }
     49    public override IRegressionProblemData LoadData(IDataDescriptor descriptor) {
     50      throw new NotImplementedException();
     51    }
    5252
    53     public override void SaveData(IRegressionProblemData instance, string path) {
     53    public override bool CanImportData {
     54      get { return true; }
     55    }
     56    public override IRegressionProblemData ImportData(string path) {
     57      TableFileParser csvFileParser = new TableFileParser();
     58      csvFileParser.Parse(path);
     59
     60      Dataset dataset = new Dataset(csvFileParser.VariableNames, csvFileParser.Values);
     61      string targetVar = csvFileParser.VariableNames.Where(x => dataset.DoubleVariables.Contains(x)).Last();
     62
     63      IEnumerable<string> allowedInputVars = dataset.DoubleVariables.Where(x => !x.Equals(targetVar));
     64
     65      IRegressionProblemData regData = new RegressionProblemData(dataset, allowedInputVars, targetVar);
     66
     67      int trainingPartEnd = csvFileParser.Rows * 2 / 3;
     68      regData.TrainingPartition.Start = 0;
     69      regData.TrainingPartition.End = trainingPartEnd;
     70      regData.TestPartition.Start = trainingPartEnd;
     71      regData.TestPartition.End = csvFileParser.Rows;
     72
     73      int pos = path.LastIndexOf('\\');
     74      if (pos < 0)
     75        regData.Name = path;
     76      else {
     77        pos++;
     78        regData.Name = path.Substring(pos, path.Length - pos);
     79      }
     80      return regData;
     81    }
     82
     83    public override bool CanExportData {
     84      get { return true; }
     85    }
     86    public override void ExportData(IRegressionProblemData instance, string path) {
    5487      StringBuilder strBuilder = new StringBuilder();
    5588
     
    74107      }
    75108    }
    76 
    77     public override IRegressionProblemData LoadData(IDataDescriptor descriptor) {
    78       throw new NotImplementedException();
    79     }
    80109  }
    81110}
Note: See TracChangeset for help on using the changeset viewer.