PyBNesian icon indicating copy to clipboard operation
PyBNesian copied to clipboard

DiscreteFactor parameter access

Open carloslihu opened this issue 3 years ago • 2 comments

Brief Context

Hello, I find your library an excellent tool for Bayesian network research. I'm currently trying to work with hybrid Bayesian networks (Discrete and Gaussian CPDs). In your library I have identified this as the CLGNetworkType.

Request

The issue is that I can't find in the documentation how to access the parameters (probabilities) in the Conditional Probability Table (CPT) of a DiscreteFactor.

I have seen it is possible with continuous factors (e.g., beta, variance). But I would like to know if it's possible with the discrete ones.

Thank you very much.

carloslihu avatar Jun 14 '22 07:06 carloslihu

Hello Carlos,

for now, the easiest way to access the CPT is through the DiscreteFactor.logl() function.

I could provide alternative ways to access that info but I am not sure what is the best format to return it (probably, a multidimensional array?). Feel free to make any suggestions.

Regards.

davenza avatar Oct 23 '22 14:10 davenza

Hi David,

Thank you very much for the quick workaround. It is very helpful. Regarding the best CPT output format, I know it's not trivial. However I can give you some ideas:

  • One of the problems I find is knowing the possible variable values. For instance, suppose we have a random variable A = {a1, a2}. I think that having a function returning a list with its possible values e.g., returning [a1, a2].

  • On the other hand, we have the problem of outputting the CPT probabilities in an intuitive way. I think that the best way is with a Pandas Multiindex Dataframe (https://pandas.pydata.org/pandas-docs/stable/user_guide/advanced.html). To help you understand my idea, I have attached a Jupyter Notebook with a simple example:

CPT_output.zip

carloslihu avatar Oct 25 '22 15:10 carloslihu