Reputation: 1151
I am trying to create a PyMC3 model of a noisy OR-gate (a common-effect Bayes net, see graph below), as characterized in Rehder (1999):
The resulting probability distribution should be as in the table below, under "Common Effect Causal Model". q is the unconditional probability of parents.
I could easily hard code the dependence of a4 on the other three random variables, of course, but I wonder if PyMC3 has a more compact way to express this kind of disjunctive interaction.
Reference: Rehder, B. (1999). A causal model theory of categorization. In *Proceedings of the 21st annual meeting of the Cognitive Science Society *(pp. 595–600).
Upvotes: 1
Views: 539
Reputation: 76780
The most compact way I can think of capturing the relationship, assuming that c
is a shared value, is to reduce down to a single probability for a_4
. That is, something along these lines:
import pymc3 as pm
import theano.tensor as tt
with pm.Model() as model:
# prior probabilities
q = pm.Beta('q', alpha=1, beta=1)
c = pm.Beta('c', alpha=1, beta=1)
u = pm.Beta('u', alpha=1, beta=1)
# input nodes
a_i = pm.Bernoulli('a_i', p=q, shape=3)
# prob for a_4
p = pm.math.switch(tt.any(a_i), 1.0 - (1.0 - c)**tt.sum(a_i), u)
# output node
a_4 = pm.Bernoulli('a_4', p=p)
prior = pm.sample_prior_predictive(samples=1000)
where, if any of the a_i
succeed, then we compute the probability of any success in sum(a_i)
tries (i.e., 1-(1-c)^sum(a_i)
), otherwise just use u
.
Obviously, the prior probabilities can be fixed or made independent as needed (e.g., maybe you want independent q
values, which would be done by adding shape=3
).
If this isn't what you're looking for, then maybe add some clarification to the question.
Upvotes: 1