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

Incorrect graph using model_graph.py #3205

Closed
albu5 opened this issue Sep 18, 2018 · 2 comments
Closed

Incorrect graph using model_graph.py #3205

albu5 opened this issue Sep 18, 2018 · 2 comments

Comments

@albu5
Copy link

albu5 commented Sep 18, 2018

Description of your problem

in pymc3/model_graph.py
_inputs method doesn't seem to give correct set of inputs for some var and func, resulting in incomplete graph

def _inputs(self, var, func, blockers=None):
"""Get inputs to a function that are also named PyMC3 variables"""
return set([j for j in inputs([func], blockers=blockers) if j in self.var_list and j != var])

Sample script I'm running to reproduce weird behavior

from pymc3 import Model
from pymc3 import Bernoulli, Uniform
from theano import shared
import numpy as np
import pymc3 as pm

n_samples = 1000
x1_samples = np.random.uniform(size=(n_samples,)) > 0.4
x2_samples = np.random.uniform(size=(n_samples,)) > 0.6
noise_sample = np.random.uniform(size=(n_samples,)) > 0.9
noisy_and_samples = x1_samples * x2_samples
noisy_and_samples[noise_sample] = 1 - noisy_and_samples[noise_sample]

x1_samples_shared = shared(x1_samples.astype(np.int))
x2_samples_shared = shared(x2_samples.astype(np.int))
noisy_and_samples_shared = shared(noisy_and_samples.astype(np.int))

with Model() as noisy_and:
# inputs node factors
x1_prob = Uniform(name='x1_prob')
x2_prob = Uniform(name='x2_prob')
x1_node = Bernoulli(name='x1_node', p=x1_prob, observed=x1_samples)
x2_node = Bernoulli(name='x2_node', p=x2_prob, observed=x2_samples)
and_res = pm.Uniform('and_res', lower=x1_node * x2_node - 1e-3, upper=x1_node * x2_node + 1e-3, shape=(n_samples,),
transform=None)
noise_prob = Uniform(name='noise_prob')
noisy_and_node = Bernoulli(name='noisy_and_node',
p=and_res * (1 - noise_prob) + (1 - and_res) * noise_prob,
observed=noisy_and_samples)

dag = pm.model_to_graphviz(noisy_and)
dag.render('cond_gauss', view=True)

Detailed Description

node "and_res" has two parents - "x1_node" and "x2_node" but the corresponding edges are absent in the graph generated.

Versions and main components

  • PyMC3 Version: 3.5
  • Theano Version: 1.0.2
  • Python Version: 3.5
  • Operating system: Windows 7
  • How did you install PyMC3: (conda/pip) pip
@ColCarroll
Copy link
Member

Shoot - related to #3165, I started looking at this, but have not made much progress. It is back on the top of the pile, though. (I am closing this in favor of the other issue, but still paying attention)

@albu5
Copy link
Author

albu5 commented Sep 19, 2018

if j in self.var_list and j != var
Why are we comparing var when we can compare var.name
something like:
j.name in [node.name for node in self.var_list] and j.name != var.name

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

No branches or pull requests

2 participants