frompymc3importCategorical,Model,DensityDistfrompymc3.distributions.dist_mathimportboundfromtheano.tensorimportswitch,log,le,constantfromtheanoimportshared,gradientimportnumpyasnpwithModel()assimple_model:Age=Categorical('Age',p=[0.3,0.5],testval=1)Sex=Categorical('Sex',p=[0.6,0.4],testval=0)defedu_logp(value):p=constant(np.array([[0.25,0.28,0.12],[0.36,0.30,0.10]]))returnbound(switch(value,log(p[Sex,Age]),log(1-p[Sex,Age])),value>=0,value<=1)Education=DensityDist('Education',edu_logp,dtype='int64',testval=0)defres_logp(value):p=constant(np.array([0.75,0.8]))returnbound(switch(value,log(p[Education]),log(1-p[Education])),value>=0,value<=1)Residence=DensityDist('Residence',res_logp,dtype='int64',testval=0)defocc_logp(value):p=constant(np.array([0.04,0.08]))returnbound(switch(value,log(p[Education]),log(1-p[Education])),value>=0,value<=1)Occupation=DensityDist('Occupation',occ_logp,dtype='int64',testval=0)deftravel_logp(value):p=constant(np.array([[[0.48,0.42,0.10],# Small and employer[0.56,0.36,0.08]],# Small and self-employed[[0.58,0.24,0.18],# Big and employer[0.70,0.21,0.09]]]))# Big and self-employedreturnbound(log(p[Residence,Occupation,value]),value>=0,value<=2)Travel=DensityDist('Travel',travel_logp,dtype='int64',testval=0)