Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

model_to_graphviz displays incomplete graph #3165

Closed
JackCaster opened this issue Aug 22, 2018 · 7 comments · Fixed by #3213
Closed

model_to_graphviz displays incomplete graph #3165

JackCaster opened this issue Aug 22, 2018 · 7 comments · Fixed by #3213
Assignees

Comments

@JackCaster
Copy link
Contributor

model_to_graphviz is awesome!
However, I have an example in which the graph seems to be incomplete: see this notebook. There, I am modelling a beta distribution. Instead of modelling directly the parameters alpha and beta, I transform them to work with central tendency and precision.
image
In the graph above I would expect the blocks for alpha and beta to be connected to the likelihood block.

OS: Windows 10
PyMC3 version: updated to master
Other packages:

# Name                    Version                   Build  Channel
appdirs                   1.4.3            py36h28b3542_0
asn1crypto                0.24.0                   py36_0
attrs                     18.1.0                   py36_0
automat                   0.7.0                    py36_0
backcall                  0.1.0                    py36_0
blas                      1.0                         mkl
bleach                    2.1.3                    py36_0
ca-certificates           2018.03.07                    0
certifi                   2018.8.13                py36_0
cffi                      1.11.5           py36h945400d_0
colorama                  0.3.9            py36h029ae33_0
constantly                15.1.0           py36h28b3542_0
cryptography              2.3              py36h74b6da3_0
cryptography-vectors      2.3                      py36_0
cycler                    0.10.0           py36h009560c_0
cython                    0.28.5           py36h6538335_0
decorator                 4.3.0                    py36_0
entrypoints               0.2.3                    py36_2
freetype                  2.9.1                ha9979f8_1
graphviz                  2.38                 hfd603c8_2
h5py                      2.8.0            py36h3bdd7fb_1
hdf5                      1.10.2               hac2f561_1
html5lib                  1.0.1                    py36_0
hyperlink                 18.0.0                   py36_0
icc_rt                    2017.0.4             h97af966_0
icu                       58.2                 ha66f8fd_1
idna                      2.7                      py36_0
incremental               17.5.0                   py36_0
intel-openmp              2018.0.3                      0
ipykernel                 4.8.2                    py36_0
ipython                   6.5.0                    py36_0
ipython_genutils          0.2.0            py36h3c5d0ee_0
ipywidgets                7.4.0                    py36_0
jedi                      0.12.1                   py36_0
jinja2                    2.10                     py36_0
joblib                    0.12.2                   py36_0
jpeg                      9b                   hb83a4c4_2
jsonschema                2.6.0            py36h7636477_0
jupyter                   1.0.0                    py36_5
jupyter_client            5.2.3                    py36_0
jupyter_console           5.2.0                    py36_1
jupyter_core              4.4.0                    py36_0
kiwisolver                1.0.1            py36h6538335_0
libgpuarray               0.7.6                hfa6e2cd_0
libpng                    1.6.34               h79bbb47_0
libpython                 2.1                      py36_0
libsodium                 1.0.16               h9d3ae62_0
m2w64-binutils            2.25.1                        5
m2w64-bzip2               1.0.6                         6
m2w64-crt-git             5.0.0.4636.2595836               2
m2w64-gcc                 5.3.0                         6
m2w64-gcc-ada             5.3.0                         6
m2w64-gcc-fortran         5.3.0                         6
m2w64-gcc-libgfortran     5.3.0                         6
m2w64-gcc-libs            5.3.0                         7
m2w64-gcc-libs-core       5.3.0                         7
m2w64-gcc-objc            5.3.0                         6
m2w64-gmp                 6.1.0                         2
m2w64-headers-git         5.0.0.4636.c0ad18a               2
m2w64-isl                 0.16.1                        2
m2w64-libiconv            1.14                          6
m2w64-libmangle-git       5.0.0.4509.2e5a9a2               2
m2w64-libwinpthread-git   5.0.0.4634.697f757               2
m2w64-make                4.1.2351.a80a8b8               2
m2w64-mpc                 1.0.3                         3
m2w64-mpfr                3.1.4                         4
m2w64-pkg-config          0.29.1                        2
m2w64-toolchain           5.3.0                         7
m2w64-tools-git           5.0.0.4592.90b8472               2
m2w64-windows-default-manifest 6.4                           3
m2w64-winpthreads-git     5.0.0.4634.697f757               2
m2w64-zlib                1.2.8                        10
mako                      1.0.7                    py36_0
markupsafe                1.0              py36hfa6e2cd_1
matplotlib                2.2.3            py36hd159220_0
mistune                   0.8.3            py36hfa6e2cd_1
mkl                       2018.0.3                      1
mkl-service               1.1.2            py36hb217b18_4
mkl_fft                   1.0.4            py36h1e22a9b_1
mkl_random                1.0.1            py36h77b88f5_1
msys2-conda-epoch         20160418                      1
nbconvert                 5.3.1                    py36_0
nbformat                  4.4.0            py36h3a5bc1b_0
notebook                  5.6.0                    py36_0
numpy                     1.15.0           py36h9fa60d3_0
numpy-base                1.15.0           py36h4a99626_0
openssl                   1.0.2p               hfa6e2cd_0
pandas                    0.23.4           py36h830ac7b_0
pandoc                    2.2.1                h1a437c5_0
pandocfilters             1.4.2                    py36_1
parso                     0.3.1                    py36_0
patsy                     0.5.0                    py36_0
pickleshare               0.7.4            py36h9de030f_0
pip                       10.0.1                   py36_0
prometheus_client         0.3.1                    py36_0
prompt_toolkit            1.0.15           py36h60b8f86_0
pyasn1                    0.4.4                    py36_0
pyasn1-modules            0.2.2                    py36_0
pycparser                 2.18                     py36_1
pygments                  2.2.0            py36hb010967_0
pygpu                     0.7.6            py36h452e1ab_0
pyhamcrest                1.9.0                      py_2    conda-forge
pymc3                     3.5                       <pip>
pyopenssl                 18.0.0                   py36_0
pyparsing                 2.2.0                    py36_1
pyqt                      5.9.2            py36ha878b3d_0
python                    3.6.6                hea74fb7_0
python-dateutil           2.7.3                    py36_0
python-graphviz           0.8.4                    py36_1
pytz                      2018.5                   py36_0
pywin32                   223              py36hfa6e2cd_1
pywinpty                  0.5.4                    py36_0
pyzmq                     17.1.2           py36hfa6e2cd_0
qt                        5.9.6            vc14h62aca36_0
qtconsole                 4.4.0                    py36_0
scipy                     1.1.0            py36h672f292_0
seaborn                   0.9.0                    py36_0
send2trash                1.5.0                    py36_0
service_identity          17.0.0           py36h28b3542_0
setuptools                40.0.0                   py36_0
simplegeneric             0.8.1                    py36_2
sip                       4.19.8           py36h6538335_0
six                       1.11.0                   py36_1
sqlite                    3.24.0               h7602738_0
statsmodels               0.9.0            py36h452e1ab_0
terminado                 0.8.1                    py36_1
testpath                  0.3.1            py36h2698cfe_0
theano                    1.0.2            py36he980bc4_0
tornado                   5.1              py36hfa6e2cd_0
tqdm                      4.24.0                   py36_0
traitlets                 4.3.2            py36h096827d_0
twisted                   18.7.0           py36hfa6e2cd_1
vc                        14.1                 h0510ff6_3
vs2015_runtime            15.5.2                        3
wcwidth                   0.1.7            py36h3d5aa90_0
webencodings              0.5.1                    py36_1
wheel                     0.31.1                   py36_0
widgetsnbextension        3.4.0                    py36_0
wincertstore              0.2              py36h7fe50ca_0
winpty                    0.4.3                         4
zeromq                    4.2.5                he025d50_1
zlib                      1.2.11               h8395fce_2
zope                      1.0                      py36_0
zope.interface            4.5.0            py36hfa6e2cd_0
@JackCaster JackCaster changed the title model_to_graphviz display incomplete graph model_to_graphviz displays incomplete graph Aug 22, 2018
@twiecki
Copy link
Member

