locked
nan Error in using Truncated Gaussian and IsPositive Op RRS feed

  • Question

  • Hi, all,

                I am new to Infer.net. And I tried to model the truncated version of  products of three Gaussians very similar to the example in the tutorial (see code below), but the NAN error pop up in the IsPositive Op.  Anyone know how to solve?

    Thank you very much.

    	public class TruncatedGaussian
    	{
    		public void Run()
    		{
    			for (double thresh = 0.1; thresh <= 1; thresh += 0.1)
    			{
    				Variable<double> x = Variable.GaussianFromMeanAndVariance(0, 1).Named("x");
                    Variable<double> a = Variable.GaussianFromMeanAndVariance(0, 1).Named("a");
                    Variable<double> b = Variable.GaussianFromMeanAndVariance(0, 1).Named("b");
                    Variable<bool> test = Variable.Bernoulli(0.001).Named("test");
                    Variable<double> y = a * x * b;
                    using (Variable.If(test))
                    {
                        Variable.ConstrainTrue(y > thresh);
                    }
    				InferenceEngine engine = new InferenceEngine();
    				if (engine.Algorithm is ExpectationPropagation)
    					Console.WriteLine("Dist over x given thresh of " + thresh + "=" + engine.Infer(x));
    				else
    					Console.WriteLine("This example only runs with Expectation Propagation");
    			}
    		}
    
    	}

    Monday, September 15, 2014 12:31 PM

Answers

  • That is caused by a bug in the Gaussian product operator.  Add this line to work around it:

    engine.Compiler.GivePriorityTo(typeof(GaussianProductOp_SHG09));
    

    • Marked as answer by Zhizhuo Friday, September 19, 2014 6:49 PM
    Tuesday, September 16, 2014 12:59 PM
    Owner

All replies

  • That is caused by a bug in the Gaussian product operator.  Add this line to work around it:

    engine.Compiler.GivePriorityTo(typeof(GaussianProductOp_SHG09));
    

    • Marked as answer by Zhizhuo Friday, September 19, 2014 6:49 PM
    Tuesday, September 16, 2014 12:59 PM
    Owner
  • It works!  Great thanks, Tom.
    Friday, September 19, 2014 3:27 PM