causalnex
causalnex copied to clipboard
InferenceEngine on infinite loop after creating latent variable
Description
I am working on the creation of a model to predict fire occurrences.
I generated this graph:
and extracted the CPDs from it. Then initiating the InferenceEngine works fine.
Then, I tried to introduce a latent variable, run the latent CPDs calculation and re-create the InferenceEngine but it keeps running forever which makes me suspect an infinite loop like what was previously reported in a similar ticket.
Context
I wanted to perform a
Steps to Reproduce
- Add node to network
bn.add_node(
node="high_number_of_people_prone_to_inattention",
edges_to_add=[
("high_number_of_people_with_not_enough_sleep", "high_number_of_people_prone_to_inattention"),
("high_number_of_single_parents", "high_number_of_people_prone_to_inattention"),
("high_number_of_people_with_disabilities", "high_number_of_people_prone_to_inattention"),
("high_number_of_elderly_people_75plus", "high_number_of_people_prone_to_inattention"),
("high_number_of_people_prone_to_inattention", "fire_density")
],
edges_to_remove=[],
)
- Set boundaries
from causalnex.estimator.em import EMSingleLatentVariable
boundaries_inat = EMSingleLatentVariable.get_default_box(
sm=bn.structure,
node_states={
**bn.node_states,
'high_number_of_people_prone_to_inattention': {0, 1}
},
lv_name='high_number_of_people_prone_to_inattention'
)
boundaries_inat['fire_density'][1].loc[1 ,0] = .8
- Fit latent CPDs
bn = bn.fit_latent_cpds(
lv_name="high_number_of_people_prone_to_inattention",
lv_states=[0, 1],
data=full_training_sample,
box_constraints=boundaries_inat,
n_runs=30,)
- Try to generate InferenceEngine
from causalnex.inference import InferenceEngine
ie = InferenceEngine(bn)
Expected Result
Should generate InferenceEngine object
Actual Result
Runs forever
Your Environment
Include as many relevant details about the environment in which you experienced the bug:
- CausalNex version used (
pip show causalnex
): Version: 0.11.0 - Python version used (
python -V
): 3.8.7 - Operating system and version: Mac OS Big Sur 11.6.7