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

Example in LinearGaussianBayesianNetwork.add_cpds doesn't work #971

Closed
chaonan99 opened this issue Jan 26, 2018 · 1 comment
Closed

Example in LinearGaussianBayesianNetwork.add_cpds doesn't work #971

chaonan99 opened this issue Jan 26, 2018 · 1 comment

Comments

@chaonan99
Copy link

chaonan99 commented Jan 26, 2018

Subject of the issue

Example code in the docstring of LinearGaussianBayesianNetwork.add_cpds doesn't work.

Your environment

  • pgmpy version: 0.1.6
  • Python version: 3.6
  • Operating System: Ubuntu 14.04

Steps to reproduce

    Examples
    --------
    >>> from pgmpy.models import LinearGaussianBayesianNetwork
    >>> from pgmpy.factors.continuous import LinearGaussianCPD
    >>> model = LinearGaussianBayesianNetwork([('x1', 'x2'), ('x2', 'x3')])
    >>> cpd1 = LinearGaussianCPD('x1', [1], 4)
    >>> cpd2 = LinearGaussianCPD('x2', [-5, 0.5], 4, ['x1'])
    >>> cpd3 = LinearGaussianCPD('x3', [4, -1], 3, ['x2'])
    >>> model.add_cpds(cpd1, cpd2, cpd3)
    >>> for cpd in model.cpds:
            print(cpd)

This cause error AttributeError: 'LinearGaussianCPD' object has no attribute 'variables', which is obviously caused by missing attribute in LinearGaussianCPD. A simple solution is to add a property

@property
def variables(self):
    return [*self.evidence, self.variable]
@chaonan99
Copy link
Author

Actually the same issue with #961

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

1 participant