pgmpy / pgmpy

Python Library for learning (Structure and Parameter), inference (Probabilistic and Causal), and simulations in Bayesian Networks.
https://pgmpy.org/
MIT License
2.73k stars 716 forks source link

When using ApproxInference for reasoning, I keep getting these warnings in a loop #1858

Open DaftofHS opened 1 week ago

DaftofHS commented 1 week ago

Subject of the issue

Describe your issue here. using ApproxInference for reasoning, I keep getting these warnings in a loop: WARNING:pgmpy:Probability values don't exactly sum to 1. Differ by: 0.000244140625. Adjusting values. This happens repeatedly with various differences, such as -0.000244140625, 0.0001220703125, and so on. How can I fix this precision issue? Is there a way to ignore precision problems?"

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. I am working with a dataset that has 18 parameters with 8 operating conditions, where each parameter has 2 states. run with ApproxInference and note any warnings about probability sums.

Expected behaviour

Tell us what should happen query-result

Actual behaviour

Tell us what happens instead WARNING:pgmpy:Probability values don't exactly sum to 1. Differ by: 6.103515625e-05. Adjusting values. WARNING:pgmpy:Probability values don't exactly sum to 1. Differ by: 6.103515625e-05. Adjusting values. WARNING:pgmpy:Probability values don't exactly sum to 1. Differ by: -6.103515625e-05. Adjusting values. WARNING:pgmpy:Probability values don't exactly sum to 1. Differ by: 0.000244140625. Adjusting values. WARNING:pgmpy:Probability values don't exactly sum to 1. Differ by: -0.000244140625. Adjusting values. WARNING:pgmpy:Probability values don't exactly sum to 1. Differ by: 0.0001220703125. Adjusting values.

ankurankan commented 1 week ago

@DaftofHS You can change the logging level to control which logging messages get shown. You can silence the warnings by running:

In [4]: from pgmpy.global_vars import logger

In [5]: import logging

In [6]: logger.setLevel(logging.ERROR)
DaftofHS commented 6 days ago

Hello, when I was running, it did not have the output result, but continued to be adjusted in a few numbers (in infinite cycle). Although these code did not display the cycle, it seemed to be constantly looping inside. There is no output result!

ankurankan commented 6 days ago

@DaftofHS The approximate inference in pgmpy is based on sampling. This can be quite slow if you generate a lot of samples. You can control between precision of the results and runtime by varying the n_samples parameter of the query method. If it's possible for you to share your code, I might be able to help better.

DaftofHS commented 6 days ago

test241101.zip Hello, the file has been imported, and the adjustment data that has been circulating when using approximate inferences

DaftofHS commented 3 days ago

Hello, I think I know why it keeps looping. In the query function, simulate is used to simulate the sample. In the sample, multiple faults will be simulated to occur at the same time (that is, the status of multiple faults is 1). However, in my data, only one fault will occur individually (in a sample, only one fault will be 1). This should be the case. But how can I modify it? I don't know yet.