I recently asked a question about how to condition a normally distributed variable on bernoulli parents. After looking at the code, and after some discussion, I understood what was going on.

In my setting, the dependent variable either takes the form of a particular distribution given the parents, or it should take the NA value (or its equivalent). So, in this case, suppose that I have two Bernoulli variables, **On** and **Triangle**, and I have one Categorical variable, **Name**, that depends on both of these. If On is true, then Name follows a categorical distribution determined by On. If Triangle is true, Name takes another categorical distribution determined by Triangle. In the case where both On and Triangle are False, Name should essentially remain undefined.

The following is mock code:

```
tri_names_given_on = numpy.array([.1, .5, .2, .2])
tri_names_given_triangle = numpy.array([.1, .1, .1, .1, .1, .3, .3])
block_names_given_on = numpy.array([.3, .4, .3])
block_names_given_block = numpy.array([.1, .2, .3, .4])
NA_ENCODING = -10.
with pymc3.Model() as model:
on = pymc3.Bernoulli('on', pOn)
triangle = pymc3.Bernoulli('triangle', pTri_given_not_on + on * tri_delta_on)
block = pymc3.Bernoulli('block', pBlock_given_not_on + on* block_delta_on)
arg1 = NA_ENCODING + on * (-NA_ENCODING + tri_names_given_on) + (1 - on) * triangle * (-NA_ENCODING + tri_names_given_triangle)
arg2 = NA_ENCODING + on * (-NA_ENCODING + block_names_given_on) + (1 - on) * block * (-NA_ENCODING + block_names_given_block)
triangle_name = None
block_name = None
if arg1 != NA_ENCODING:
triangle_name = pymc3.Categorical('triangle_name', arg1)
else:
triangle_name = pymc3.Deterministic('triangle_name', NA_ENCODING)
if arg2 != NA_ENCODING:
block_name = pymc3.Categorical('block_name', arg2)
else:
block_name = pymc3.Deterministic('block_name', NA_ENCODING)
```

Iâ€™ve been having difficulty specifying my model in PyMC, so I think Iâ€™m missing some fundamental knowledge. Iâ€™ve looked at some of the tutorials, but right now, they donâ€™t seem comprehensive. I seem to have a lot of gaps in my ability. So, any help is greatly appreciated.