Exemplo n.º 1
0
        static void LevelI()
        {
            // Load training samples
            var signal     = DataSet.ReadDataSet(path + "signal.dat");
            var background = DataSet.ReadDataSet(path + "background.dat");

            // Load data sample
            var data = DataSet.ReadDataSet(path + "decisionTreeData.dat");

            int    bestVariableIndex = -1;
            double bestSplitValue    = 0;

            // TODO: Insert code here that calculates the proper values of bestVariableIndex and bestSplitValue



            using var file = File.CreateText(path + "decisionTreeResultsLevelI.txt");
            file.WriteLine("Event\tPurity");

            for (int i = 0; i < data.Points.Count; ++i)
            {
                // Note that you may have to change the order of the 1 and 0 here, depending on which one matches signal.
                // 1 means signal and 0 means background
                double output = data.Points[i].Variables[bestVariableIndex] > bestSplitValue ? 1 : 0;
                file.WriteLine(i + "\t" + output);
            }
        }
Exemplo n.º 2
0
        static void LevelIIAndBeyond()
        {
            // Load training samples
            var signal     = DataSet.ReadDataSet(path + "signal.dat");
            var background = DataSet.ReadDataSet(path + "background.dat");

            // Load data sample
            var data = DataSet.ReadDataSet(path + "decisionTreeData.dat");

            var tree = new Tree();

            // Train the tree
            tree.Train(signal, background);

            // Calculate output value for each event and write to file
            tree.MakeTextFile(path + "decisionTreeResults.txt", data);
        }
Exemplo n.º 3
0
        static void Main()
        {
            // Load training samples
            var background = DataSet.ReadDataSet(path + "backgroundOverallTrainingSample.dat");
            var signal     = DataSet.ReadDataSet(path + "signalOverallTrainingSample.dat");

            // Load data sample
            //var data = DataSet.ReadDataSet(path + "project3Data.dat");
            var data = DataSet.ReadDataSet(path + "project3Data.dat");

            int    numTrees = 30;
            Forest forest   = new Forest(numTrees);

            forest.Train(signal, background);
            List <double> outputs = new List <double>();

            for (int i = 0; i < data.Points.Count; i++)
            {
                double output = forest.RunDataPoint(data.Points[i]);
                outputs.Add(output);
                //Need to normalize datapoint on new scale
            }
            //double normalizationFactor = outputs.Max();
            double normalizationFactor = 1;
            //It seems like numAbove is background and numBelow is signal
            int numAbove = 0;
            int numBelow = 0;

            using var file = File.CreateText(path + "JayAyanSignals.txt");
            int count = 0;

            foreach (double d in outputs)
            {
                Console.WriteLine(d / normalizationFactor);
                if (d / normalizationFactor >= numTrees)
                {
                    numAbove += 1;
                    file.WriteLine(count);
                }
                else
                {
                    numBelow += 1;
                }
                count += 1;
            }
            Console.WriteLine("num above: " + numAbove);
            Console.WriteLine("num below: " + numBelow);
            Console.WriteLine(count);
            //Level1(signal, background, data);

            //var tree = new Tree();

            //// Train the tree
            //tree.Train(signal, background);

            //// Calculate output value for each event and write to file
            //using var file = File.CreateText(path + "Level 2 Results.txt");
            //file.WriteLine("Event\tPurity");

            //for (int i = 0; i < data.Points.Count; ++i)
            //{
            //    double output = tree.RunDataPoint(data.Points[i]);
            //    file.WriteLine(i + "\t" + output);
            //}
        }