cmu-phil / tetrad

Repository for the Tetrad Project, www.phil.cmu.edu/tetrad.
GNU General Public License v2.0
402 stars 110 forks source link

Fges doesn't return DAG #379

Closed haluk closed 7 years ago

haluk commented 7 years ago

I have continuous data and I use the following code to get BN.

// structure learning double penaltyDiscount = 2.0; ICovarianceMatrix cov = new CovarianceMatrixOnTheFly(data); SemBicScore score = new SemBicScore(cov); score.setPenaltyDiscount(penaltyDiscount); Fges fges = new Fges(score); fges.setVerbose(false); fges.setNumPatternsToStore(0); fges.setOut(out); fges.setFaithfulnessAssumed(true); fges.setCycleBound(5); Graph estPattern = fges.search();

However, estPattern is not a DAG. What do I do wrong?

ccd-helpdesk commented 7 years ago

By design, the FGES algorithm outputs a “pattern” [Chickering, 2002] that containing arcs (->), which represent direct causation, and undirected edges (―), where such an edge indicates there is a causal arc, but its direction cannot be determined.

Each pattern encode different DAGs. For example, the A--B pattern, encodes the next DAGs
A->B, or B<-A.

So, in you case, once you get a pattern you can call another function to extract a DAG from it.

Take a look to the SearchGraphUtils class, and in there to the chooseDagInPattern method.

Otherwise you can try the java TETRAD GUI, where there is a process box that will do exactly that. It is the "Graph Manipulation Box", and in it you need to choose the "choose dag in pattern" option. First you open you pattern using the "Graph" box and then connect it to the "Graph Manipulation Box"

Let us know if this helps.

haluk commented 7 years ago

I tried BDeuScore and Fges algorithm for structure learning. I am able to get pattern out of it. However, I'm trying to export the BN in bifxml format. In order to have CPT values, I am trying to apply parameter learning as in the following:

BayesPm bn = new BayesPm(estPattern);
EmBayesEstimator estimator = new EmBayesEstimator(bn, data);

I had continuous data but I discretized it as follows:

public static DataSet discretize(DataSet data) {
    DataSet discrete = DataUtils.discretize(data, 2, false);

    return DataUtils.restrictToMeasured(discrete);
}

When I serialized the BN with BayesXmlRenderer I got "Not a directed edge" exception.

In order to get DAG in structure learning step, I tried "Lingam" algorithm as follows:

LingamPattern lingam = new LingamPattern(estPattern, data);
Graph learned = lingam.search();

However, I'm now receiving a "SingularMatrixException: matrix is singular".

What should I do now? Thanks.

ccd-helpdesk commented 7 years ago

Hi Haluk,

LiNGAM will only work on continuous data where the number of observations is much larger than the number of random variables. It also requires the assumption that the underlying model has linear relationships between the variables and non-Gaussian error terms. If those things aren't true of your dataset, you'll have to use a different search algorithm.

You could use FGES to learn a pattern, and then choose an arbitrary DAG in the pattern, and then fit that DAG to your data. To choose a DAG in the pattern, the SearchGraphUtils class has the following methods, I'm not sure which one you need but it'll be one of these:

I'm not familiar with bifxml format, unfortunately. I don't know whether Tetrad is able to export in that format.

On Fri, Jan 27, 2017 at 2:12 PM, Haluk Dogan notifications@github.com wrote:

I tried BDeuScore and Fges algorithm for structure learning. I am able to get pattern out of it. However, I'm trying to export the BN in bifxml format. In order to have CPT values, I am trying to apply parameter learning as in the following:

BayesPm bn = new BayesPm(estPattern); EmBayesEstimator estimator = new EmBayesEstimator(bn, data);

I had continuous data but I discretized it as follows:

public static DataSet discretize(DataSet data) { DataSet discrete = DataUtils.discretize(data, 2, false);

return DataUtils.restrictToMeasured(discrete);

}

When I serialized the BN with BayesXmlRenderer I got "Not a directed edge" exception.

In order to get DAG in structure learning step, I tried "Lingam" algorithm as follows:

LingamPattern lingam = new LingamPattern(estPattern, data); Graph learned = lingam.search();

However, I'm now receiving a "SingularMatrixException: matrix is singular".

What should I do now? Thanks.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/cmu-phil/tetrad/issues/379#issuecomment-275748416, or mute the thread https://github.com/notifications/unsubscribe-auth/AXWXj8eAoLmDu2JmxNa7uYpfN6zMc2d-ks5rWkGJgaJpZM4LvOpE .

jdramsey commented 7 years ago

The discussion seems to have stopped on this.