Parameterizing with Continuous Variables Code Error
Opened this issue · 4 comments
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,
@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.
@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.
@RockLeeStudio It would help if you can share the complete example along with the error you got.
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