This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

norm.ppf inside expression?

0 votes

Hi there.
I am trying to use the norm.ppf() function inside an expression, but i dont know how?.

norm.ppf is an inverse normal distribution, do any other inverse normal distributions would suffice.
ex:

Expression(' norm.ppf( x[1])' )

best regards.

asked Nov 20, 2014 by Jakob RC FEniCS Novice (130 points)

1 Answer

+1 vote

Hi, this might be easiest to achive with boost and compiled expression machinery. Consider

from dolfin import *

code = '''
#include <boost/math/distributions/inverse_gaussian.hpp>
using boost::math::inverse_gaussian;

namespace dolfin {
    class IG : public Expression
    {
    public:
        IG() : Expression()
        {
            _a = 1;
            _b = 1;
            ig = inverse_gaussian(_a, _b);
        }

        // Probability density function
        void eval(Array<double>& values, const Array<double>& x) const
        {
            values[0] = pdf(ig, x[0]);
        }

        // Change alpha, beta;
        void set(double alpha, double beta)
        {
            _a = alpha;
            _b = beta;
            ig = inverse_gaussian(_a, _b);
        }

    private:
        inverse_gaussian ig;
        double _a, _b;
    };
}'''

ig = Expression(code)
mesh = IntervalMesh(100, 0, 3)
plot(ig, mesh=mesh, interactive=True)
ig.set(1, 5)
plot(ig, mesh=mesh, interactive=True) 
answered Nov 21, 2014 by MiroK FEniCS Expert (80,920 points)
...