use of edu.cmu.tetrad.graph.Endpoint in project tetrad by cmu-phil.
the class JsonUtils method parseJSONObjectToTetradEdge.
public static Edge parseJSONObjectToTetradEdge(Graph graph, JSONObject jObj) {
Node node1 = graph.getNode(jObj.getJSONObject("node1").getString("name"));
Node node2 = graph.getNode(jObj.getJSONObject("node2").getString("name"));
Endpoint endpoint1 = Endpoint.TYPES[jObj.getJSONObject("endpoint1").getInt("ordinal")];
Endpoint endpoint2 = Endpoint.TYPES[jObj.getJSONObject("endpoint2").getInt("ordinal")];
Edge edge = new Edge(node1, node2, endpoint1, endpoint2);
try {
// properties
JSONArray jArray = jObj.getJSONArray("properties");
if (jArray != null) {
for (int i = 0; i < jArray.length(); i++) {
edge.addProperty(parseJSONObjectToEdgeProperty(jArray.getString(i)));
}
}
} catch (JSONException e) {
// TODO Auto-generated catch block
// e.printStackTrace();
}
try {
// properties
JSONArray jArray = jObj.getJSONArray("edgeTypeProbabilities");
if (jArray != null) {
for (int i = 0; i < jArray.length(); i++) {
edge.addEdgeTypeProbability(parseJSONObjectToEdgeTypeProperty(jArray.getJSONObject(i)));
}
}
} catch (JSONException e) {
// TODO Auto-generated catch block
// e.printStackTrace();
}
return edge;
}
use of edu.cmu.tetrad.graph.Endpoint in project tetrad by cmu-phil.
the class KnowledgeDisplayEdge method drawEndpoints.
/**
* Draws endpoints appropriate to the type of edge this is.
*
* @param pp the point pair which specifies where and at what angle the
* endpoints are to be drawn. The 'from' endpoint is drawn at the
* 'from' point angled as it it were coming from the 'to'
* endpoint, and vice-versa.
* @param g the graphics context.
*/
private void drawEndpoints(PointPair pp, Graphics g) {
if (getModelEdge() != null) {
Endpoint endpointA = getModelEdge().getEndpoint1();
Endpoint endpointB = getModelEdge().getEndpoint2();
if (endpointA == Endpoint.CIRCLE) {
drawCircleEndpoint(pp.getTo(), pp.getFrom(), g);
} else if (endpointA == Endpoint.ARROW) {
drawArrowEndpoint(pp.getTo(), pp.getFrom(), g);
}
if (endpointB == Endpoint.CIRCLE) {
drawCircleEndpoint(pp.getFrom(), pp.getTo(), g);
} else if (endpointB == Endpoint.ARROW) {
drawArrowEndpoint(pp.getFrom(), pp.getTo(), g);
}
} else {
drawArrowEndpoint(pp.getFrom(), pp.getTo(), g);
}
}
use of edu.cmu.tetrad.graph.Endpoint in project tetrad by cmu-phil.
the class TsFciOrient method orientSimilarPairs.
private void orientSimilarPairs(Graph graph, IKnowledge knowledge, Node x, Node y, Endpoint mark) {
if (x.getName().equals("time") || y.getName().equals("time")) {
return;
}
System.out.println("Entering orient similar pairs method for x and y: " + x + ", " + y);
int ntiers = knowledge.getNumTiers();
int indx_tier = knowledge.isInWhichTier(x);
int indy_tier = knowledge.isInWhichTier(y);
int tier_diff = Math.max(indx_tier, indy_tier) - Math.min(indx_tier, indy_tier);
int indx_comp = -1;
int indy_comp = -1;
List tier_x = knowledge.getTier(indx_tier);
// Collections.sort(tier_x);
List tier_y = knowledge.getTier(indy_tier);
// Collections.sort(tier_y);
int i;
for (i = 0; i < tier_x.size(); ++i) {
if (getNameNoLag(x.getName()).equals(getNameNoLag(tier_x.get(i)))) {
indx_comp = i;
break;
}
}
for (i = 0; i < tier_y.size(); ++i) {
if (getNameNoLag(y.getName()).equals(getNameNoLag(tier_y.get(i)))) {
indy_comp = i;
break;
}
}
if (indx_comp == -1)
System.out.println("WARNING: indx_comp = -1!!!! ");
if (indy_comp == -1)
System.out.println("WARNING: indy_comp = -1!!!! ");
for (i = 0; i < ntiers - tier_diff; ++i) {
if (knowledge.getTier(i).size() == 1)
continue;
String A;
Node x1;
String B;
Node y1;
if (indx_tier >= indy_tier) {
List tmp_tier1 = knowledge.getTier(i + tier_diff);
// Collections.sort(tmp_tier1);
List tmp_tier2 = knowledge.getTier(i);
// Collections.sort(tmp_tier2);
A = (String) tmp_tier1.get(indx_comp);
B = (String) tmp_tier2.get(indy_comp);
if (A.equals(B))
continue;
if (A.equals(tier_x.get(indx_comp)) && B.equals(tier_y.get(indy_comp)))
continue;
if (B.equals(tier_x.get(indx_comp)) && A.equals(tier_y.get(indy_comp)))
continue;
x1 = this.independenceTest.getVariable(A);
y1 = this.independenceTest.getVariable(B);
if (graph.isAdjacentTo(x1, y1) && graph.getEndpoint(x1, y1) == Endpoint.CIRCLE) {
System.out.print("Orient edge " + graph.getEdge(x1, y1).toString());
graph.setEndpoint(x1, y1, mark);
System.out.println(" by structure knowledge as: " + graph.getEdge(x1, y1).toString());
}
} else {
// System.out.println("############## WARNING (orientSimilarPairs): did not catch x,y pair " + x + ", " + y);
}
}
}