Closed MeghaNarjary closed 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
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
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
@MeghaNarjary Could you share what code you are running exactly to get that error? Ideally, it should be
from pgmpy.factors.discrete import DiscreteFactor