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

Parameterizing with Continuous Variables Code Error #25

Open
ghost opened this issue May 29, 2018 · 4 comments
Open

Parameterizing with Continuous Variables Code Error #25

ghost opened this issue May 29, 2018 · 4 comments

Comments

@ghost
Copy link

ghost commented May 29, 2018

In the Linear Gaussian CPD chapter,when using LinearGaussianBayesianNetwork ,there have following codes:

cpd1.variables = [*cpd1.evidence, cpd1.variable]
cpd2.variables = [*cpd2.evidence, cpd2.variable]
cpd3.variables = [*cpd3.evidence, cpd3.variable]
However,it caused syntax error and can't run it . So I changed it to

cpd1.variables = ["".join(cpd1.evidence), cpd1.variable]
cpd2.variables = ["".join(cpd2.evidence), cpd2.variable]
cpd3.variables = ["".join(cpd3.evidence), cpd3.variable]

But "ValueError: ('CPD defined on variable not in the model', <pgmpy.factors.continuous.LinearGaussianCPD.LinearGaussianCPD object at 0x000000000AFECA58>)"
occured.I don't kown what to do .By the way, I‘m in Python2 Enviroment,

@yashu-seth
Copy link
Member

yashu-seth commented Jun 2, 2018

@RockLeeStudio
However,it caused syntax error and can't run it . So I changed it to
Please share the syntax error that you got in this case.

@ghost
Copy link
Author

ghost commented Jun 4, 2018

@yashu-seth It's a grammatical problem,* not defined. I'm using Anaconda python 2 environment.
I actually have no idea of * means there , what I know is it can be used in function parameters.

@yashu-seth
Copy link
Member

@RockLeeStudio It would help if you can share the complete example along with the error you got.

@essie-chiang
Copy link

I run in to this issue, too!
6. Parameterizing with Continuous Variables
code:
from pgmpy.models import LinearGaussianBayesianNetwork

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'])

This is a hack due to a bug in pgmpy (LinearGaussianCPD

doesn't have variables attribute but add_cpds function

wants to check that...)

cpd1.variables = [*cpd1.evidence, cpd1.variable]
cpd2.variables = [*cpd2.evidence, cpd2.variable]
cpd3.variables = [*cpd3.evidence, cpd3.variable]
model.add_cpds(cpd1, cpd2, cpd3)
jgd = model.to_joint_gaussian()
jgd.variables

File "", line 10
cpd1.variables = [*cpd1.evidence, cpd1.variable]
^
SyntaxError: invalid syntax

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