bd2kccd / py-causal

Other
204 stars 50 forks source link

BIC score for a graph, given data #107

Open kollibylecoffee opened 2 years ago

kollibylecoffee commented 2 years ago

Hi,

I'm trying to get a BIC score on a graph given data but most of the time, print('Graph BIC: {}'.format(graph.getAttribute('BIC'))), returns None. I saw the thread about FCI algm returning None if graph returned was a PAG, but thought it was fixed? On another note, is it possible to get a BIC score on any graph (not just one that was learned), given data? Such as in: http://bnlearn.com/examples/score/

Thanks!

jdramsey commented 2 years ago

You know, I was just trying to figure out how to implement that in Tetrad. Obviously in the code it's easy. I'm not sure about pycausal, but I should be able to solve it in Tetrad if I can figure out how.

jdramsey commented 2 years ago

Oh wait, I should ask, what types of graphs are you trying to print the BIC of? I recently went through my own code and added BIC attributes to all CPDAG search models. PAG models shouldn't get them.

kollibylecoffee commented 2 years ago

Thank you for your reply! I have a regular DAG (based on some prior temporal knowledge and forbidden edges) and I wanted to score it based on the data. When you say, "Obviously in the code it's easy. I'm not sure about pycausal," is it correct to assume that the code you are talking about in the java code. Thanks again!

jdramsey commented 2 years ago

Yeah it's in the Java code.....but maybe you can do it from pycausal..... I don't know how to use pycausal, sorry, but I can tell you want to do. The BIC score is in the FGES class--you make and FGES with a SEM BIC score with penalty 1, and then you call this function:P

public double scoreDag(Graph dag) {
    return scoreDag(dag, false);
}

That's the BIC score. Penalty 1 is important--that's standard BIC. Is this something you're able to do from pycausal?

jdramsey commented 2 years ago

It's possible that Kong exposed this function somewhere in the pycausal API. If he sees this, maybe he'll respond.