- Join over
**1.5M+ people** - Join over
**100K+ communities** - Free
**without limits** - Create
**your own community**

- Sep 17 06:25basavarajuise commented #881
- Sep 16 09:33ankurankan commented #881
- Sep 16 09:09basavarajuise commented #881
- Sep 15 07:39ankurankan milestoned #1322
- Sep 15 07:39ankurankan commented #1322
- Sep 15 07:38ankurankan labeled #1322
- Sep 15 06:41ankurankan closed #1323
- Sep 15 06:41ankurankan commented #1323
- Sep 15 05:49ysgncss opened #1323
- Sep 07 17:30nalanishada commented #1321
- Sep 07 13:42MrYu001 commented #1322
- Sep 07 12:57ankurankan edited #1322
- Sep 07 12:57ankurankan closed #1321
- Sep 07 12:57ankurankan commented #1321
- Sep 07 12:49MrYu001 opened #1322
- Sep 07 10:54nalanishada opened #1321
- Aug 28 12:26ankurankan commented #1320
- Aug 28 12:26ankurankan closed #1320
- Aug 28 12:26ankurankan commented #1320
- Aug 28 12:24ankurankan edited #1320

@StefanRiess Depends on what kind of final structure you are looking for. For a generalized structure learning, I don't think there is any way to specify a root node in case of PC or HillClimb algorithms. But in the case of HillClimb you can specify a list of whitelist and blacklist nodes, using which you can force the direction of the edges to be always outwards from a given root node. If you are looking to learn a tree structure, you can easily specify a root node: http://pgmpy.org/estimators.html#tree-search

@ankurankan Hi, I would like to ask a favor about Bayesian theorem, sorry that maybe it does not relate directly to the pgmpy. However, I hope further to implement the network through pgmpy. Is it possible to calculate the posterior probability by the entire factor (random variable) instead of event? For example, there are 2 related factors; A and B, which are continuous data. So, how can I calculate the probability of P(A|B)? I found the way to use the normal dist which calculate from the μ and σ^2. But the result will show the probability of μ and σ^2 given by data, P(μ, σ^2|data) which refer to the posterior of only one variable. Please kindly give me any suggestion, thank you in advanced.

@KittyNatty I am sorry but I don't understand the question. Are you looking to compute the posterior of both the variables? In that case, to compute the joint posterior P(A, B | data), you can simply start with priors for 4 parameters ($ \mu_A $, $ \mu_B $, $ \sigma_A $, $ \sigma_B $) instead of two, and then can compute the posterior for all these parameters. You should also be able to encode your relational assumptions in the likelihood function. If you are just looking for the conditional distributions, P(A|B), you will get a single \mu and \sigma but they will be functions of B (if you assume some kind of relation between them). Have a look at this: https://en.wikipedia.org/wiki/Multivariate_normal_distribution#Conditional_distributions

I am using HillClimbing with BIC Scoring

@arghyakusumdas6163 Hi, have a look at the example notebook: https://github.com/pgmpy/pgmpy/blob/dev/examples/Structure%20Learning%20in%20Bayesian%20Networks.ipynb

Let me look at it

ImportError: cannot import name 'get_example_model'

I not sure

Is there any way how I can create a model quickly

The get example method fetches the model from https://www.bnlearn.com/bnrepository/ and uses the readwrite.BIFReader to create the model. So, you can try to do it manually. Or you can also look at the example notebooks for manually creating models

Can I start with any arbitrary model?

Sorry for asking so many question. I am actually in the process of benchmarking many Baysian structure learning tools

So, Just needed to know the mose efficient way to do it in here

I don't think you will need to define a model if you are just looking for doing structure learning. You can directly give the data to HillClimb. If you are looking to simulate data as well, you will need to add parameterization to the model structure as well. Here's a complete example: https://github.com/pgmpy/pgmpy/blob/dev/examples/Creating%20a%20Discrete%20Bayesian%20Network.ipynb

Assuming everything has a binary outcome

makes sense.....

But max_degree needed to set to 1

I have another question: Is there any function so that I can pass a graph structure and get the overall score of that?

model = BayesianModel([('A', 'C'), ('B', 'C')])

data = pd.DataFrame(data={'A': ['a1', 'a1', 'a2'],

'B': ['b1', 'b2', 'b1'],

'C': ['c1', 'c1', 'c2']})

data = pd.DataFrame(data={'A': ['a1', 'a1', 'a2'],

'B': ['b1', 'b2', 'b1'],

'C': ['c1', 'c1', 'c2']})

Copied the code from your example

@arghyakusumdas6163 Yes, you can use the

`BicScore.score`

method. Have a look at the this example: https://github.com/pgmpy/pgmpy/blob/dev/pgmpy/estimators/StructureScore.py#L59
`cpd_a = estimator.estimate_cpd('A', prior_type="dirichlet", pseudo_counts=[[1], [3]])`

This only seem to work is I have actually observed two values for A in the data.. Could someone please help me to work this out?

@felixleopoldo If I am understanding this correctly, you have a dataset which doesn't have both the states for

`A`

in it? In that case, you can pass a `state_names`

argument while initializing the `BayesianEstimator`

and it will fall back to computing CPD sizes using that. The `state_names`

should be a dict of type `{var1: [state1, state2, ..], var2: [...] }`

. Here's an example:```
In [21]: df = pd.DataFrame(np.ones((5, 2), dtype='int'), columns=['A', 'B'])
In [22]: model = BayesianModel([('A', 'B')])
In [23]: est = BayesianEstimator(model, data=data, state_names={'A': [0, 1]})
In [24]: est.estimate_cpd('A', prior_type='dirichlet', pseudo_counts=[[1], [3]])
Out[24]: <TabularCPD representing P(A:2) at 0x7f51955d92b0>
In [25]: print(est)
<pgmpy.estimators.BayesianEstimator.BayesianEstimator object at 0x7f5194f34b50>
In [26]: print(__)
+------+----------+
| A(0) | 0.111111 |
+------+----------+
| A(1) | 0.888889 |
+------+----------+
```

thanks! thats what I needed