twiecki commented Aug 22, 2018

Seems like a problem with tracing the nodes through Determinsitics.

@ColCarroll
Copy link
Member

Funny! Should be able to take a look at it this week. Deterministics are hard to "see" when tracing the graph.

In the mean time, the function does return a graphviz graph, so you can add the connections manually. I'll post that snippet when I start looking if it is easy.

@ColCarroll
Copy link
Member

well, this is funny for any number of reasons:

image

@junpenglao
Copy link
Member

Well, it's not wrong about that link.

@twiecki
Copy link
Member

twiecki commented Sep 4, 2018

Should be fixed by #3170. Reopen if not.

@twiecki twiecki closed this as completed Sep 4, 2018
@twiecki
Copy link
Member

twiecki commented Sep 4, 2018

Looking at it again I might be wrong. @ColCarroll?

@ColCarroll
Copy link
Member

@JackCaster 's example is still a bug:

mu_real = 0.87
phi_real = 10

n_samples = 500

alpha_real = mu_real * phi_real
beta_real = (1-mu_real) * phi_real
Y = np.random.beta(a=alpha_real, b=beta_real, size=n_samples)

with pm.Model() as model:
    
    # Prior on 'mu'
    mu = pm.Beta('mu', alpha=1, beta=1)
    
    # Prior on 'phi'
    phi = pm.HalfNormal('phi', sd=25)
    
    # Parametrize in terms of a, b
    alpha = pm.Deterministic('alpha', mu*phi)
    beta = pm.Deterministic('beta', (1-mu)*phi)
    
    #alpha = pm.HalfNormal('alpha', sd=25)
    #beta = pm.HalfNormal('beta', sd=25)    
    
    # Likelihood
    likelihood = pm.Beta('likelihood', alpha=alpha, beta=beta, observed=Y)

pm.model_to_graphviz(model)

image

My example is a lot better than previously, but still draws extra lines.

with pm.Model() as model:
    w = pm.Normal('w')
    x = pm.Deterministic('x', w)
    y = pm.Deterministic('y', x)
    u = pm.Deterministic('u', y)
    z = pm.Normal('z', u)
pm.model_to_graphviz(model)

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants