コード例 #1
0
        public static void RunCyclingTime2()
        {
            double[]  trainingData = new double[] { 13, 17, 16, 12, 13, 12, 14, 18, 16, 16 };
            ModelData initPriors   = new ModelData(
                Gaussian.FromMeanAndPrecision(1.0, 0.01),
                Gamma.FromShapeAndScale(2.0, 0.5));

            // Train the model
            CyclistTraining cyclistTraining = new CyclistTraining();

            cyclistTraining.CreateModel();
            cyclistTraining.SetModelData(initPriors);

            ModelData posteriors1 = cyclistTraining.InferModelData(trainingData);

            Console.WriteLine("Average travel time = " + posteriors1.AverageTimeDist);
            Console.WriteLine("Traffic noise = " + posteriors1.TrafficNoiseDist);

            // Make predictions based on the trained model
            CyclistPrediction cyclistPrediction = new CyclistPrediction();

            cyclistPrediction.CreateModel();
            cyclistPrediction.SetModelData(posteriors1);

            Gaussian tomorrowsTimeDist = cyclistPrediction.InferTomorrowsTime();

            double tomorrowsMean   = tomorrowsTimeDist.GetMean();
            double tomorrowsStdDev = Math.Sqrt(tomorrowsTimeDist.GetVariance());

            Console.WriteLine("Tomorrows average time: {0:f2}", tomorrowsMean);
            Console.WriteLine("Tomorrows standard deviation: {0:f2}", tomorrowsStdDev);
            Console.WriteLine("Probability that tomorrow's time is < 18 min: {0}",
                              cyclistPrediction.InferProbabilityTimeLessThan(18.0));

            // Second round of training
            double[] trainingData2 = new double[] { 17, 19, 18, 21, 15 };

            cyclistTraining.SetModelData(posteriors1);
            ModelData posteriors2 = cyclistTraining.InferModelData(trainingData2);

            Console.WriteLine("\n2nd training pass");
            Console.WriteLine("Average travel time = " + posteriors2.AverageTimeDist);
            Console.WriteLine("Traffic noise = " + posteriors2.TrafficNoiseDist);

            // Predictions based on two rounds of training
            cyclistPrediction.SetModelData(posteriors2);

            tomorrowsTimeDist = cyclistPrediction.InferTomorrowsTime();
            tomorrowsMean     = tomorrowsTimeDist.GetMean();
            tomorrowsStdDev   = Math.Sqrt(tomorrowsTimeDist.GetVariance());

            Console.WriteLine("Tomorrows average time: {0:f2}", tomorrowsMean);
            Console.WriteLine("Tomorrows standard deviation: {0:f2}", tomorrowsStdDev);
            Console.WriteLine("Probability that tomorrow's time is < 18 min: {0}",
                              cyclistPrediction.InferProbabilityTimeLessThan(18));
        }
コード例 #2
0
 public void CreateModel()
 {
     cyclist1 = new CyclistTraining();
     cyclist1.CreateModel();
     cyclist2 = new CyclistTraining();
     cyclist2.CreateModel();
     cyclist3 = new CyclistTraining();
     cyclist3.CreateModel();
     cyclict4 = new CyclistTraining();
     cyclict4.CreateModel();
     cyclist5 = new CyclistTraining();
     cyclist5.CreateModel();
     cyclist6 = new CyclistTraining();
     cyclist6.CreateModel();
 }