You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to set up a simple graph structure of 2 nodes (x and y) and 3 factors: f_x, f_y, f_x_y. The probability distribution functions I used for now are not relevant, I wanted to have a working toy example using pgmpy first and then I'll adapt my whole problem statement. However I have problems with using the function add_factors, because I get an Attribute error. Does anybody have any advice? It might be that I'm doing something wrong.
Your environment
pgmpy version 0.1.25
Python version 3.10
Operating System
Steps to reproduce
Tell us how to reproduce this issue. Please provide a minimal reproducible code of
the issue you are facing if possible.
import numpy as np
from pgmpy.models import FactorGraph
from pgmpy.factors.continuous import ContinuousFactor
np.random.seed(0)
num_points = 30
x = np.linspace(0, 10, num_points)
y = x + np.random.normal(0, 0.5, num_points)
@ilincaburdulea Sorry for the late reply. Unfortunately, continuous factors aren't supported fully yet, and I would suggest not using them at the moment.
Subject of the issue
I am trying to set up a simple graph structure of 2 nodes (x and y) and 3 factors: f_x, f_y, f_x_y. The probability distribution functions I used for now are not relevant, I wanted to have a working toy example using pgmpy first and then I'll adapt my whole problem statement. However I have problems with using the function add_factors, because I get an Attribute error. Does anybody have any advice? It might be that I'm doing something wrong.
Your environment
Steps to reproduce
Tell us how to reproduce this issue. Please provide a minimal reproducible code of
the issue you are facing if possible.
import numpy as np
from pgmpy.models import FactorGraph
from pgmpy.factors.continuous import ContinuousFactor
np.random.seed(0)
num_points = 30
x = np.linspace(0, 10, num_points)
y = x + np.random.normal(0, 0.5, num_points)
fg = FactorGraph()
def pdf_2d(x,y):
return np.exp(-((y - x) ** 2) / (2 * 0.5))
def pdf_1d(x):
mean = 0
variance = 2
return np.exp(-((x - mean) ** 2) / (2 * variance)) / np.sqrt(2 * np.pi * variance)
factor_x_y = ContinuousFactor(variables = ['x', 'y'], pdf = pdf_2d)
fg.add_nodes_from(['x', 'y'])
fg.add_edges_from([('x', factor_x_y), ('y', factor_x_y)])
fg.add_factors(factor_x_y)
Expected behaviour
Tell us what should happen
add_factors should work so I can continue with belief propagation
Actual behaviour
AttributeError: 'ContinuousFactor' object has no attribute 'variables'
The text was updated successfully, but these errors were encountered: