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

what sampling method does approximate inference class use? #1726

Open hjyoon93 opened 8 months ago

hjyoon93 commented 8 months ago

Inside approximate inference using sampling class,

there is this "query" function as below.

query(variables, n_samples=10000, samples=None, evidence=None, virtual_evidence=None, joint=True, state_names=None, show_progress=True, seed=None)

If I sample using "n_samples=100", what sampling method does it use to sample 100 samples?

Is it forward sampling, rejection sampling or likelihood weighted sampling?

And If I use query method to do sampling, does it sample based on evidence I give?

ankurankan commented 8 months ago

@hjyoon93 When no evidence is provided, it does a forward sampling. When evidence is provided, it does a rejection sampling till the specified number of samples are generated that satisfy the given evidence.