コード例 #1
0
ファイル: Tree.cs プロジェクト: bkputnam/RandomForest
        /// <summary>
        /// slice is assumed to be a slice of indexes into data on column dim.
        /// Reorder the slice inline so that all indices pointing to dim-values
        /// that are >= splitVal are at the front, and all others are at the back.
        /// Return two new slices corresponding to those regions (the &gt;= slice is
        /// first, the &lt; slice is second)
        /// </summary>
        public static Tuple <Slice <int>, Slice <int> > ReorderSlice(Slice <int> slice, Indexer <double> featureCol, double splitVal)
        {
            int swap;
            int startIndex = 0;
            int endIndex   = slice.Length - 1;

            while (true)
            {
                while (featureCol[slice[startIndex]] >= splitVal)
                {
                    startIndex++;
                }

                while (featureCol[slice[endIndex]] < splitVal)
                {
                    endIndex--;
                }

                if (startIndex < endIndex)
                {
                    swap = slice[startIndex];
                    slice[startIndex] = slice[endIndex];
                    slice[endIndex]   = swap;
                }
                else
                {
                    return(new Tuple <Slice <int>, Slice <int> >(
                               slice.MakeSlice(0, startIndex),
                               slice.MakeSlice(startIndex, slice.Length - startIndex)
                               ));
                }
            }
        }
コード例 #2
0
ファイル: RecordSet.cs プロジェクト: bkputnam/RandomForest
        public RecordSet(List <CsvRecord> data, double nanValue = -999.0)
        {
            NRows     = data.Count;
            NFeatures = CsvRecord.NUM_FEATURES;

            Index = new int[NRows];

            _EventIds = new int[NRows];
            EventIds  = new Indexer <int>(this, _EventIds);

            _FeatureCols = new double[NFeatures][];
            FeatureCols  = new Indexer <double> [NFeatures];
            for (int featureIndex = 0; featureIndex < NFeatures; featureIndex++)
            {
                _FeatureCols[featureIndex] = new double[NRows];
                FeatureCols[featureIndex]  = new Indexer <double>(this, _FeatureCols[featureIndex]);
            }


            #region fill arrays
            for (int rownum = 0; rownum < NRows; rownum++)
            {
                var row = data[rownum];

                _EventIds[rownum] = row.EventId;
                Index[rownum]     = rownum;

                _FeatureCols[0][rownum]  = row.DER_mass_MMC;
                _FeatureCols[1][rownum]  = row.DER_mass_transverse_met_lep;
                _FeatureCols[2][rownum]  = row.DER_mass_vis;
                _FeatureCols[3][rownum]  = row.DER_pt_h;
                _FeatureCols[4][rownum]  = row.DER_deltaeta_jet_jet;
                _FeatureCols[5][rownum]  = row.DER_mass_jet_jet;
                _FeatureCols[6][rownum]  = row.DER_prodeta_jet_jet;
                _FeatureCols[7][rownum]  = row.DER_deltar_tau_lep;
                _FeatureCols[8][rownum]  = row.DER_pt_tot;
                _FeatureCols[9][rownum]  = row.DER_sum_pt;
                _FeatureCols[10][rownum] = row.DER_pt_ratio_lep_tau;
                _FeatureCols[11][rownum] = row.DER_met_phi_centrality;
                _FeatureCols[12][rownum] = row.DER_lep_eta_centrality;
                _FeatureCols[13][rownum] = row.PRI_tau_pt;
                _FeatureCols[14][rownum] = row.PRI_tau_eta;
                _FeatureCols[15][rownum] = row.PRI_tau_phi;
                _FeatureCols[16][rownum] = row.PRI_lep_pt;
                _FeatureCols[17][rownum] = row.PRI_lep_eta;
                _FeatureCols[18][rownum] = row.PRI_lep_phi;
                _FeatureCols[19][rownum] = row.PRI_met;
                _FeatureCols[20][rownum] = row.PRI_met_phi;
                _FeatureCols[21][rownum] = row.PRI_met_sumet;
                _FeatureCols[22][rownum] = row.PRI_jet_num;
                _FeatureCols[23][rownum] = row.PRI_jet_leading_pt;
                _FeatureCols[24][rownum] = row.PRI_jet_leading_eta;
                _FeatureCols[25][rownum] = row.PRI_jet_leading_phi;
                _FeatureCols[26][rownum] = row.PRI_jet_subleading_pt;
                _FeatureCols[27][rownum] = row.PRI_jet_subleading_eta;
                _FeatureCols[28][rownum] = row.PRI_jet_subleading_phi;
                _FeatureCols[29][rownum] = row.PRI_jet_all_pt;
            }
            #endregion

            for (int featureNum = 0; featureNum < NFeatures; featureNum++)
            {
                Yarr.InlineReplace(
                    _FeatureCols[featureNum],
                    nanValue,
                    double.NaN
                    );
            }
        }