How to create RV with known distribution and not to infer it?

I have a classic, generic linear model with number of parameters that are defined by set of priors and later inferred. However, in some of the instances, the parameters have known uncertainty distribution and do not need to be inferred.

All I want in this case is to assign the appropriate (known) distribution to them in order to evaluate the model (together with remaining FreeRVs). The code below works fine if all the model parameters are to be inferred. I am not sure how to implement and package into Theano tensor a known distribution that will not be inferred/calibrated later. I’ve tried number of options but just can’t get it right. Any suggestions will be much appreciated.

    with pm.Model():  # model specifications in PyMC3 are wrapped in a with-statement
        # Define priors for the unknown parameters
        priors = []
        for i, pri in enumerate(pri_inputs):
            if pri[0] == 1:
                priors.append(
                    pm.Uniform("priors_{}".format(i), lower=pri[1], upper=pri[2])
                )
            elif pri[0] == 2:
                priors.append(
                    pm.Deterministic("priors_{}".format(i), tt.constant(pri[1]))
                )
            elif pri[0] == 3:
                bounded_N = pm.Bound(pm.Normal, lower=pri[3], upper=pri[4])
                priors.append(bounded_N("priors_{}".format(i), mu=pri[1], sigma=pri[2]))
            elif pri[0] == 4:
                bounded_LogN = pm.Bound(pm.Lognormal, lower=pri[3], upper=pri[4])
                priors.append(
                    bounded_LogN("priors_{}".format(i), mu=pri[1], sigma=pri[2])
                )

        priors = tt.stack(priors)[:, None]
1 Like

Check out the information about random streams in the documentation for aesara, the successor to theano (e.g., here and here).

2 Likes

@cluhmann Thank you for such a rapid response! This is exactly what I needed. To be frank, I looked into this earlier today but just couldn’t get it to work, and the reason is as follows.

I followed the examples from Theno-pymc “Using Random Numbers” documentation but just couldn’t get imports right (I have theano-pymc 1.1.2 installed with PyMC v3.4.11). The link you provided for Aesara “Using Random Numbers” section seem to be up-to-date and it works OK.

Thanks again, I have been struggling with this for a few days and now I can see some light in the tunnel :slight_smile:

For those still a bit confused, for my theano-pymc 1.1.2 below code does work (modified from Aesara docs):

from theano.tensor.random.utils import RandomStream
from theano import function

and this doesn’t work (directly from theano-pymc docs):

from theano.tensor.shared_randomstreams import RandomStreams
from theano import function
2 Likes