Exemplo n.º 1
0
 private static void StringToCategorical(IList<int> colInds, IMatrixData mdata)
 {
     int[] inds = ArrayUtils.Complement(colInds, mdata.StringColumnCount);
     string[] names = ArrayUtils.SubArray(mdata.StringColumnNames, colInds);
     string[] descriptions = ArrayUtils.SubArray(mdata.StringColumnDescriptions, colInds);
     string[][] str = ArrayUtils.SubArray(mdata.StringColumns, colInds);
     string[][][] newCat = new string[str.Length][][];
     for (int j = 0; j < str.Length; j++){
         newCat[j] = new string[str[j].Length][];
         for (int i = 0; i < newCat[j].Length; i++){
             if (str[j][i] == null || str[j][i].Length == 0){
                 newCat[j][i] = new string[0];
             } else{
                 string[] x = str[j][i].Split(';');
                 Array.Sort(x);
                 newCat[j][i] = x;
             }
         }
     }
     mdata.AddCategoryColumns(names, descriptions, newCat);
     mdata.StringColumns = ArrayUtils.SubList(mdata.StringColumns, inds);
     mdata.StringColumnNames = ArrayUtils.SubList(mdata.StringColumnNames, inds);
     mdata.StringColumnDescriptions = ArrayUtils.SubList(mdata.StringColumnDescriptions, inds);
 }
Exemplo n.º 2
0
 private static void NumericToCategorical(IList<int> colInds, IMatrixData mdata)
 {
     int[] inds = ArrayUtils.Complement(colInds, mdata.NumericColumnCount);
     string[] names = ArrayUtils.SubArray(mdata.NumericColumnNames, colInds);
     string[] descriptions = ArrayUtils.SubArray(mdata.NumericColumnDescriptions, colInds);
     double[][] num = ArrayUtils.SubArray(mdata.NumericColumns, colInds);
     string[][][] newCat = new string[num.Length][][];
     for (int j = 0; j < num.Length; j++){
         newCat[j] = new string[num[j].Length][];
         for (int i = 0; i < newCat[j].Length; i++){
             if (double.IsNaN(num[j][i]) || double.IsInfinity(num[j][i])){
                 newCat[j][i] = new string[0];
             } else{
                 newCat[j][i] = new[]{"" + num[j][i]};
             }
         }
     }
     mdata.AddCategoryColumns(names,descriptions, newCat);
     mdata.NumericColumns = ArrayUtils.SubList(mdata.NumericColumns, inds);
     mdata.NumericColumnNames = ArrayUtils.SubList(mdata.NumericColumnNames, inds);
     mdata.NumericColumnDescriptions = ArrayUtils.SubList(mdata.NumericColumnDescriptions, inds);
 }