-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Draft]: Calculate local markov blanket against true graph for parted nodes that passed AD Test #1757
Draft
vbcwonderland
wants to merge
6
commits into
development
Choose a base branch
from
vbc-04-07
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+189
−22
Draft
[Draft]: Calculate local markov blanket against true graph for parted nodes that passed AD Test #1757
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0fe7866
partite all nodes into pass or not pass the AndersonDarling Test
vbcwonderland 3443c1d
get markov banket for each node and calculate against true graph for …
vbcwonderland 2355c6a
Accepts and Recalls with process prints
vbcwonderland d3db254
nit
vbcwonderland e7ea86f
nit fix imports
vbcwonderland 49c96b0
MB part done
vbcwonderland File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
import edu.cmu.tetrad.graph.GraphUtils; | ||
import edu.cmu.tetrad.graph.IndependenceFact; | ||
import edu.cmu.tetrad.graph.Node; | ||
import edu.cmu.tetrad.graph.Edge; | ||
import edu.cmu.tetrad.search.test.*; | ||
import edu.cmu.tetrad.util.SublistGenerator; | ||
import edu.cmu.tetrad.util.TetradLogger; | ||
|
@@ -251,6 +252,62 @@ public Double checkAgainstAndersonDarlingTest(List<Double> pValues) { | |
return generalAndersonDarlingTest.getP(); | ||
} | ||
|
||
public List<List<Node>> getAndersonDarlingTestAcceptsRejectsNodesForAllNodes(IndependenceTest independenceTest, Graph graph, Double threshold) { | ||
// when calling, default reject null as <=0.05 | ||
List<List<Node>> accepts_rejects = new ArrayList<>(); | ||
List<Node> accepts = new ArrayList<>(); | ||
List<Node> rejects = new ArrayList<>(); | ||
List<Node> allNodes = graph.getNodes(); | ||
for (Node x : allNodes) { | ||
List<IndependenceFact> localIndependenceFacts = getLocalIndependenceFacts(x); | ||
List<Double> localPValues = getLocalPValues(independenceTest, localIndependenceFacts); | ||
Double ADTest = checkAgainstAndersonDarlingTest(localPValues); | ||
if (ADTest <= threshold) { | ||
rejects.add(x); | ||
} else { | ||
accepts.add(x); | ||
} | ||
} | ||
accepts_rejects.add(accepts); | ||
accepts_rejects.add(rejects); | ||
return accepts_rejects; | ||
} | ||
|
||
public Double getPrecisionOrRecallOnMarkovBlanketGraph(Node x, Graph estimatedGraph, Graph trueGraph, boolean getPrecision) { | ||
List<Node> singleNode = Arrays.asList(x); | ||
// Lookup graph is the same structure as trueGraph's structure but node objects replaced by estimated graph nodes. | ||
Graph lookupGraph = GraphUtils.replaceNodes(trueGraph, estimatedGraph.getNodes()); | ||
|
||
// TODO VBC use the recurssion method | ||
Graph xMBLookupGraph = GraphUtils.trimGraph(singleNode, lookupGraph, 3); | ||
Set<Edge> xMBLookupGraphEdges = xMBLookupGraph.getEdges(); | ||
System.out.println("@@@@@@@@@@@@@@@@"); | ||
System.out.println("True Graph:" + trueGraph); | ||
System.out.println("LookupGraph:" + lookupGraph); // this print should be the same as the true graph | ||
|
||
System.out.println("xMBLookupGraphEdges size: " + xMBLookupGraphEdges.size()); | ||
System.out.println("xMBLookupGraph Nodes size: " + xMBLookupGraph.getNodes().size()); | ||
System.out.println("xMBLookupGraph:" + xMBLookupGraph); // The MB trim of the lookup graph, so it should be a subset of the lookup graph print | ||
|
||
// Get Markov Blanket Subgraph for this node x. | ||
Graph xMBEstimatedGraph = GraphUtils.trimGraph(singleNode, estimatedGraph, 3); | ||
Set<Edge> xMBEstimatedGraphEdges = xMBEstimatedGraph.getEdges(); | ||
System.out.println("xMBEstimatedGraphEdges size: " + xMBEstimatedGraphEdges.size()); | ||
System.out.println("xMBEstimatedGraph Nodes size: " + xMBEstimatedGraph.getNodes().size()); | ||
System.out.println("xMBEstimatedGraph:" + xMBEstimatedGraph); // This should be compared with the xMBLookupGraph | ||
System.out.println("@@@@@@@@@@@@@@@@"); | ||
|
||
HashSet<Edge> truePositive = new HashSet<>(xMBEstimatedGraphEdges); | ||
// TODO VBC: QUESTION FOr DISCUSSION | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jdramsey We need to discuss this tho |
||
// Here it would only be retained if the points and direction of an edge is exactly the same. | ||
// Do we want to only check for points? If not, a lot wrong/no direction edges would be filtered out at this step. | ||
truePositive.retainAll(xMBLookupGraphEdges); | ||
|
||
double precision = (double) truePositive.size() / xMBLookupGraphEdges.size(); | ||
double recall = (double) truePositive.size() / xMBEstimatedGraphEdges.size(); | ||
return getPrecision ? precision : recall; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These outprints seems correct to me, maybe you want a second check : ) |
||
} | ||
|
||
|
||
/** | ||
* Returns the variables of the independence test. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jdramsey for confirmation :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the method I had in mind:
You could put that method somewhere helpful; it may not already exist in the code.