Esempio n. 1
0
        /// <summary>
        /// Trains this leaf based on input DataSets for signal and background
        /// </summary>
        public void Train(DataSet signal, DataSet background)
        {
            nSignal     = signal.Points.Count;
            nBackground = background.Points.Count;

            // Determines whether this is a final leaf or if it branches
            bool branch = ChooseVariable(signal, background);

            if (branch)
            {
                // Creates a branch
                output1 = new Leaf();
                output2 = new Leaf();

                DataSet signalLeft      = new DataSet(signal.Names);
                DataSet signalRight     = new DataSet(signal.Names);
                DataSet backgroundLeft  = new DataSet(background.Names);
                DataSet backgroundRight = new DataSet(background.Names);

                foreach (var dataPoint in signal.Points)
                {
                    if (DoSplit(dataPoint))
                    {
                        signalLeft.AddDataPoint(dataPoint);
                    }
                    else
                    {
                        signalRight.AddDataPoint(dataPoint);
                    }
                }

                foreach (var dataPoint in background.Points)
                {
                    if (DoSplit(dataPoint))
                    {
                        backgroundLeft.AddDataPoint(dataPoint);
                    }
                    else
                    {
                        backgroundRight.AddDataPoint(dataPoint);
                    }
                }

                //Console.WriteLine("Splitting sLeft: " + signalLeft.Points.Count + " sRight: " + signalRight.Points.Count
                //    + " bLeft: " + backgroundLeft.Points.Count + " bRight: " + backgroundRight.Points.Count);
                // Trains each of the resulting leaves
                output1.Train(signalLeft, backgroundLeft);
                output2.Train(signalRight, backgroundRight);
            }
            // Do nothing more if it is not a branch
        }
        static public DataSet ReadDataSet(this BinaryReader br)
        {
            int nvar = br.ReadInt32();

            var names = new string[nvar];

            for (int i = 0; i < nvar; ++i)
            {
                names[i] = br.ReadString();
            }
            var dataset = new DataSet(names);

            int size = br.ReadInt32();

            for (int i = 0; i < size; ++i)
            {
                var dp = br.ReadDataPoint(nvar);
                dataset.AddDataPoint(dp);
            }

            return(dataset);
        }