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

'ContinuousFactor' object has no attribute 'variables' #1755

Open
ilincaburdulea opened this issue May 3, 2024 · 1 comment
Open

'ContinuousFactor' object has no attribute 'variables' #1755

ilincaburdulea opened this issue May 3, 2024 · 1 comment

Comments

@ilincaburdulea
Copy link

ilincaburdulea commented May 3, 2024

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

  • 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)

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'

@ankurankan
Copy link
Member

@ilincaburdulea Sorry for the late reply. Unfortunately, continuous factors aren't supported fully yet, and I would suggest not using them at the moment.

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