PyMC: setting model installation restrictions

I'm trying to set limits on fitting variables using the MCMC approach using PyMC For example, I defined the following stochastic models in PyMC

import pymc as pm
a=pm.Uniform('a',lower=0.,upper=1.,value=0.2)
b=pm.Uniform('b',lower=0.,upper=1.,value=0.2)

How can I define a model so that b is always less than or equal? Is this the right approach?

a=pm.Uniform('a',lower=0.,upper=1.,value=0.2)
b=pm.Uniform('b',lower=0.,upper=b,value=0.2) #used a as the upper bound for b
+4
source share
1 answer

I think you mean "upper = a".

I think you can define "b" as a stochastic variable depending on "a", as in the following:

import pymc as pm
import numpy as np
import scipy.stats as scs

@pm.stochastic
def b(value=0.0, a=a):
    def logp(value, a):
        if 0 <= value <= a:
            return np.log(1/a)
        else:
            return -np.inf

    def random(a):
        return scs.uniform(0, a).rvs()

Now you can check the variable by calling "b.random ()" and you should see the uniform distribution bounded above by "a" ("a.value").

PyMC .

0

Source: https://habr.com/ru/post/1543457/


All Articles