Find() public method

Find the specified column.
public Find ( String name ) : int
name String The column name.
return int
        /// <summary>
        /// Extract fields from a file into a numeric array for machine learning.
        /// </summary>
        ///
        /// <param name="analyst">The analyst to use.</param>
        /// <param name="headers">The headers for the input data.</param>
        /// <param name="csv">The CSV that holds the input data.</param>
        /// <param name="outputLength">The length of the returned array.</param>
        /// <param name="skipOutput">True if the output should be skipped.</param>
        /// <returns>The encoded data.</returns>
        public static double[] ExtractFields(EncogAnalyst analyst,
                                             CSVHeaders headers, ReadCSV csv,
                                             int outputLength, bool skipOutput)
        {
            var output = new double[outputLength];
            int outputIndex = 0;

            foreach (AnalystField stat in analyst.Script.Normalize.NormalizedFields)
            {
                if (stat.Action == NormalizationAction.Ignore)
                {
                    continue;
                }

                if (stat.Output && skipOutput)
                {
                    continue;
                }

                int index = headers.Find(stat.Name);
                String str = csv.Get(index);

                // is this an unknown value?
                if (str.Equals("?") || str.Length == 0)
                {
                    IHandleMissingValues handler = analyst.Script.Normalize.MissingValues;
                    double[] d = handler.HandleMissing(analyst, stat);

                    // should we skip the entire row
                    if (d == null)
                    {
                        return null;
                    }

                    // copy the returned values in place of the missing values
                    for (int i = 0; i < d.Length; i++)
                    {
                        output[outputIndex++] = d[i];
                    }
                }
                else
                {
                    // known value

                    if (stat.Action == NormalizationAction.Normalize)
                    {
                        double d = csv.Format.Parse(str.Trim());
                        d = stat.Normalize(d);
                        output[outputIndex++] = d;
                    }
                    else
                    {
                        double[] d = stat.Encode(str.Trim());

                        foreach (double element in d)
                        {
                            output[outputIndex++] = element;
                        }
                    }
                }
            }

            return output;
        }
Ejemplo n.º 2
0
 public static double[] ExtractFields(EncogAnalyst analyst, CSVHeaders headers, ReadCSV csv, int outputLength, bool skipOutput)
 {
     double[] numArray = new double[outputLength];
     int num = 0;
     using (IEnumerator<AnalystField> enumerator = analyst.Script.Normalize.NormalizedFields.GetEnumerator())
     {
         AnalystField field;
         int num2;
         string str;
         IHandleMissingValues values;
         double[] numArray2;
         int num3;
         double num4;
         double num5;
         double[] numArray4;
         double[] numArray5;
         int num6;
         goto Label_0070;
     Label_0022:
         if (!skipOutput)
         {
             goto Label_02B7;
         }
     Label_0029:
         if ((((uint) skipOutput) + ((uint) num6)) > uint.MaxValue)
         {
             goto Label_00B1;
         }
         goto Label_0070;
     Label_0043:
         if ((((uint) num4) - ((uint) outputLength)) > uint.MaxValue)
         {
             goto Label_0022;
         }
         if (((uint) num3) > uint.MaxValue)
         {
             goto Label_022A;
         }
     Label_0070:
         if (enumerator.MoveNext())
         {
             goto Label_02CD;
         }
         goto Label_01C2;
     Label_007E:
         if (((uint) num2) > uint.MaxValue)
         {
             goto Label_021B;
         }
         goto Label_0043;
     Label_009A:
         if (!field.Output)
         {
             goto Label_02B7;
         }
         goto Label_0022;
     Label_00B1:
         num5 = numArray5[num6];
     Label_00B9:
         numArray[num++] = num5;
         num6++;
     Label_00C8:
         if (num6 < numArray5.Length)
         {
             goto Label_00B1;
         }
         if ((((uint) num3) + ((uint) num5)) >= 0)
         {
             goto Label_0116;
         }
     Label_00E8:
         numArray5 = field.Encode(str.Trim());
         num6 = 0;
         if ((((uint) num6) + ((uint) num5)) >= 0)
         {
             goto Label_00C8;
         }
     Label_0116:
         if ((((uint) num4) - ((uint) num5)) <= uint.MaxValue)
         {
             goto Label_007E;
         }
         goto Label_01C2;
     Label_0138:
         if (field.Action == NormalizationAction.Normalize)
         {
             num4 = csv.Format.Parse(str.Trim());
             num4 = field.Normalize(num4);
             numArray[num++] = num4;
             if ((((uint) outputLength) - ((uint) num6)) > uint.MaxValue)
             {
                 goto Label_022A;
             }
             goto Label_0070;
         }
         if ((((uint) num2) - ((uint) outputLength)) <= uint.MaxValue)
         {
             goto Label_00E8;
         }
         goto Label_01C2;
     Label_01A4:
         if (num3 < numArray2.Length)
         {
             goto Label_0207;
         }
         goto Label_0070;
     Label_01B1:
         if (str.Length == 0)
         {
             goto Label_025F;
         }
         goto Label_0138;
     Label_01C2:
         if ((((uint) num6) - ((uint) num3)) >= 0)
         {
             return numArray;
         }
         if ((((uint) num2) - ((uint) num5)) <= uint.MaxValue)
         {
             goto Label_02CD;
         }
         goto Label_0295;
     Label_0202:
         num3 = 0;
         goto Label_01A4;
     Label_0207:
         numArray[num++] = numArray2[num3];
         num3++;
         goto Label_02E6;
     Label_021B:
         numArray2 = values.HandleMissing(analyst, field);
         if (numArray2 != null)
         {
             goto Label_0202;
         }
     Label_022A:
         numArray4 = null;
         if ((((uint) outputLength) | 8) != 0)
         {
             return numArray4;
         }
         goto Label_02E6;
     Label_024E:
         if (!str.Equals("?"))
         {
             goto Label_01B1;
         }
     Label_025F:
         values = analyst.Script.Normalize.MissingValues;
         goto Label_021B;
     Label_0273:
         if (((uint) num5) > uint.MaxValue)
         {
             goto Label_00B9;
         }
         str = csv.Get(num2);
         goto Label_024E;
     Label_0295:
         if ((((uint) num5) | uint.MaxValue) == 0)
         {
             goto Label_0029;
         }
         goto Label_0022;
     Label_02B7:
         num2 = headers.Find(field.Name);
         goto Label_0273;
     Label_02CD:
         field = enumerator.Current;
         if (field.Action == NormalizationAction.Ignore)
         {
             goto Label_0070;
         }
         goto Label_009A;
     Label_02E6:
         if ((((uint) num4) - ((uint) skipOutput)) >= 0)
         {
             goto Label_01A4;
         }
     }
     return numArray;
 }