Example #1
0
        void ApplyOnTest(IEnumerable<Image> test, Stopwatch sw, IOracle oracle, string resultFile)
        {
            Console.WriteLine("Begin predicting on TEST ... elapsed time (in s):" + sw.Elapsed.TotalSeconds);
            int nbTest = test.Count();
            List<int> result = new List<int>(nbTest);
            int count = 0;
            foreach (Image t in test)
            {
                int predict = oracle.Predict(t);
                //t.ToImage(count.ToString() + ".bmp");
                //Console.WriteLine(count.ToString() + " = predict => " + predict);

                result.Add(predict);

                count++;
                if (count % 1000 == 0)
                {
                    Console.WriteLine("at count=" + count);
                    Console.WriteLine("elapsed time (in s):" + sw.Elapsed.TotalSeconds);
                }
            }

            using (StreamWriter writer = new StreamWriter(resultFile))
            {
                foreach (int res in result)
                    writer.WriteLine(res);
            }
            Console.WriteLine("elapsed time (in s):" + sw.Elapsed.TotalSeconds);
        }
Example #2
0
 public Solver(Phrases phrases, IFinder finder, IOracle oracle, int bestSugessionsCount = 20, double metricEpsilon = 1)
 {
     this.phrases = phrases;
     Finder = finder;
     Oracle = oracle;
     this.bestSugessionsCount = bestSugessionsCount;
     this.metricEpsilon = metricEpsilon;
     Name = oracle.GetType().Name + "-" + finder.GetType().Name;
 }
Example #3
0
        static void InfoAboutTrainingSet(List<Person> ps, IOracle oracle = null)
        {
            double nbSurvived = ps.Count(
                p => oracle == null ? p.Survived : oracle.Predict(p)
                );
            double nbTotal = ps.Count();
            double rate = nbSurvived / nbTotal;

            Console.WriteLine("NbSurvived:{0};NbTotal:{1};SurvivalRate:{2}", nbSurvived, nbTotal, rate);
        }
Example #4
0
 void ApplyOnValidation(IEnumerable<Image> validation, Stopwatch sw, IOracle oracle)
 {
     int nbTotal = 0;
     int nbCorrect = 0;
     Console.WriteLine("Begin predicting ...Elapsed time (in s):" + sw.Elapsed.TotalSeconds);
     Console.WriteLine();
     foreach (Image v in validation)
     {
         nbTotal++;
         if (nbTotal % 50 == 0)
         {
             Console.WriteLine("at nbTotal=" + nbTotal + ". Elapsed time (in s):" + sw.Elapsed.TotalSeconds);
         }
         int predict = oracle.Predict(v);
         if (predict == v.Label)
             nbCorrect++;
     }
     Console.WriteLine("nbTotal:" + nbTotal);
     Console.WriteLine("nbCorrect:" + nbCorrect);
     Console.WriteLine("elapsed time (in s):" + sw.Elapsed.TotalSeconds);
 }
Example #5
0
 private Solver BuildSolver(IOracle mephalaOracle)
 {
     return new Solver(phrases, finder, mephalaOracle);
 }
Example #6
0
        static void WriteToTestResult(IOracle forest)
        {
            List<Person> test = ImportFromCsv.GetDataSet(__dataFolder + "originalTest.csv", train: false);

            using (StreamReader reader = new StreamReader(__dataFolder + "originalTest.csv")) // Just to take the csv header ...
            using (StreamWriter writer = new StreamWriter(__dataFolder + "/result.csv"))
            {
                writer.Write("survived,");
                writer.WriteLine(reader.ReadLine());

                foreach (var p in test)
                {
                    bool predict = forest.Predict(p);
                    writer.Write(predict ? "1," : "0,");
                    writer.WriteLine(reader.ReadLine());
                }
            }
        }
Example #7
0
 static double MesureModelOnValidation(List<Person> valid, IOracle oracle)
 {
     // Mesrue forest's Performance on Validation
     int nbErrorOnValidation = 0;
     foreach (var v in valid)
     {
         bool predict = oracle.Predict(v);
         if (predict != v.Survived)
             nbErrorOnValidation++;
     }
     double percent = (nbErrorOnValidation + 0.00) / valid.Count * 100;
     return percent;
 }
Example #8
0
 public void AddChild(object modality, IOracle dn)
 {
     _children.Add(modality, dn);
 }
Example #9
0
 private double Score(IEnumerable<Image> valid, IOracle oracle)
 {
     double nbImage = 0;
     double correct = 0;
     foreach (Image image in valid)
     {
         nbImage++;
         int predict = oracle.Predict(image);
         if (predict == image.Label)
         {
             correct++;
         }
     }
     return correct / nbImage;
 }