pgmpy / pgmpy_notebook

Short Tutorial to Probabilistic Graphical Models(PGM) and pgmpy
http://pgmpy.org/
MIT License
371 stars 212 forks source link

Cannot import name 'Factor' from 'pgmpy.factors' #56

Closed MeghaNarjary closed 1 year ago

ankurankan commented 1 year ago

@MeghaNarjary Could you share what code you are running exactly to get that error? Ideally, it should be from pgmpy.factors.discrete import DiscreteFactor

MeghaNarjary commented 1 year ago

from pgmpy.models import MarkovNetwork from pgmpy.factors import Factor import numpy as np model = MarkovNetwork([('A','B'),('B','C'), ('C','D'),('D','A')]) factor_a_b = Factor(variables=['A', 'B'], cardinality=[2, 2], value=np.random.rand(4)) # The numpy.random.rand() function creates

an array of specified shape and fills it with random values

factor_b_c = Factor(variables=['B', 'C'], cardinality=[2, 2], value=np.random.rand(4)) factor_c_d = Factor(variables=['C', 'D'], cardinality=[2, 2], value=np.random.rand(4)) factor_d_a = Factor(variables=['D', 'A'], cardinality=[2, 2], value=np.random.rand(4)) model.add_factors(factor_a_b, factor_b_c, factor_c_d, factor_d_a) model.get_factors()

here I get an error that 'Factor' cannot import from 'pgmpy.factors' and also I try with 'DiscreteFactor' ......and 'DiscreteFactor' also gives me the same kind of error

ankurankan commented 1 year ago

Sorry for the late reply. Factor isn't a class in pgmpy, maybe you want to use DiscreteFactor. And it can be imported using: from pgmpy.factors.discrete import DiscreteFactor