locked
Standard Deviation RRS feed

  • Question

  • I'm using the following code to get a prediction for the nextPointX and nextPointY Variables, all observed values are the same, therefore the prediction should be very good at some point, the standard deviation, however, doesn't decrease lower than .6 even with 20 or more observations.

    Is there any way to get a more accurate prediction?

            protected override List<PredictionOutput> RunAlgorithm(List<System.Windows.Vector> Input, int length)
            {
                Variable<double> averageExpansionX = Variable.GaussianFromMeanAndPrecision(0, 0.01);
                Variable<double> averageExpansionY = Variable.GaussianFromMeanAndPrecision(0, 0.01);
                Variable<double> precisionX = Variable.GammaFromShapeAndScale(2.0, 0.5);
                Variable<double> precisionY = Variable.GammaFromShapeAndScale(2.0, 0.5);
                Variable<double> nextPointX = Variable.GaussianFromMeanAndPrecision(averageExpansionX, precisionX);
                Variable<double> nextPointY = Variable.GaussianFromMeanAndPrecision(averageExpansionY, precisionY);
                List<Variable<double>> perimeterPointsX = new List<Variable<double>>();
                List<Variable<double>> perimeterPointsY = new List<Variable<double>>();
                List<PredictionOutput> varOutput = new List<PredictionOutput>();
    
                InferenceEngine engine = new InferenceEngine();
    
                // add all points as observed values one by one
                for (int i = 0; i < Input.Count; i++)
                {
                    if (perimeterPointsX.Count < length)
                        perimeterPointsX.Add(Variable.GaussianFromMeanAndPrecision(averageExpansionX, precisionX));
                    if (perimeterPointsY.Count < length)
                        perimeterPointsY.Add(Variable.GaussianFromMeanAndPrecision(averageExpansionY, precisionY));
    
               // only the last length elements are used as observed values, the oldest value is overwritten whenever a new value is observed.
                    perimeterPointsX[i % length].ObservedValue = Input[i].X;
                    perimeterPointsY[i % length].ObservedValue = Input[i].Y;
    
                    Gaussian averageExpansionPosteriorX = engine.Infer<Gaussian>(averageExpansionX);
                    Gaussian averageExpansionPosteriorY = engine.Infer<Gaussian>(averageExpansionY);
                    Gamma noisePosteriorX = engine.Infer<Gamma>(precisionX);
                    Gamma noisePosteriorY = engine.Infer<Gamma>(precisionY);
    
                    // Infer the next point and compare it to the real value
                    if (i + 1 < Input.Count)
                    {
                        Gaussian predictionX = engine.Infer<Gaussian>(nextPointX);
                        Gaussian predictionY = engine.Infer<Gaussian>(nextPointY);
    
                        double predictionXMean = predictionX.GetMean();
                        double predictionYMean = predictionY.GetMean();
    
                        double predictionXStdDev = Math.Sqrt(predictionX.GetVariance());
                        double predictionYStdDev = Math.Sqrt(predictionY.GetVariance());
    
                        varOutput.Add(new PredictionOutput(i, new System.Windows.Vector(predictionXMean, predictionYMean), Input[i + 1], new System.Windows.Vector(predictionXStdDev, predictionYStdDev)));
    
                    }
                }
                return varOutput;
            }




    • Edited by XardasM Thursday, June 21, 2012 10:15 AM
    Thursday, June 21, 2012 10:09 AM

All replies

  • Try using Variational Message Passing.
    Monday, July 2, 2012 3:58 PM
    Owner