Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/11/11 18:41:03 (14 years ago)
Author:
gkronber
Message:

#790 Fixed minor issues in LDA, LR, SVC and SVR to make sure everything works correctly in presence of NaN and infinity values.

Location:
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/AlglibUtil.cs

    r5809 r6002  
    2727  public static class AlglibUtil {
    2828    public static double[,] PrepareInputMatrix(Dataset dataset, IEnumerable<string> variables, IEnumerable<int> rows) {
    29       List<int> allowedRows = CalculateAllowedRows(dataset, variables, rows).ToList();
     29      List<string> variablesList = variables.ToList();
     30      List<int> rowsList = rows.ToList();
    3031
    31       double[,] matrix = new double[allowedRows.Count, variables.Count()];
    32       for (int row = 0; row < allowedRows.Count; row++) {
     32      double[,] matrix = new double[rowsList.Count, variablesList.Count];
     33      for (int row = 0; row < rowsList.Count; row++) {
    3334        int col = 0;
    3435        foreach (string column in variables) {
    35           matrix[row, col] = dataset[column, row];
     36          matrix[row, col] = dataset[column, rowsList[row]];
    3637          col++;
    3738        }
     
    3940      return matrix;
    4041    }
    41 
    42     private static IEnumerable<int> CalculateAllowedRows(Dataset dataset, IEnumerable<string> variables, IEnumerable<int> rows) {
    43       // return only rows that contain no infinity or NaN values
    44       return from row in rows
    45              where (from variable in variables
    46                     let x = dataset[variable, row]
    47                     where double.IsInfinity(x) || double.IsNaN(x)
    48                     select 1)
    49                     .Any() == false
    50              select row;
    51     }
    5242  }
    5343}
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/LinearDiscriminantAnalysis.cs

    r5809 r6002  
    7373      int nClasses = problemData.ClassNames.Count();
    7474      double[,] inputMatrix = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables.Concat(new string[] { targetVariable }), rows);
     75      if (inputMatrix.Cast<double>().Any(x => double.IsNaN(x) || double.IsInfinity(x)))
     76        throw new NotSupportedException("Linear discriminant analysis does not support NaN or infinity values in the input dataset.");
    7577
    7678      // change class values into class index
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/LinearRegression.cs

    r5809 r6002  
    7676      IEnumerable<int> rows = Enumerable.Range(samplesStart, samplesEnd - samplesStart);
    7777      double[,] inputMatrix = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables.Concat(new string[] { targetVariable }), rows);
     78      if (inputMatrix.Cast<double>().Any(x => double.IsNaN(x) || double.IsInfinity(x)))
     79        throw new NotSupportedException("Linear regression does not support NaN or infinity values in the input dataset.");
    7880
    7981      alglib.linearmodel lm = new alglib.linearmodel();
Note: See TracChangeset for help on using the changeset viewer.