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

Inconsistent behavior of query method in Variable Elimination #683

Open
ankurankan opened this issue May 4, 2016 · 4 comments · May be fixed by #932
Open

Inconsistent behavior of query method in Variable Elimination #683

ankurankan opened this issue May 4, 2016 · 4 comments · May be fixed by #932
Projects
Milestone

Comments

@ankurankan
Copy link
Member

from pgmpy.inference import VariableElimination
from pgmpy.models import BayesianModel
import numpy as np
import pandas as pd
 values = pd.DataFrame(np.random.randint(low=0, high=2, size=(1000, 5)),
                      columns=['A', 'B', 'C', 'D', 'E'])
model = BayesianModel([('A', 'B'), ('C', 'B'), ('C', 'D'), ('B', 'E')])
model.fit(values)
inference = VariableElimination(model)

inference.query(variables=None)
Out[5]: 
{<Factor representing phi(D:2, C:2) at 0x7f2c3a07abe0>,
 <Factor representing phi(B:2, A:2, C:2) at 0x7f2c3a07ae48>,
 <Factor representing phi(A:2) at 0x7f2c3a07af98>,
 <Factor representing phi(C:2) at 0x7f2c3a07ab00>,
 <Factor representing phi(E:2, B:2) at 0x7f2c3a07af60>}

inference.query(variables=['A'])
Out[6]: {'A': <Factor representing phi(A:2) at 0x7f2c58718400>}

Returns a set when variables is None. Otherwise returns a dict.

@yashu-seth
Copy link
Member

@ankurankan What do you think should be the expected behavior? Shouldn't this return an empty dict for no variables specified?

@khalibartan
Copy link
Member

@ankurankan Yes, I agree with @yashu-seth . it should return an empty dictionary, because in case of variables not being an empty list we return marginal distrbution w.r.t that variable, so makes much sense to return a empty dict

@ankurankan ankurankan modified the milestone: Release 0.1.3 Sep 6, 2016
@ankurankan ankurankan added this to Urgent in GSoC 2018 Sep 28, 2017
@lohani2280
Copy link
Contributor

lohani2280 commented Oct 31, 2017

@ankurankan I also agree that it should return an empty dict when no variables specified .I want to work on this issue . What is your views on this?

@ankurankan
Copy link
Member Author

@lohani2280 Please go ahead. Should be a simple fix.

lohani2280 added a commit to lohani2280/pgmpy that referenced this issue Nov 5, 2017
…tion

Now the query method returns an empty dict for no variables specified
closes pgmpy#683
lohani2280 added a commit to lohani2280/pgmpy that referenced this issue Nov 6, 2017
…tion

Now the query method returns an empty dict for no variables specified
closes pgmpy#683
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
4 participants