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 class
Represents a NodeId with a name and a lag value. -
Constructor Summary
ConstructorsConstructorDescriptionConstructor for TimeLagGraph.TimeLagGraph
(TimeLagGraph graph) Constructor for TimeLagGraph. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAmbiguousTriple
(Node x, Node y, Node z) Adds an ambiguous triple to the list of ambiguous triples.void
addAttribute
(String key, Object value) Adds a key-value pair to the attributes map.boolean
addBidirectedEdge
(Node node1, Node node2) Adds a bidirected edge between two nodes.boolean
addDirectedEdge
(Node node1, Node node2) Adds a directed edge between two nodes to the graph.void
addDottedUnderlineTriple
(Node x, Node y, Node z) Adds a triple with dotted underline to the list of triples.boolean
Adds a directed edge to the graph.boolean
Adds a node to the graph.boolean
addNondirectedEdge
(Node node1, Node node2) Adds a nondirected edge between two nodes.boolean
addPartiallyOrientedEdge
(Node node1, Node node2) Adds a partially oriented edge between two given nodes.void
Adds aPropertyChangeListener
to the list of listeners that are notified when a bound property is changed.void
addUnderlineTriple
(Node x, Node y, Node z) Adds an underline triple consisting of three nodes to the graph.boolean
addUndirectedEdge
(Node node1, Node node2) Adds an undirected edge between two nodes.void
clear()
Clears the graph by removing all vertices and edges.boolean
containsEdge
(Edge edge) Checks if the givenEdge
object exists in the graph.boolean
containsNode
(Node node) Checks if the graph contains a specific node.boolean
Compares this Graph object with the specified object for equality.void
fullyConnect
(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.int
Returns the degree of the graph.int
Retrieves 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.int
getIndegree
(Node node) Returns the indegree of a given node in the graph.Getter for the fieldlag0Nodes
.int
Getter 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.int
Retrieves the number of edges in the graph.int
getNumEdges
(Node node) Retrieves the number of edges connected to a specific node.int
Getter for the fieldnumInitialLags
.int
Gets the number of nodes in the graph.int
getOutdegree
(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.int
hashCode()
Returns the hash code value for this object.boolean
isAdjacentTo
(Node node1, Node node2) Determines whether two nodes are adjacent in the graph.boolean
isAmbiguousTriple
(Node x, Node y, Node z) Checks whether a triple of nodes is ambiguous.boolean
Checks if a given node is a child of another node in the graph.boolean
isDefCollider
(Node node1, Node node2, Node node3) Determines if there is a definite collider relationship between the given nodes.boolean
isDefNoncollider
(Node node1, Node node2, Node node3) Determines if the given nodes form a definite noncollider in the graph.boolean
isExogenous
(Node node) Checks if a given node is exogenous.boolean
isParameterizable
(Node node) Checks if a node is parameterizable.boolean
isParentOf
(Node node1, Node node2) Determines if a given node is a parent of another node in the graph.boolean
Checks if the model is based on time lag.boolean
isUnderlineTriple
(Node x, Node y, Node z) Checks whether a given triple (x, y, z) is an underline triple.paths()
Returns the instance of Paths.void
removeAmbiguousTriple
(Node x, Node y, Node z) Removes an ambiguous triple from the collection.void
removeAttribute
(String key) Removes the attribute with the specified key from the object.void
removeDottedUnderlineTriple
(Node x, Node y, Node z) Removes a triple of nodes from the set of dottedUnderLineTriples.boolean
removeEdge
(Edge edge) Removes an edge from the graph.boolean
removeEdge
(Node node1, Node node2) Removes the edge between two given nodes.boolean
removeEdges
(Node node1, Node node2) Removes edges between two nodes.boolean
removeEdges
(Collection<Edge> edges) Removes the specified collection of edges from the graph.boolean
removeHighLagEdges
(int maxLag) removeHighLagEdges.boolean
removeNode
(Node node) Removes the given node from the graph.boolean
removeNodes
(List<Node> nodes) Removes the specified nodes from the graph.void
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.void
removeUnderlineTriple
(Node x, Node y, Node z) Removes the specified triple (x, y, z) from the list of underline triples.void
reorientAllWith
(Endpoint endpoint) Reorients all edges in the graph to point towards the specified endpoint.static TimeLagGraph
Generates a simple exemplar of this class to test serialization.void
setAmbiguousTriples
(Set<Triple> triples) Sets the set of ambiguous triples.void
setDottedUnderLineTriples
(Set<Triple> triples) Sets the dotted underline triples.boolean
setEndpoint
(Node from, Node to, Endpoint endPoint) Sets the endpoint of an edge between two nodes in the graph.boolean
setMaxLag
(int maxLag) Setter for the fieldmaxLag
.void
Sets the nodes of the graph.boolean
setNumInitialLags
(int numInitialLags) Setter for the fieldnumInitialLags
.void
setUnderLineTriples
(Set<Triple> triples) Sets the underline triples.Returns a subgraph of the current graph based on the provided nodes.toString()
toString.void
transferAttributes
(Graph graph) Transfers attributes from the given graph to the current graph.void
transferNodesAndEdges
(Graph graph) Transfers nodes and edges from the given graph to the current graph.Methods inherited from interface edu.cmu.tetrad.graph.Graph
existsSemidirectedPath, isAncestorOf
-
Constructor Details
-
TimeLagGraph
public TimeLagGraph()Constructor for TimeLagGraph.
-
TimeLagGraph
Constructor for TimeLagGraph.
- Parameters:
graph
- aTimeLagGraph
object
-
-
Method Details
-
serializableInstance
Generates a simple exemplar of this class to test serialization.- Returns:
- a
TimeLagGraph
object
-
addNode
-
removeNode
Removes the given node from the graph.- Specified by:
removeNode
in 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:
addEdge
in 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:
removeEdge
in 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
- aNode
object- Returns:
- a
TimeLagGraph.NodeId
object
-
getNode
-
getLag0Nodes
-
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
-
addDirectedEdge
Adds a directed edge between two nodes to the graph.- Specified by:
addDirectedEdge
in 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:
addUndirectedEdge
in 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:
addNondirectedEdge
in 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:
addPartiallyOrientedEdge
in interfaceGraph
- Parameters:
node1
- the first node of the edgenode2
- the second node of the edge- Returns:
true
if the edge is successfully added,false
otherwise
-
addBidirectedEdge
Adds a bidirected edge between two nodes.- Specified by:
addBidirectedEdge
in 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:
isDefNoncollider
in 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:
isDefCollider
in interfaceGraph
- Parameters:
node1
- The first node.node2
- The second node.node3
- The third node.- Returns:
true
if there is a definite collider relationship between the nodes,false
otherwise.
-
getChildren
-
getDegree
-
getEdge
-
getDirectedEdge
Retrieves the directed edge connecting two nodes in the graph.- Specified by:
getDirectedEdge
in 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:
getParents
in 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:
getIndegree
in 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:
getOutdegree
in 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:
isAdjacentTo
in 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:
isParentOf
in interfaceGraph
- Parameters:
node1
- the firstNode
object to comparenode2
- the secondNode
object 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:
transferNodesAndEdges
in 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:
transferAttributes
in interfaceGraph
- Parameters:
graph
- aGraph
object to transfer attributes from- Throws:
IllegalArgumentException
- if the provided graph is null
-
paths
-
isParameterizable
Checks if a node is parameterizable.- Specified by:
isParameterizable
in interfaceGraph
- Parameters:
node
- The node to be checked. Must be aNode
object.- Returns:
- True if the node is parameterizable, false otherwise.
-
isTimeLagModel
public boolean isTimeLagModel()Checks if the model is based on time lag.- Specified by:
isTimeLagModel
in interfaceGraph
- Returns:
true
if the model is based on time lag,false
otherwise.
-
getTimeLagGraph
Returns the TimeLagGraph object.- Specified by:
getTimeLagGraph
in 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:
isExogenous
in interfaceGraph
- Parameters:
node
- The node to check. It should be aNode
object.- Returns:
- Returns true if the node is exogenous, false otherwise.
-
getAdjacentNodes
Retrieves a list of adjacent nodes for the given node.- Specified by:
getAdjacentNodes
in 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:
getEndpoint
in 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:
setEndpoint
in 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:
getNodesInTo
in interfaceGraph
- Parameters:
node
- the source node from which the incoming edges are consideredendpoint
- the specific endpoint of the incoming edge- Returns:
- a list of
Node
objects 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:
getNodesOutTo
in 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 aPropertyChangeListener
to the list of listeners that are notified when a bound property is changed.- Specified by:
addPropertyChangeListener
in interfaceGraph
- Parameters:
l
- ThePropertyChangeListener
to be added
-
getEdges
-
containsEdge
Checks if the givenEdge
object exists in the graph.- Specified by:
containsEdge
in 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:
containsNode
in interfaceGraph
- Parameters:
node
- the node to be checked. It should be aNode
object.- Returns:
true
if the graph contains the specified node,false
otherwise.
-
getEdges
Returns the list of edges connected to the specified node. -
getEdges
-
hashCode
-
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:
fullyConnect
in interfaceGraph
- Parameters:
endpoint
- the endpoint to be fully connected
-
reorientAllWith
Reorients all edges in the graph to point towards the specified endpoint.- Specified by:
reorientAllWith
in interfaceGraph
- Parameters:
endpoint
- the endpoint to reorient all edges with (an instance ofEndpoint
)
-
getNode
-
getNumNodes
public int getNumNodes()Gets the number of nodes in the graph.- Specified by:
getNumNodes
in interfaceGraph
- Returns:
- the total number of nodes in the graph
-
getNumEdges
public int getNumEdges()Retrieves the number of edges in the graph.- Specified by:
getNumEdges
in interfaceGraph
- Returns:
- the number of edges in the graph
-
getNumEdges
Retrieves the number of edges connected to a specific node.- Specified by:
getNumEdges
in interfaceGraph
- Parameters:
node
- aNode
object representing the node to check- Returns:
- an integer value representing the number of edges connected to the specified node
-
subgraph
-
getNodes
-
setNodes
Sets the nodes of the graph.- Specified by:
setNodes
in 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:
getNodeNames
in interfaceGraph
- Returns:
- a List of Strings representing the node names
-
clear
-
removeEdge
Removes the edge between two given nodes.- Specified by:
removeEdge
in 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:
removeEdges
in 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:
removeNodes
in interfaceGraph
- Parameters:
nodes
- a list of nodes to be removed from the graph- Returns:
- true if the nodes were successfully removed, false otherwise
-
removeEdges
-
getAllAttributes
Retrieves all the attributes stored in the object.- Specified by:
getAllAttributes
in 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:
getAttribute
in 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:
removeAttribute
in interfaceGraph
- Parameters:
key
- The key of the attribute to be removed. This must be aString
object.
-
addAttribute
Adds a key-value pair to the attributes map.- Specified by:
addAttribute
in interfaceGraph
- Parameters:
key
- the key of the attributevalue
- the value of the attribute
-
getAmbiguousTriples
Retrieves the set of ambiguous triples.- Specified by:
getAmbiguousTriples
in interfaceGraph
- Returns:
- The set of ambiguous triples.
-
setAmbiguousTriples
Sets the set of ambiguous triples.- Specified by:
setAmbiguousTriples
in 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:
getUnderLines
in interfaceGraph
- Returns:
- a set of Triple objects representing the underlines
-
getDottedUnderlines
Returns a set of Triple objects representing dotted underlines.- Specified by:
getDottedUnderlines
in interfaceGraph
- Returns:
- a set of Triple objects representing dotted underlines
-
isAmbiguousTriple
Checks whether a triple of nodes is ambiguous.- Specified by:
isAmbiguousTriple
in interfaceGraph
- Parameters:
x
- aNode
object representing the first node.y
- aNode
object representing the second node.z
- aNode
object 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:
isUnderlineTriple
in interfaceGraph
- Parameters:
x
- The first node of the triple.y
- The second node of the triple.z
- The third node of the triple.- Returns:
true
if the triple is an underline triple,false
otherwise.
-
addAmbiguousTriple
-
addUnderlineTriple
Adds an underline triple consisting of three nodes to the graph.- Specified by:
addUnderlineTriple
in 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:
addDottedUnderlineTriple
in 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:
removeAmbiguousTriple
in 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:
removeUnderlineTriple
in 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:
removeDottedUnderlineTriple
in 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:
setUnderLineTriples
in interfaceGraph
- Parameters:
triples
- the set of triples to set as underline triples
-
setDottedUnderLineTriples
Sets the dotted underline triples.- Specified by:
setDottedUnderLineTriples
in 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:
removeTriplesNotInGraph
in interfaceGraph
-