locked
Model cannot be infered useing expectation propagation RRS feed

  • Question

  • Hi,

    I have a model which I want to run using expectation propagation.

    I studied this page to see if I can run my model, since I get this error:

    This model is not supported with ExpectationPropagation due to Factor.Product(double product, double a, double b). Try using a different algorithm or expressing the model differently in
    Factor.Product(beta_use[geneRange], vdouble37)

    It means there is no way that I can run my model using EP? That is not good for me. Isn't there a trick to overcome the problem (like using other distributions, etc)? After putting a lot of effort on this work, I'm now getting this error :-(

    I also receive these errors, and I can't find out what is the problem in these cases:

    Details: [0] System.ArgumentException: Beta is not of type Gaussian for argument 3 of method GaussianProductOp.ProductAverageConditional(Gaussian Product = Gaussian, Gaussian A = Gaussian, Gaussian B = Beta)
    [1] System.ArgumentException: Gaussian is not of type double for argument 1 of method GaussianProductOp.ProductAverageConditional(double A = Gaussian, Gaussian B = Beta)
    [2] System.ArgumentException: Beta is not of type double for argument 2 of method GaussianProductOp.ProductAverageConditional(Gaussian A = Gaussian, double B = Beta)

    .....

    I would appreciate any help. Thanks a lot.

    Tuesday, May 27, 2014 5:44 PM

Answers

  • You could approximate the logistic function (or any other function) by a set of linear pieces.  Use Variable.If to determine what region of the input you are in, then output the appropriate linear function.  It depends on what aspect of the logistic function is important for your problem.
    • Marked as answer by RazinR Wednesday, May 28, 2014 2:32 PM
    Wednesday, May 28, 2014 2:31 PM
    Owner
  • The logistic returns a beta.
    • Marked as answer by RazinR Wednesday, May 28, 2014 1:39 PM
    Wednesday, May 28, 2014 12:42 PM
  • For now I'd stick to the factorized solution (products + sum).

    As to the exception you're seeing, I think it's caused by the line 

    Variable<double> othersEffect = beta[geneRange] * Variable.Logistic(Variable.Sum(weightSum));
    You're multiplying a Gaussian distributed random variable by a Beta distributed one, and we don't have such an EP product factor.
    • Marked as answer by RazinR Wednesday, May 28, 2014 1:39 PM
    Wednesday, May 28, 2014 11:01 AM

All replies

  • Can you give the one line of code that generates the exception, as well as the definitions of the random variables that participate in the product?
    Tuesday, May 27, 2014 9:58 PM
  • Here's my code. The exception occurs at run-time on line (Console.WriteLine("w array : "+engine.Infer(w));).


                var w = Variable.Array(Variable.Array<double>(geneWeightRange), geneRange).Named("w");
                w[geneRange][geneWeightRange] = Variable.GaussianFromMeanAndVariance(0, 2).ForEach(geneRange, geneWeightRange);
                
                VariableArray<double> genesubarray = Variable.Array<double>(geneWeightRange).Named("genesubarray");
                using (ForEachBlock firstBlock = Variable.ForEach(geneRange))
                {
                    Variable<double> selfEffect = -(alpha[geneRange] * genesT1[geneRange]);
                    VariableArray<double> weightSum = Variable.Array<double>(geneWeightRange).Named("weightSum");
                    Console.WriteLine("summing " + geneRange + " + " + geneWeightRange);
                    genesubarray = Variable.Subarray(genesT1, indicesArray[geneRange]);
                    weightSum[geneWeightRange] = w[geneRange][geneWeightRange] * genesubarray[geneWeightRange];//genesT1[geneRange2]
                    
                    // !!!! here a subarray should be used to remove diagonal values
                     Variable<double> othersEffect = beta[geneRange] * Variable.Logistic(Variable.Sum(weightSum));
                    genesT2[geneRange] = selfEffect + othersEffect;
                }

            

    =========

    * I just understood I may be able to compute an innerproduct for weightSum (instead of producing the multiply and then applying sum). Is it correct?

    then my code will be:

    using (ForEachBlock firstBlock = Variable.ForEach(geneRange))
                {
                    Variable<double> selfEffect = -(alpha[geneRange] * genesT1[geneRange]);
                    VariableArray<double> weightSum = Variable.Array<double>(geneWeightRange).Named("weightSum");
                    genesubarray = Variable.Subarray(genesT1, indicesArray[geneRange]);
                    // weightSum[geneWeightRange] = w[geneRange][geneWeightRange] * genesubarray[geneWeightRange];//genesT1[geneRange2]
                    Variable<double> innerproduct = Variable.InnerProduct(w[geneRange], genesubarray);
                    
                     Variable<double> othersEffect = beta[geneRange] * Variable.Logistic(innerproduct);
                    genesT2[geneRange] = selfEffect + othersEffect;
                }

    But here I still get an error on the line "Variable<double> innerproduct = Variable.InnerProduct(w[geneRange], genesubarray);". How can I refer to one row of the jagged array?



    • Edited by RazinR Wednesday, May 28, 2014 2:52 PM
    Wednesday, May 28, 2014 9:21 AM
  • For now I'd stick to the factorized solution (products + sum).

    As to the exception you're seeing, I think it's caused by the line 

    Variable<double> othersEffect = beta[geneRange] * Variable.Logistic(Variable.Sum(weightSum));
    You're multiplying a Gaussian distributed random variable by a Beta distributed one, and we don't have such an EP product factor.
    • Marked as answer by RazinR Wednesday, May 28, 2014 1:39 PM
    Wednesday, May 28, 2014 11:01 AM
  • Thanks a lot Yordan.

    Actually the innerproduct is working this way by converting the arrays to vectors:

                    Variable<Vector> v1 = Variable.Vector(w[geneRange]);
                    Variable<Vector> v2 = Variable.Vector(genesubarray);
                    Variable<double> innerproduct = Variable.InnerProduct(v1,v2);
                     Variable<double> othersEffect = beta[geneRange] * Variable.Logistic(innerproduct);

    About the problem, I don't understand it well. Since my beta variable is not distributed due to beta distribution:

    beta[geneRange] = Variable.GaussianFromMeanAndVariance(1, 0.002).ForEach(geneRange);

    I don't have any distribution other that Gaussian I think. You can see it in my code.

    Would you please help me in this case?

    How can I understand from which line of code the error is raised?


    • Edited by RazinR Wednesday, May 28, 2014 2:51 PM
    Wednesday, May 28, 2014 11:17 AM
  • The logistic returns a beta.
    • Marked as answer by RazinR Wednesday, May 28, 2014 1:39 PM
    Wednesday, May 28, 2014 12:42 PM
  • Thanks a lot Yordan. I removed the logistic and my inference is running now.

    But do you think there is a factor doing something similar that I can use here instead of logistic?

    • Edited by RazinR Wednesday, May 28, 2014 1:38 PM
    Wednesday, May 28, 2014 1:38 PM
  • You could approximate the logistic function (or any other function) by a set of linear pieces.  Use Variable.If to determine what region of the input you are in, then output the appropriate linear function.  It depends on what aspect of the logistic function is important for your problem.
    • Marked as answer by RazinR Wednesday, May 28, 2014 2:32 PM
    Wednesday, May 28, 2014 2:31 PM
    Owner
  • Thank you very much :-)

    This is really a great Forum!

    Wednesday, May 28, 2014 2:33 PM