Package edu.cmu.tetrad.graph
Class TimeLagGraph
java.lang.Object
edu.cmu.tetrad.graph.TimeLagGraph
- All Implemented Interfaces:
Graph,TetradSerializable,Serializable
Represents a time series graph--that is, a graph with a fixed number S of lags, with edges into initial lags
only--that is, into nodes in the first R lags, for some R. Edge structure repeats every R nodes.
- Version:
- $Id: $Id
- Author:
- josephramsey
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresents a NodeId with a name and a lag value. -
Constructor Summary
ConstructorsConstructorDescriptionConstructor for TimeLagGraph.TimeLagGraph(TimeLagGraph graph) Constructor for TimeLagGraph. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAmbiguousTriple(Node x, Node y, Node z) Adds an ambiguous triple to the list of ambiguous triples.voidaddAttribute(String key, Object value) Adds a key-value pair to the attributes map.booleanaddBidirectedEdge(Node node1, Node node2) Adds a bidirected edge between two nodes.booleanaddDirectedEdge(Node node1, Node node2) Adds a directed edge between two nodes to the graph.voidaddDottedUnderlineTriple(Node x, Node y, Node z) Adds a triple with dotted underline to the list of triples.booleanAdds a directed edge to the graph.booleanAdds a node to the graph.booleanaddNondirectedEdge(Node node1, Node node2) Adds a nondirected edge between two nodes.booleanaddPartiallyOrientedEdge(Node node1, Node node2) Adds a partially oriented edge between two given nodes.voidAdds aPropertyChangeListenerto the list of listeners that are notified when a bound property is changed.voidaddUnderlineTriple(Node x, Node y, Node z) Adds an underline triple consisting of three nodes to the graph.booleanaddUndirectedEdge(Node node1, Node node2) Adds an undirected edge between two nodes.voidclear()Clears the graph by removing all vertices and edges.booleancontainsEdge(Edge edge) Checks if the givenEdgeobject exists in the graph.booleancontainsNode(Node node) Checks if the graph contains a specific node.booleanCompares this Graph object with the specified object for equality.voidfullyConnect(Endpoint endpoint) Fully connects the given endpoint to all other endpoints in the graph.getAdjacentNodes(Node node) Retrieves a list of adjacent nodes for the given node.Retrieves all the attributes stored in the object.Retrieves the set of ambiguous triples.getAttribute(String key) Retrieves the value associated with the specified key from the attributes map.getChildren(Node node) Returns a list of children nodes for the given node.intReturns the degree of the graph.intRetrieves the degree of a given node in the graph.getDirectedEdge(Node node1, Node node2) Retrieves the directed edge connecting two nodes in the graph.Returns a set of Triple objects representing dotted underlines.Retrieves the edge between the given nodes.getEdges()Retrieves the set of edges in the graph.Returns the list of edges connected to the specified node.Finds all edges between two nodes.getEndpoint(Node node1, Node node2) Returns the endpoint between two nodes in the graph.intgetIndegree(Node node) Returns the indegree of a given node in the graph.Getter for the fieldlag0Nodes.intGetter for the fieldmaxLag.Retrieves a Node from the graph based on the given name.getNode.getNodeId.Returns a list of node names in the graph.getNodes()Retrieves a list of nodes from the graph.getNodesInTo(Node node, Endpoint endpoint) Retrieves a list of nodes that have an incoming edge from a specific node and endpoint.getNodesOutTo(Node node, Endpoint endpoint) Retrieves the list of nodes in a graph that have an outgoing edge to the given node and endpoint.intRetrieves the number of edges in the graph.intgetNumEdges(Node node) Retrieves the number of edges connected to a specific node.intGetter for the fieldnumInitialLags.intGets the number of nodes in the graph.intgetOutdegree(Node node) Retrieves the outdegree of the specified node in the graph.getParents(Node node) Returns the list of parent nodes for the given node.getSepset(Node n1, Node n2, IndependenceTest test) Retrieves the sepset of two nodes in the graph.Returns the TimeLagGraph object.Returns a set of Triple objects representing the underlines.inthashCode()Returns the hash code value for this object.booleanisAdjacentTo(Node node1, Node node2) Determines whether two nodes are adjacent in the graph.booleanisAmbiguousTriple(Node x, Node y, Node z) Checks whether a triple of nodes is ambiguous.booleanChecks if a given node is a child of another node in the graph.booleanisDefCollider(Node node1, Node node2, Node node3) Determines if there is a definite collider relationship between the given nodes.booleanisDefNoncollider(Node node1, Node node2, Node node3) Determines if the given nodes form a definite noncollider in the graph.booleanisExogenous(Node node) Checks if a given node is exogenous.booleanisParameterizable(Node node) Checks if a node is parameterizable.booleanisParentOf(Node node1, Node node2) Determines if a given node is a parent of another node in the graph.booleanChecks if the model is based on time lag.booleanisUnderlineTriple(Node x, Node y, Node z) Checks whether a given triple (x, y, z) is an underline triple.paths()Returns the instance of Paths.voidremoveAmbiguousTriple(Node x, Node y, Node z) Removes an ambiguous triple from the collection.voidremoveAttribute(String key) Removes the attribute with the specified key from the object.voidremoveDottedUnderlineTriple(Node x, Node y, Node z) Removes a triple of nodes from the set of dottedUnderLineTriples.booleanremoveEdge(Edge edge) Removes an edge from the graph.booleanremoveEdge(Node node1, Node node2) Removes the edge between two given nodes.booleanremoveEdges(Node node1, Node node2) Removes edges between two nodes.booleanremoveEdges(Collection<Edge> edges) Removes the specified collection of edges from the graph.booleanremoveHighLagEdges(int maxLag) removeHighLagEdges.booleanremoveNode(Node node) Removes the given node from the graph.booleanremoveNodes(List<Node> nodes) Removes the specified nodes from the graph.voidRemoves triples from the object's internal lists if any of the nodes in the triple is not present in the graph, or if any of the nodes are not adjacent to each other in the graph.voidremoveUnderlineTriple(Node x, Node y, Node z) Removes the specified triple (x, y, z) from the list of underline triples.voidreorientAllWith(Endpoint endpoint) Reorients all edges in the graph to point towards the specified endpoint.static TimeLagGraphGenerates a simple exemplar of this class to test serialization.voidsetAmbiguousTriples(Set<Triple> triples) Sets the set of ambiguous triples.voidsetDottedUnderLineTriples(Set<Triple> triples) Sets the dotted underline triples.booleansetEndpoint(Node from, Node to, Endpoint endPoint) Sets the endpoint of an edge between two nodes in the graph.booleansetMaxLag(int maxLag) Setter for the fieldmaxLag.voidSets the nodes of the graph.booleansetNumInitialLags(int numInitialLags) Setter for the fieldnumInitialLags.voidsetUnderLineTriples(Set<Triple> triples) Sets the underline triples.Returns a subgraph of the current graph based on the provided nodes.toString()toString.voidtransferAttributes(Graph graph) Transfers attributes from the given graph to the current graph.voidtransferNodesAndEdges(Graph graph) Transfers nodes and edges from the given graph to the current graph.Methods inherited from interface edu.cmu.tetrad.graph.Graph
copy, existsSemidirectedPath, isAncestorOf
-
Constructor Details
-
TimeLagGraph
public TimeLagGraph()Constructor for TimeLagGraph.
-
TimeLagGraph
Constructor for TimeLagGraph.
- Parameters:
graph- aTimeLagGraphobject
-
-
Method Details
-
serializableInstance
Generates a simple exemplar of this class to test serialization.- Returns:
- a
TimeLagGraphobject
-
addNode
Adds a node to the graph. -
removeNode
Removes the given node from the graph.- Specified by:
removeNodein interfaceGraph- Parameters:
node- the node to be removed- Returns:
- true if the node was successfully removed from the graph, false otherwise
- Throws:
IllegalArgumentException- if the node is not present in the graph
-
addEdge
Adds a directed edge to the graph.- Specified by:
addEdgein interfaceGraph- Parameters:
edge- the directed edge to be added- Returns:
- true if the edge was successfully added, false otherwise
- Throws:
IllegalArgumentException- if the edge is not a directed edge, or if the edge does not connect nodes within the current time lag
-
removeEdge
Removes an edge from the graph.- Specified by:
removeEdgein interfaceGraph- Parameters:
edge- the edge to be removed- Returns:
- true if the edge was removed successfully, false otherwise
- Throws:
IllegalArgumentException- if the edge is not a directed edge
-
setMaxLag
public boolean setMaxLag(int maxLag) Setter for the field
maxLag.- Parameters:
maxLag- a int- Returns:
- a boolean
-
removeHighLagEdges
public boolean removeHighLagEdges(int maxLag) removeHighLagEdges.
- Parameters:
maxLag- a int- Returns:
- a boolean
-
setNumInitialLags
public boolean setNumInitialLags(int numInitialLags) Setter for the field
numInitialLags.- Parameters:
numInitialLags- a int- Returns:
- a boolean
-
getNodeId
getNodeId.
- Parameters:
node- aNodeobject- Returns:
- a
TimeLagGraph.NodeIdobject
-
getNode
getNode.
-
getLag0Nodes
Getter for the field
lag0Nodes.- Returns:
- a
Listobject
-
getMaxLag
public int getMaxLag()Getter for the field
maxLag.- Returns:
- a int
-
getNumInitialLags
public int getNumInitialLags()Getter for the field
numInitialLags.- Returns:
- a int
-
toString
toString.
-
addDirectedEdge
Adds a directed edge between two nodes to the graph.- Specified by:
addDirectedEdgein interfaceGraph- Parameters:
node1- the first node to connect (source)node2- the second node to connect (target)- Returns:
- true if the directed edge was successfully added, false otherwise
-
addUndirectedEdge
Adds an undirected edge between two nodes.- Specified by:
addUndirectedEdgein interfaceGraph- Parameters:
node1- the first node to be connected by the edgenode2- the second node to be connected by the edge- Returns:
- true if the undirected edge was successfully added; otherwise, false
- Throws:
UnsupportedOperationException- if undirected edges are not supported
-
addNondirectedEdge
Adds a nondirected edge between two nodes.- Specified by:
addNondirectedEdgein interfaceGraph- Parameters:
node1- the first node.node2- the second node.- Returns:
- true if the nondirected edge is successfully added, false otherwise.
-
addPartiallyOrientedEdge
Adds a partially oriented edge between two given nodes.- Specified by:
addPartiallyOrientedEdgein interfaceGraph- Parameters:
node1- the first node of the edgenode2- the second node of the edge- Returns:
trueif the edge is successfully added,falseotherwise
-
addBidirectedEdge
Adds a bidirected edge between two nodes.- Specified by:
addBidirectedEdgein interfaceGraph- Parameters:
node1- the first node to connect (non-null)node2- the second node to connect (non-null)- Returns:
- true if the bidirected edge was added successfully, false otherwise
-
isDefNoncollider
Determines if the given nodes form a definite noncollider in the graph.- Specified by:
isDefNoncolliderin interfaceGraph- Parameters:
node1- the first nodenode2- the second nodenode3- the third node- Returns:
- true if the nodes form a definite noncollider, false otherwise
-
isDefCollider
Determines if there is a definite collider relationship between the given nodes.- Specified by:
isDefColliderin interfaceGraph- Parameters:
node1- The first node.node2- The second node.node3- The third node.- Returns:
trueif there is a definite collider relationship between the nodes,falseotherwise.
-
getChildren
Returns a list of children nodes for the given node.- Specified by:
getChildrenin interfaceGraph- Parameters:
node- aNodeobject representing the parent node- Returns:
- a list of
Nodeobjects representing the children nodes
-
getDegree
public int getDegree()Returns the degree of the graph. The degree of a graph is the number of edges incident to a vertex. -
getEdge
Retrieves the edge between the given nodes. -
getDirectedEdge
Retrieves the directed edge connecting two nodes in the graph.- Specified by:
getDirectedEdgein interfaceGraph- Parameters:
node1- The first node.node2- The second node.- Returns:
- The directed edge connecting the two nodes, or null if no such edge exists.
-
getParents
Returns the list of parent nodes for the given node.- Specified by:
getParentsin interfaceGraph- Parameters:
node- the node for which to retrieve the parent nodes- Returns:
- a List of Node objects representing the parent nodes of the given node
-
getIndegree
Returns the indegree of a given node in the graph.- Specified by:
getIndegreein interfaceGraph- Parameters:
node- the node for which the indegree is to be determined- Returns:
- the indegree of the node
-
getDegree
Retrieves the degree of a given node in the graph. The degree of a node is the number of edges connected to it. -
getOutdegree
Retrieves the outdegree of the specified node in the graph.- Specified by:
getOutdegreein interfaceGraph- Parameters:
node- The node for which to calculate the outdegree.- Returns:
- The number of outgoing edges from the specified node.
-
isAdjacentTo
Determines whether two nodes are adjacent in the graph.- Specified by:
isAdjacentToin interfaceGraph- Parameters:
node1- the first node to check adjacencynode2- the second node to check adjacency- Returns:
- true if the nodes are adjacent, false otherwise
-
isChildOf
Checks if a given node is a child of another node in the graph. -
isParentOf
Determines if a given node is a parent of another node in the graph.- Specified by:
isParentOfin interfaceGraph- Parameters:
node1- the firstNodeobject to comparenode2- the secondNodeobject to compare- Returns:
- true if node1 is a parent of node2, false otherwise
-
transferNodesAndEdges
Transfers nodes and edges from the given graph to the current graph.- Specified by:
transferNodesAndEdgesin interfaceGraph- Parameters:
graph- the graph from which nodes and edges are to be transferred- Throws:
IllegalArgumentException- if the given graph is null
-
transferAttributes
Transfers attributes from the given graph to the current graph.- Specified by:
transferAttributesin interfaceGraph- Parameters:
graph- aGraphobject to transfer attributes from- Throws:
IllegalArgumentException- if the provided graph is null
-
paths
Returns the instance of Paths. -
isParameterizable
Checks if a node is parameterizable.- Specified by:
isParameterizablein interfaceGraph- Parameters:
node- The node to be checked. Must be aNodeobject.- Returns:
- True if the node is parameterizable, false otherwise.
-
isTimeLagModel
public boolean isTimeLagModel()Checks if the model is based on time lag.- Specified by:
isTimeLagModelin interfaceGraph- Returns:
trueif the model is based on time lag,falseotherwise.
-
getTimeLagGraph
Returns the TimeLagGraph object.- Specified by:
getTimeLagGraphin interfaceGraph- Returns:
- the TimeLagGraph object
-
getSepset
Retrieves the sepset of two nodes in the graph. -
isExogenous
Checks if a given node is exogenous.- Specified by:
isExogenousin interfaceGraph- Parameters:
node- The node to check. It should be aNodeobject.- Returns:
- Returns true if the node is exogenous, false otherwise.
-
getAdjacentNodes
Retrieves a list of adjacent nodes for the given node.- Specified by:
getAdjacentNodesin interfaceGraph- Parameters:
node- The Node object for which to find adjacent nodes.- Returns:
- A list of adjacent nodes.
-
getEndpoint
Returns the endpoint between two nodes in the graph.- Specified by:
getEndpointin interfaceGraph- Parameters:
node1- The first node in the graph.node2- The second node in the graph.- Returns:
- The endpoint between the two nodes.
-
setEndpoint
Sets the endpoint of an edge between two nodes in the graph.- Specified by:
setEndpointin interfaceGraph- Parameters:
from- the source node for the edgeto- the destination node for the edgeendPoint- the endpoint to set for the edge- Returns:
- true if the endpoint was set successfully, false otherwise
- Throws:
IllegalArgumentException- if the source or destination node is null or not present in the graph
-
getNodesInTo
Retrieves a list of nodes that have an incoming edge from a specific node and endpoint.- Specified by:
getNodesInToin interfaceGraph- Parameters:
node- the source node from which the incoming edges are consideredendpoint- the specific endpoint of the incoming edge- Returns:
- a list of
Nodeobjects representing the nodes that have an incoming edge from the specified node and endpoint
-
getNodesOutTo
Retrieves the list of nodes in a graph that have an outgoing edge to the given node and endpoint.- Specified by:
getNodesOutToin interfaceGraph- Parameters:
node- the node to which the outgoing edges should be consideredendpoint- the endpoint at which the edges should be considered- Returns:
- a list of nodes that have an outgoing edge to the specified node and endpoint
-
addPropertyChangeListener
Adds aPropertyChangeListenerto the list of listeners that are notified when a bound property is changed.- Specified by:
addPropertyChangeListenerin interfaceGraph- Parameters:
l- ThePropertyChangeListenerto be added
-
getEdges
Retrieves the set of edges in the graph. -
containsEdge
Checks if the givenEdgeobject exists in the graph.- Specified by:
containsEdgein interfaceGraph- Parameters:
edge- the edge to be tested for existence in the graph- Returns:
- true if the edge exists in the graph, false otherwise
-
containsNode
Checks if the graph contains a specific node.- Specified by:
containsNodein interfaceGraph- Parameters:
node- the node to be checked. It should be aNodeobject.- Returns:
trueif the graph contains the specified node,falseotherwise.
-
getEdges
Returns the list of edges connected to the specified node. -
getEdges
Finds all edges between two nodes. -
hashCode
public int hashCode()Returns the hash code value for this object. -
equals
Compares this Graph object with the specified object for equality. -
fullyConnect
Fully connects the given endpoint to all other endpoints in the graph.- Specified by:
fullyConnectin interfaceGraph- Parameters:
endpoint- the endpoint to be fully connected
-
reorientAllWith
Reorients all edges in the graph to point towards the specified endpoint.- Specified by:
reorientAllWithin interfaceGraph- Parameters:
endpoint- the endpoint to reorient all edges with (an instance ofEndpoint)
-
getNode
Retrieves a Node from the graph based on the given name. -
getNumNodes
public int getNumNodes()Gets the number of nodes in the graph.- Specified by:
getNumNodesin interfaceGraph- Returns:
- the total number of nodes in the graph
-
getNumEdges
public int getNumEdges()Retrieves the number of edges in the graph.- Specified by:
getNumEdgesin interfaceGraph- Returns:
- the number of edges in the graph
-
getNumEdges
Retrieves the number of edges connected to a specific node.- Specified by:
getNumEdgesin interfaceGraph- Parameters:
node- aNodeobject representing the node to check- Returns:
- an integer value representing the number of edges connected to the specified node
-
subgraph
Returns a subgraph of the current graph based on the provided nodes. -
getNodes
Retrieves a list of nodes from the graph. -
setNodes
Sets the nodes of the graph.- Specified by:
setNodesin interfaceGraph- Parameters:
nodes- a list of Node objects representing the nodes of the graph- Throws:
IllegalArgumentException- if an attempt is made to replace the nodes for a time lag graph
-
getNodeNames
Returns a list of node names in the graph.- Specified by:
getNodeNamesin interfaceGraph- Returns:
- a List of Strings representing the node names
-
clear
public void clear()Clears the graph by removing all vertices and edges. -
removeEdge
Removes the edge between two given nodes.- Specified by:
removeEdgein interfaceGraph- Parameters:
node1- The first node.node2- The second node.- Returns:
- true if the edge was successfully removed, false otherwise.
-
removeEdges
Removes the specified collection of edges from the graph.- Specified by:
removeEdgesin interfaceGraph- Parameters:
edges- a collection of edges to be removed- Returns:
- true if any edge is successfully removed, false otherwise
-
removeNodes
Removes the specified nodes from the graph.- Specified by:
removeNodesin interfaceGraph- Parameters:
nodes- a list of nodes to be removed from the graph- Returns:
- true if the nodes were successfully removed, false otherwise
-
removeEdges
Removes edges between two nodes.- Specified by:
removeEdgesin interfaceGraph- Parameters:
node1- the firstNodeobjectnode2- the secondNodeobject- Returns:
- true if edges between the two nodes are removed, false otherwise
-
getAllAttributes
Retrieves all the attributes stored in the object.- Specified by:
getAllAttributesin interfaceGraph- Returns:
- a map containing the attribute names as keys and their corresponding values as values
-
getAttribute
Retrieves the value associated with the specified key from the attributes map.- Specified by:
getAttributein interfaceGraph- Parameters:
key- The key for which to retrieve the value. Must not be null.- Returns:
- The value associated with the specified key. If the key is not found, null is returned.
-
removeAttribute
Removes the attribute with the specified key from the object.- Specified by:
removeAttributein interfaceGraph- Parameters:
key- The key of the attribute to be removed. This must be aStringobject.
-
addAttribute
Adds a key-value pair to the attributes map.- Specified by:
addAttributein interfaceGraph- Parameters:
key- the key of the attributevalue- the value of the attribute
-
getAmbiguousTriples
Retrieves the set of ambiguous triples.- Specified by:
getAmbiguousTriplesin interfaceGraph- Returns:
- The set of ambiguous triples.
-
setAmbiguousTriples
Sets the set of ambiguous triples.- Specified by:
setAmbiguousTriplesin interfaceGraph- Parameters:
triples- a set of triples to be set as ambiguous triples.
-
getUnderLines
Returns a set of Triple objects representing the underlines.- Specified by:
getUnderLinesin interfaceGraph- Returns:
- a set of Triple objects representing the underlines
-
getDottedUnderlines
Returns a set of Triple objects representing dotted underlines.- Specified by:
getDottedUnderlinesin interfaceGraph- Returns:
- a set of Triple objects representing dotted underlines
-
isAmbiguousTriple
Checks whether a triple of nodes is ambiguous.- Specified by:
isAmbiguousTriplein interfaceGraph- Parameters:
x- aNodeobject representing the first node.y- aNodeobject representing the second node.z- aNodeobject representing the third node.- Returns:
- true if the given triple (x, y, z) is ambiguous, false otherwise.
-
isUnderlineTriple
Checks whether a given triple (x, y, z) is an underline triple.- Specified by:
isUnderlineTriplein interfaceGraph- Parameters:
x- The first node of the triple.y- The second node of the triple.z- The third node of the triple.- Returns:
trueif the triple is an underline triple,falseotherwise.
-
addAmbiguousTriple
Adds an ambiguous triple to the list of ambiguous triples.- Specified by:
addAmbiguousTriplein interfaceGraph- Parameters:
x- the firstNodein the tripley- the secondNodein the triplez- the thirdNodein the triple
-
addUnderlineTriple
Adds an underline triple consisting of three nodes to the graph.- Specified by:
addUnderlineTriplein interfaceGraph- Parameters:
x- the first node of the tripley- the second node of the triplez- the third node of the triple
-
addDottedUnderlineTriple
Adds a triple with dotted underline to the list of triples.- Specified by:
addDottedUnderlineTriplein interfaceGraph- Parameters:
x- the first node of the triple. Must not be null.y- the second node of the triple. Must not be null.z- the third node of the triple. Must not be null.
-
removeAmbiguousTriple
Removes an ambiguous triple from the collection.- Specified by:
removeAmbiguousTriplein interfaceGraph- Parameters:
x- The first node of the triple.y- The second node of the triple.z- The third node of the triple.
-
removeUnderlineTriple
Removes the specified triple (x, y, z) from the list of underline triples.- Specified by:
removeUnderlineTriplein interfaceGraph- Parameters:
x- The first node of the triple.y- The second node of the triple.z- The third node of the triple.
-
removeDottedUnderlineTriple
Removes a triple of nodes from the set of dottedUnderLineTriples.- Specified by:
removeDottedUnderlineTriplein interfaceGraph- Parameters:
x- the first node in the tripley- the second node in the triplez- the third node in the triple
-
setUnderLineTriples
Sets the underline triples.- Specified by:
setUnderLineTriplesin interfaceGraph- Parameters:
triples- the set of triples to set as underline triples
-
setDottedUnderLineTriples
Sets the dotted underline triples.- Specified by:
setDottedUnderLineTriplesin interfaceGraph- Parameters:
triples- the set of triples to set
-
removeTriplesNotInGraph
public void removeTriplesNotInGraph()Removes triples from the object's internal lists if any of the nodes in the triple is not present in the graph, or if any of the nodes are not adjacent to each other in the graph. The triples are removed from the list `ambiguousTriples`, `underLineTriples`, and `dottedUnderLineTriples`.- Specified by:
removeTriplesNotInGraphin interfaceGraph
-