Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10193


Ignore:
Timestamp:
12/04/13 16:52:31 (11 years ago)
Author:
mleitner
Message:

Move attribute replacement methods to separate class.

Location:
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/HeuristicLab.DataPreprocessing-3.3.csproj

    r10182 r10193  
    8585    </Compile>
    8686    <Compile Include="Implementations\PreprocessingData.cs" />
     87    <Compile Include="Implementations\PreprocessingDataManipulation.cs" />
    8788    <Compile Include="Implementations\StatisticInfo.cs" />
    8889    <Compile Include="Interfaces\IStatisticInfo.cs" />
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/PreprocessingData.cs

    r10192 r10193  
    3939
    4040    private double trainingToTestRatio;
    41     private StatisticInfo statisticInfo;
    42 
     41 
    4342    private PreprocessingData(PreprocessingData original, Cloner cloner)
    4443      : base(original, cloner) {
     
    7675      Columns = problemData.Dataset.Columns;
    7776      Rows = problemData.Dataset.Rows;
    78 
    79       statisticInfo = new StatisticInfo(this);
    8077    }
    8178
     
    184181    }
    185182
    186     public void ReplaceIndicesByValue<T>(string variableName, IEnumerable<int> indices, T value)
    187     {
    188         foreach (int index in indices)
    189         {
    190             SetCell<T>(variableName, index, value);
    191         }
    192     }
    193 
    194     public void ReplaceIndicesByAverageValue(string variableName, IEnumerable<int> indices) {
    195         double average = statisticInfo.GetAverage(variableName);
    196         ReplaceIndicesByValue<double>(variableName, indices, average);
    197     }
    198 
    199     public void ReplaceIndicesByAverageValue(string variableName, IEnumerable<int> indices) {
    200         double median = statisticInfo.GetMedian(variableName);
    201         ReplaceIndicesByValue<double>(variableName, indices, median);
    202     }
    203 
    204     public void ReplaceIndicesByRandomValue(string variableName, IEnumerable<int> indices) {
    205         Random r = new Random();
    206 
    207         double max = statisticInfo.GetMax<double>(variableName);
    208         double min = statisticInfo.GetMin<double>(variableName);
    209         double randMultiplier = (max - min);
    210         foreach (int index in indices)
    211         {
    212             double rand = r.NextDouble() * randMultiplier + min;
    213             SetCell<double>(variableName, index, rand);
    214         }
    215     }
    216 
    217     public void ReplaceIndicesByLinearInterpolationOfNeighbours(string variableName, IEnumerable<int> indices) {
    218         int countValues = GetValues<double>(variableName).Count();
    219         foreach (int index in indices)
    220         {
    221             // dont replace first or last values
    222             if (index > 0 && index < countValues) {
    223                double prev = GetCell<double>(variableName, index - 1);
    224                double next = GetCell<double>(variableName, index + 1);
    225 
    226                double interpolated = (prev + next) / 2;
    227 
    228                SetCell<double>(variableName, index, interpolated);
    229             }
    230         }
    231     }
    232 
    233     public void ReplaceIndicesByMostCommonValue(string variableName, IEnumerable<int> indices) {   
    234       if (IsType<double>(variableName)) {
    235         ReplaceIndicesByValue<double>(variableName, indices,statisticInfo.GetMostCommonValue<double>(variableName));
    236       } else if (IsType<string>(variableName)) {
    237         ReplaceIndicesByValue<string>(variableName, indices, statisticInfo.GetMostCommonValue<string>(variableName));
    238       } else if (IsType<DateTime>(variableName)) {
    239         ReplaceIndicesByValue<DateTime>(variableName, indices, statisticInfo.GetMostCommonValue<DateTime>(variableName));
    240       } else {
    241         throw new ArgumentException("column with index: " + variableName + " contains a non supported type.");
    242       }
    243     }
    244 
    245183    #endregion
    246184  }
Note: See TracChangeset for help on using the changeset viewer.