示例#1
0
        public static void Test()
        {
            Console.WriteLine("Line 1:");
            string line1 = Console.ReadLine();

            Console.WriteLine("Line 2:");
            string line2 = Console.ReadLine();

            RecordPair pair = new RecordPair();

            pair.Record1 = DataCleaner.CleanRecord(Record.FromString(line1));
            pair.Record2 = DataCleaner.CleanRecord(Record.FromString(line2));

            DecisionTree[] forest = DataLoader.LoadForestFromDirectory(".");

            TreeLogger logger  = new TreeLogger();
            bool       isMatch = DecisionTreeBuilder.IsMatch(pair, forest, logger);

            Console.WriteLine("Search for those in training data who make it there?");
            string response = Console.ReadLine();

            //RecordPair pair2 = new RecordPair();
            //pair2.Record1 = Record.FromString("LAZAR,,KALLER,,M,,16/10/1965,,,,,,,-1,,,4839002,15479245,");
            //pair2.Record2 = Record.FromString("ADRIENNE,,KELLEY,,F,895535860,16/10/1965,9175738850,,1560 SILVER ST,2H,BRONX,NY,10461,,[email protected],4799491,15637549,");

            //bool ret = DecisionTreeBuilder.ReplayDecision(pair2, logger.SplittingQuestionsToTheBottom);

            if (response.ToLower() == "y")
            {
                using (StreamWriter sw = File.AppendText("c:/users/brush/desktop/gothere.txt"))
                {
                    List <RecordPair> pairs = new List <RecordPair>();
                    Console.Write("Loading training data for this iteration...");
                    pairs.AddRange(DataLoader.GetPositivesFromMRNData("mrns.csv"));
                    pairs.AddRange(DataLoader.GetHandPassedSets("more.csv"));
                    pairs.AddRange(DataLoader.GetRejectedRecordPairs("rejected.txt"));
                    //pairs.AddRange(DataLoader.GetPairsFromMisfitsFile("misfits.txt"));
                    Console.WriteLine("...done");

                    Parallel.ForEach(pairs, p =>
                    {
                        if (DecisionTreeBuilder.ReplayDecision(p, logger.SplittingQuestionsToTheBottom))
                        {
                            lock (sw)
                            {
                                sw.WriteLine(p);
                            }
                        }
                    });
                }
            }

            return;
        }
示例#2
0
        public static bool IsMatch(RecordPair pair, DecisionTree[] forest, TreeLogger logger)
        {
            int positives = 0;

            foreach (DecisionTree tree in forest)
            {
                if (RecurseAndCheckIsMatch(tree.Root, pair, logger))
                {
                    positives++;
                }
            }

            return((positives / (forest.Length) * 1.0) > .5);
        }
示例#3
0
        private static bool RecurseAndCheckIsMatch(DecisionTreeNode parentNode, RecordPair pair, TreeLogger logger)
        {
            if (parentNode.IsLeaf)
            {
                if (logger != null)
                {
                    logger.FinalResultIsMatch = parentNode.IsMatch;
                    Console.WriteLine($"Is Match {parentNode.IsMatch}");
                }

                return(parentNode.IsMatch);
            }
            else
            {
                bool goesLeft = ComputeSplitDirection(parentNode.Question, pair);

                if (logger != null)
                {
                    Console.WriteLine($"Question: {parentNode.Question} Answer: {goesLeft}.");
                    logger.SplittingQuestionsToTheBottom.Add(new Tuple <SplittingQuestion, bool>(parentNode.Question, goesLeft));
                }

                if (goesLeft)
                {
                    return(RecurseAndCheckIsMatch(parentNode.LeftBranch, pair, logger));
                }
                else
                {
                    return(RecurseAndCheckIsMatch(parentNode.RightBranch, pair, logger));
                }
            }
        }