Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/03/12 16:46:35 (12 years ago)
Author:
gkronber
Message:

#1847: merged r8084:8205 from trunk into GP move operators branch

Location:
branches/GP-MoveOperators
Files:
7 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/GP-MoveOperators

  • branches/GP-MoveOperators/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Classification/CSV/ClassifiactionCSVInstanceProvider.cs

    r7860 r8206  
    2020#endregion
    2121
    22 
    2322using System;
    2423using System.Collections.Generic;
     24using System.IO;
     25using System.Linq;
     26using System.Text;
    2527using HeuristicLab.Problems.DataAnalysis;
     28
    2629namespace HeuristicLab.Problems.Instances.DataAnalysis {
    2730  public class ClassificationCSVInstanceProvider : ClassificationInstanceProvider {
    2831    public override string Name {
    29       get { return "CSV Problem Provider"; }
     32      get { return "Comma-separated Values File"; }
    3033    }
    3134    public override string Description {
     
    4851      throw new NotImplementedException();
    4952    }
     53
     54    public override bool CanImportData {
     55      get { return true; }
     56    }
     57    public override IClassificationProblemData ImportData(string path) {
     58      TableFileParser csvFileParser = new TableFileParser();
     59
     60      csvFileParser.Parse(path);
     61
     62      Dataset dataset = new Dataset(csvFileParser.VariableNames, csvFileParser.Values);
     63      string targetVar = csvFileParser.VariableNames.Where(x => dataset.DoubleVariables.Contains(x)).Last();
     64      IEnumerable<string> allowedInputVars = dataset.DoubleVariables.Where(x => !x.Equals(targetVar));
     65
     66      ClassificationProblemData claData = new ClassificationProblemData(dataset, allowedInputVars, targetVar);
     67
     68      int trainingPartEnd = csvFileParser.Rows * 2 / 3;
     69      claData.TrainingPartition.Start = 0;
     70      claData.TrainingPartition.End = trainingPartEnd;
     71      claData.TestPartition.Start = trainingPartEnd;
     72      claData.TestPartition.End = csvFileParser.Rows;
     73      int pos = path.LastIndexOf('\\');
     74      if (pos < 0)
     75        claData.Name = path;
     76      else {
     77        pos++;
     78        claData.Name = path.Substring(pos, path.Length - pos);
     79      }
     80
     81      return claData;
     82    }
     83
     84    public override bool CanExportData {
     85      get { return true; }
     86    }
     87    public override void ExportData(IClassificationProblemData instance, string path) {
     88      StringBuilder strBuilder = new StringBuilder();
     89
     90      foreach (var variable in instance.InputVariables) {
     91        strBuilder.Append(variable + ";");
     92      }
     93      strBuilder.Remove(strBuilder.Length - 1, 1);
     94      strBuilder.AppendLine();
     95
     96      Dataset dataset = instance.Dataset;
     97
     98      for (int i = 0; i < dataset.Rows; i++) {
     99        for (int j = 0; j < dataset.Columns; j++) {
     100          strBuilder.Append(dataset.GetValue(i, j) + ";");
     101        }
     102        strBuilder.Remove(strBuilder.Length - 1, 1);
     103        strBuilder.AppendLine();
     104      }
     105
     106      using (StreamWriter writer = new StreamWriter(path)) {
     107        writer.Write(strBuilder);
     108      }
     109    }
    50110  }
    51111}
  • branches/GP-MoveOperators/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Classification/ClassificationInstanceProvider.cs

    r7965 r8206  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections;
    24 using System.Collections.Generic;
    25 using System.IO;
    26 using System.Linq;
    27 using System.Text;
    2822using HeuristicLab.Problems.DataAnalysis;
    2923
    3024namespace HeuristicLab.Problems.Instances.DataAnalysis {
    31   public abstract class ClassificationInstanceProvider : IProblemInstanceProvider<IClassificationProblemData> {
    32     public IClassificationProblemData LoadData(string path) {
    33       TableFileParser csvFileParser = new TableFileParser();
    34 
    35       csvFileParser.Parse(path);
    36 
    37       Dataset dataset = new Dataset(csvFileParser.VariableNames, csvFileParser.Values);
    38       string targetVar = csvFileParser.VariableNames.Where(x => dataset.DoubleVariables.Contains(x)).Last();
    39       IEnumerable<string> allowedInputVars = dataset.DoubleVariables.Where(x => !x.Equals(targetVar));
    40 
    41       ClassificationProblemData claData = new ClassificationProblemData(dataset, allowedInputVars, targetVar);
    42 
    43       int trainingPartEnd = csvFileParser.Rows * 2 / 3;
    44       claData.TrainingPartition.Start = 0;
    45       claData.TrainingPartition.End = trainingPartEnd;
    46       claData.TestPartition.Start = trainingPartEnd;
    47       claData.TestPartition.End = csvFileParser.Rows;
    48       int pos = path.LastIndexOf('\\');
    49       if (pos < 0)
    50         claData.Name = path;
    51       else {
    52         pos++;
    53         claData.Name = path.Substring(pos, path.Length - pos);
    54       }
    55 
    56       return claData;
    57     }
    58 
    59     public void SaveData(IClassificationProblemData instance, string path) {
    60       StringBuilder strBuilder = new StringBuilder();
    61 
    62       foreach (var variable in instance.InputVariables) {
    63         strBuilder.Append(variable + ";");
    64       }
    65       strBuilder.Remove(strBuilder.Length - 1, 1);
    66       strBuilder.AppendLine();
    67 
    68       Dataset dataset = instance.Dataset;
    69 
    70       for (int i = 0; i < dataset.Rows; i++) {
    71         for (int j = 0; j < dataset.Columns; j++) {
    72           strBuilder.Append(dataset.GetValue(i, j) + ";");
    73         }
    74         strBuilder.Remove(strBuilder.Length - 1, 1);
    75         strBuilder.AppendLine();
    76       }
    77 
    78       using (StreamWriter writer = new StreamWriter(path)) {
    79         writer.Write(strBuilder);
    80       }
    81     }
    82 
    83     public abstract IEnumerable<IDataDescriptor> GetDataDescriptors();
    84     public abstract IClassificationProblemData LoadData(IDataDescriptor descriptor);
    85 
    86     public abstract string Name { get; }
    87     public abstract string Description { get; }
    88     public abstract Uri WebLink { get; }
    89     public abstract string ReferencePublication { get; }
     25  public abstract class ClassificationInstanceProvider : ProblemInstanceProvider<IClassificationProblemData> {
    9026  }
    9127}
  • branches/GP-MoveOperators/HeuristicLab.Problems.Instances.DataAnalysis/3.3/HeuristicLab.Problems.Instances.DataAnalysis-3.3.csproj

    r7892 r8206  
    121121    <Compile Include="Classification\ResourceClassificationDataDescriptor.cs" />
    122122    <Compile Include="Classification\ResourceClassificationInstanceProvider.cs" />
     123    <Compile Include="Clustering\ClusteringInstanceProvider.cs" />
     124    <Compile Include="Clustering\CSV\ClusteringCSVInstanceProvider.cs" />
    123125    <Compile Include="Plugin.cs" />
    124126    <Compile Include="Properties\AssemblyInfo.cs" />
  • branches/GP-MoveOperators/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Plugin.cs.frame

    r7849 r8206  
    2525  [Plugin("HeuristicLab.Problems.Instances.DataAnalysis", "3.3.6.$WCREV$")]
    2626  [PluginFile("HeuristicLab.Problems.Instances.DataAnalysis-3.3.dll", PluginFileType.Assembly)]
    27   [PluginDependency("HeuristicLab.Common", "3.3")]
    2827  [PluginDependency("HeuristicLab.Core", "3.3")]
    2928  [PluginDependency("HeuristicLab.Data", "3.3")]
  • branches/GP-MoveOperators/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/CSV/RegressionCSVInstanceProvider.cs

    r7860 r8206  
    2020#endregion
    2121
    22 
    2322using System;
    2423using System.Collections.Generic;
     24using System.IO;
     25using System.Linq;
     26using System.Text;
    2527using HeuristicLab.Problems.DataAnalysis;
     28
    2629namespace HeuristicLab.Problems.Instances.DataAnalysis {
    2730  public class RegressionCSVInstanceProvider : RegressionInstanceProvider {
    2831    public override string Name {
    29       get { return "CSV Problem Provider"; }
     32      get { return "Comma-separated Values File"; }
    3033    }
    3134    public override string Description {
     
    4447      return new List<IDataDescriptor>();
    4548    }
    46 
    4749    public override IRegressionProblemData LoadData(IDataDescriptor descriptor) {
    4850      throw new NotImplementedException();
    4951    }
     52
     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) {
     87      StringBuilder strBuilder = new StringBuilder();
     88
     89      foreach (var variable in instance.InputVariables) {
     90        strBuilder.Append(variable + ";");
     91      }
     92      strBuilder.Remove(strBuilder.Length - 1, 1);
     93      strBuilder.AppendLine();
     94
     95      Dataset dataset = instance.Dataset;
     96
     97      for (int i = 0; i < dataset.Rows; i++) {
     98        for (int j = 0; j < dataset.Columns; j++) {
     99          strBuilder.Append(dataset.GetValue(i, j) + ";");
     100        }
     101        strBuilder.Remove(strBuilder.Length - 1, 1);
     102        strBuilder.AppendLine();
     103      }
     104
     105      using (StreamWriter writer = new StreamWriter(path)) {
     106        writer.Write(strBuilder);
     107      }
     108    }
    50109  }
    51110}
  • branches/GP-MoveOperators/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/RegressionInstanceProvider.cs

    r7965 r8206  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections;
    24 using System.Collections.Generic;
    25 using System.IO;
    26 using System.Linq;
    27 using System.Text;
    2822using HeuristicLab.Problems.DataAnalysis;
    2923
    3024namespace HeuristicLab.Problems.Instances.DataAnalysis {
    31   public abstract class RegressionInstanceProvider : IProblemInstanceProvider<IRegressionProblemData> {
    32 
    33     public IRegressionProblemData LoadData(string path) {
    34       TableFileParser csvFileParser = new TableFileParser();
    35       csvFileParser.Parse(path);
    36 
    37       Dataset dataset = new Dataset(csvFileParser.VariableNames, csvFileParser.Values);
    38       string targetVar = csvFileParser.VariableNames.Where(x => dataset.DoubleVariables.Contains(x)).Last();
    39 
    40       IEnumerable<string> allowedInputVars = dataset.DoubleVariables.Where(x => !x.Equals(targetVar));
    41 
    42       IRegressionProblemData regData = new RegressionProblemData(dataset, allowedInputVars, targetVar);
    43 
    44       int trainingPartEnd = csvFileParser.Rows * 2 / 3;
    45       regData.TrainingPartition.Start = 0;
    46       regData.TrainingPartition.End = trainingPartEnd;
    47       regData.TestPartition.Start = trainingPartEnd;
    48       regData.TestPartition.End = csvFileParser.Rows;
    49 
    50       int pos = path.LastIndexOf('\\');
    51       if (pos < 0)
    52         regData.Name = path;
    53       else {
    54         pos++;
    55         regData.Name = path.Substring(pos, path.Length - pos);
    56       }
    57       return regData;
    58     }
    59 
    60     public void SaveData(IRegressionProblemData instance, string path) {
    61       StringBuilder strBuilder = new StringBuilder();
    62 
    63       foreach (var variable in instance.InputVariables) {
    64         strBuilder.Append(variable + ";");
    65       }
    66       strBuilder.Remove(strBuilder.Length - 1, 1);
    67       strBuilder.AppendLine();
    68 
    69       Dataset dataset = instance.Dataset;
    70 
    71       for (int i = 0; i < dataset.Rows; i++) {
    72         for (int j = 0; j < dataset.Columns; j++) {
    73           strBuilder.Append(dataset.GetValue(i, j) + ";");
    74         }
    75         strBuilder.Remove(strBuilder.Length - 1, 1);
    76         strBuilder.AppendLine();
    77       }
    78 
    79       using (StreamWriter writer = new StreamWriter(path)) {
    80         writer.Write(strBuilder);
    81       }
    82     }
    83 
    84     public abstract IEnumerable<IDataDescriptor> GetDataDescriptors();
    85     public abstract IRegressionProblemData LoadData(IDataDescriptor descriptor);
    86 
    87     public abstract string Name { get; }
    88     public abstract string Description { get; }
    89     public abstract Uri WebLink { get; }
    90     public abstract string ReferencePublication { get; }
     25  public abstract class RegressionInstanceProvider : ProblemInstanceProvider<IRegressionProblemData> {
    9126  }
    9227}
Note: See TracChangeset for help on using the changeset viewer.