Class TimeLagGraph

java.lang.Object
edu.cmu.tetrad.graph.TimeLagGraph
All Implemented Interfaces:
Graph, TetradSerializable, Serializable

public class TimeLagGraph extends Object implements Graph
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:
  • Constructor Details

    • TimeLagGraph

      public TimeLagGraph()

      Constructor for TimeLagGraph.

    • TimeLagGraph

      public TimeLagGraph(TimeLagGraph graph)

      Constructor for TimeLagGraph.

      Parameters:
      graph - a TimeLagGraph object
  • Method Details

    • serializableInstance

      public static TimeLagGraph serializableInstance()
      Generates a simple exemplar of this class to test serialization.
      Returns:
      a TimeLagGraph object
    • addNode

      public boolean addNode(Node node)
      Adds a node to the graph.
      Specified by:
      addNode in interface Graph
      Parameters:
      node - the node to be added
      Returns:
      true if the node was added successfully, false otherwise
    • removeNode

      public boolean removeNode(Node node)
      Removes the given node from the graph.
      Specified by:
      removeNode in interface Graph
      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

      public boolean addEdge(Edge edge)
      Adds a directed edge to the graph.
      Specified by:
      addEdge in interface Graph
      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

      public boolean removeEdge(Edge edge)
      Removes an edge from the graph.
      Specified by:
      removeEdge in interface Graph
      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

      public TimeLagGraph.NodeId getNodeId(Node node)

      getNodeId.

      Parameters:
      node - a Node object
      Returns:
      a TimeLagGraph.NodeId object
    • getNode

      public Node getNode(String name, int lag)

      getNode.

      Parameters:
      name - a String object
      lag - a int
      Returns:
      a Node object
    • getLag0Nodes

      public List<Node> getLag0Nodes()

      Getter for the field lag0Nodes.

      Returns:
      a List object
    • 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

      public String toString()

      toString.

      Specified by:
      toString in interface Graph
      Overrides:
      toString in class Object
      Returns:
      a String object
    • addDirectedEdge

      public boolean addDirectedEdge(Node node1, Node node2)
      Adds a directed edge between two nodes to the graph.
      Specified by:
      addDirectedEdge in interface Graph
      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

      public boolean addUndirectedEdge(Node node1, Node node2)
      Adds an undirected edge between two nodes.
      Specified by:
      addUndirectedEdge in interface Graph
      Parameters:
      node1 - the first node to be connected by the edge
      node2 - 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

      public boolean addNondirectedEdge(Node node1, Node node2)
      Adds a nondirected edge between two nodes.
      Specified by:
      addNondirectedEdge in interface Graph
      Parameters:
      node1 - the first node.
      node2 - the second node.
      Returns:
      true if the nondirected edge is successfully added, false otherwise.
    • addPartiallyOrientedEdge

      public boolean addPartiallyOrientedEdge(Node node1, Node node2)
      Adds a partially oriented edge between two given nodes.
      Specified by:
      addPartiallyOrientedEdge in interface Graph
      Parameters:
      node1 - the first node of the edge
      node2 - the second node of the edge
      Returns:
      true if the edge is successfully added, false otherwise
    • addBidirectedEdge

      public boolean addBidirectedEdge(Node node1, Node node2)
      Adds a bidirected edge between two nodes.
      Specified by:
      addBidirectedEdge in interface Graph
      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

      public boolean isDefNoncollider(Node node1, Node node2, Node node3)
      Determines if the given nodes form a definite noncollider in the graph.
      Specified by:
      isDefNoncollider in interface Graph
      Parameters:
      node1 - the first node
      node2 - the second node
      node3 - the third node
      Returns:
      true if the nodes form a definite noncollider, false otherwise
    • isDefCollider

      public boolean isDefCollider(Node node1, Node node2, Node node3)
      Determines if there is a definite collider relationship between the given nodes.
      Specified by:
      isDefCollider in interface Graph
      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

      public List<Node> getChildren(Node node)
      Returns a list of children nodes for the given node.
      Specified by:
      getChildren in interface Graph
      Parameters:
      node - a Node object representing the parent node
      Returns:
      a list of Node objects 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.
      Specified by:
      getDegree in interface Graph
      Returns:
      the degree of the graph
    • getEdge

      public Edge getEdge(Node node1, Node node2)
      Retrieves the edge between the given nodes.
      Specified by:
      getEdge in interface Graph
      Parameters:
      node1 - The first node in the edge.
      node2 - The second node in the edge.
      Returns:
      The edge between the given nodes.
    • getDirectedEdge

      public Edge getDirectedEdge(Node node1, Node node2)
      Retrieves the directed edge connecting two nodes in the graph.
      Specified by:
      getDirectedEdge in interface Graph
      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

      public List<Node> getParents(Node node)
      Returns the list of parent nodes for the given node.
      Specified by:
      getParents in interface Graph
      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

      public int getIndegree(Node node)
      Returns the indegree of a given node in the graph.
      Specified by:
      getIndegree in interface Graph
      Parameters:
      node - the node for which the indegree is to be determined
      Returns:
      the indegree of the node
    • getDegree

      public int getDegree(Node node)
      Retrieves the degree of a given node in the graph. The degree of a node is the number of edges connected to it.
      Specified by:
      getDegree in interface Graph
      Parameters:
      node - a Node object representing the node for which the degree is to be determined
      Returns:
      the degree of the specified node in the graph
    • getOutdegree

      public int getOutdegree(Node node)
      Retrieves the outdegree of the specified node in the graph.
      Specified by:
      getOutdegree in interface Graph
      Parameters:
      node - The node for which to calculate the outdegree.
      Returns:
      The number of outgoing edges from the specified node.
    • isAdjacentTo

      public boolean isAdjacentTo(Node node1, Node node2)
      Determines whether two nodes are adjacent in the graph.
      Specified by:
      isAdjacentTo in interface Graph
      Parameters:
      node1 - the first node to check adjacency
      node2 - the second node to check adjacency
      Returns:
      true if the nodes are adjacent, false otherwise
    • isChildOf

      public boolean isChildOf(Node node1, Node node2)
      Checks if a given node is a child of another node in the graph.
      Specified by:
      isChildOf in interface Graph
      Parameters:
      node1 - the first Node to check
      node2 - the second Node to check if it is the parent
      Returns:
      true if node1 is a child of node2, false otherwise
    • isParentOf

      public boolean isParentOf(Node node1, Node node2)
      Determines if a given node is a parent of another node in the graph.
      Specified by:
      isParentOf in interface Graph
      Parameters:
      node1 - the first Node object to compare
      node2 - the second Node object to compare
      Returns:
      true if node1 is a parent of node2, false otherwise
    • transferNodesAndEdges

      public void transferNodesAndEdges(Graph graph) throws IllegalArgumentException
      Transfers nodes and edges from the given graph to the current graph.
      Specified by:
      transferNodesAndEdges in interface Graph
      Parameters:
      graph - the graph from which nodes and edges are to be transferred
      Throws:
      IllegalArgumentException - if the given graph is null
    • transferAttributes

      public void transferAttributes(Graph graph) throws IllegalArgumentException
      Transfers attributes from the given graph to the current graph.
      Specified by:
      transferAttributes in interface Graph
      Parameters:
      graph - a Graph object to transfer attributes from
      Throws:
      IllegalArgumentException - if the provided graph is null
    • paths

      public Paths paths()
      Returns the instance of Paths.
      Specified by:
      paths in interface Graph
      Returns:
      the instance of Paths.
    • isParameterizable

      public boolean isParameterizable(Node node)
      Checks if a node is parameterizable.
      Specified by:
      isParameterizable in interface Graph
      Parameters:
      node - The node to be checked. Must be a Node 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 interface Graph
      Returns:
      true if the model is based on time lag, false otherwise.
    • getTimeLagGraph

      public TimeLagGraph getTimeLagGraph()
      Returns the TimeLagGraph object.
      Specified by:
      getTimeLagGraph in interface Graph
      Returns:
      the TimeLagGraph object
    • getSepset

      public Set<Node> getSepset(Node n1, Node n2)
      Retrieves the sepset of two nodes in the graph.
      Specified by:
      getSepset in interface Graph
      Parameters:
      n1 - The first node
      n2 - The second node
      Returns:
      The set of nodes that form the sepset of n1 and n2
    • isExogenous

      public boolean isExogenous(Node node)
      Checks if a given node is exogenous.
      Specified by:
      isExogenous in interface Graph
      Parameters:
      node - The node to check. It should be a Node object.
      Returns:
      Returns true if the node is exogenous, false otherwise.
    • getAdjacentNodes

      public List<Node> getAdjacentNodes(Node node)
      Retrieves a list of adjacent nodes for the given node.
      Specified by:
      getAdjacentNodes in interface Graph
      Parameters:
      node - The Node object for which to find adjacent nodes.
      Returns:
      A list of adjacent nodes.
    • getEndpoint

      public Endpoint getEndpoint(Node node1, Node node2)
      Returns the endpoint between two nodes in the graph.
      Specified by:
      getEndpoint in interface Graph
      Parameters:
      node1 - The first node in the graph.
      node2 - The second node in the graph.
      Returns:
      The endpoint between the two nodes.
    • setEndpoint

      public boolean setEndpoint(Node from, Node to, Endpoint endPoint) throws IllegalArgumentException
      Sets the endpoint of an edge between two nodes in the graph.
      Specified by:
      setEndpoint in interface Graph
      Parameters:
      from - the source node for the edge
      to - the destination node for the edge
      endPoint - 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

      public List<Node> getNodesInTo(Node node, Endpoint endpoint)
      Retrieves a list of nodes that have an incoming edge from a specific node and endpoint.
      Specified by:
      getNodesInTo in interface Graph
      Parameters:
      node - the source node from which the incoming edges are considered
      endpoint - 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

      public List<Node> getNodesOutTo(Node node, Endpoint endpoint)
      Retrieves the list of nodes in a graph that have an outgoing edge to the given node and endpoint.
      Specified by:
      getNodesOutTo in interface Graph
      Parameters:
      node - the node to which the outgoing edges should be considered
      endpoint - 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

      public void addPropertyChangeListener(PropertyChangeListener l)
      Adds a PropertyChangeListener to the list of listeners that are notified when a bound property is changed.
      Specified by:
      addPropertyChangeListener in interface Graph
      Parameters:
      l - The PropertyChangeListener to be added
    • getEdges

      public Set<Edge> getEdges()
      Retrieves the set of edges in the graph.
      Specified by:
      getEdges in interface Graph
      Returns:
      a set of edges in the graph
    • containsEdge

      public boolean containsEdge(Edge edge)
      Checks if the given Edge object exists in the graph.
      Specified by:
      containsEdge in interface Graph
      Parameters:
      edge - the edge to be tested for existence in the graph
      Returns:
      true if the edge exists in the graph, false otherwise
    • containsNode

      public boolean containsNode(Node node)
      Checks if the graph contains a specific node.
      Specified by:
      containsNode in interface Graph
      Parameters:
      node - the node to be checked. It should be a Node object.
      Returns:
      true if the graph contains the specified node, false otherwise.
    • getEdges

      public List<Edge> getEdges(Node node)
      Returns the list of edges connected to the specified node.
      Specified by:
      getEdges in interface Graph
      Parameters:
      node - a Node object representing the node
      Returns:
      a List containing the edges connected to the node, or null if the node does not exist in the graph
    • getEdges

      public List<Edge> getEdges(Node node1, Node node2)
      Finds all edges between two nodes.
      Specified by:
      getEdges in interface Graph
      Parameters:
      node1 - the first node
      node2 - the second node
      Returns:
      a list of edges between the two nodes
    • hashCode

      public int hashCode()
      Returns the hash code value for this object.
      Overrides:
      hashCode in class Object
      Returns:
      the hash code value for this object
    • equals

      public boolean equals(Object o)
      Compares this Graph object with the specified object for equality.
      Specified by:
      equals in interface Graph
      Overrides:
      equals in class Object
      Parameters:
      o - the object to be compared
      Returns:
      true if the specified object is also a Graph and if their underlying graphs are equal; false otherwise
    • fullyConnect

      public void fullyConnect(Endpoint endpoint)
      Fully connects the given endpoint to all other endpoints in the graph.
      Specified by:
      fullyConnect in interface Graph
      Parameters:
      endpoint - the endpoint to be fully connected
    • reorientAllWith

      public void reorientAllWith(Endpoint endpoint)
      Reorients all edges in the graph to point towards the specified endpoint.
      Specified by:
      reorientAllWith in interface Graph
      Parameters:
      endpoint - the endpoint to reorient all edges with (an instance of Endpoint)
    • getNode

      public Node getNode(String name)
      Retrieves a Node from the graph based on the given name.
      Specified by:
      getNode in interface Graph
      Parameters:
      name - the name of the Node to retrieve
      Returns:
      the retrieved Node
    • getNumNodes

      public int getNumNodes()
      Gets the number of nodes in the graph.
      Specified by:
      getNumNodes in interface Graph
      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 interface Graph
      Returns:
      the number of edges in the graph
    • getNumEdges

      public int getNumEdges(Node node)
      Retrieves the number of edges connected to a specific node.
      Specified by:
      getNumEdges in interface Graph
      Parameters:
      node - a Node object representing the node to check
      Returns:
      an integer value representing the number of edges connected to the specified node
    • subgraph

      public Graph subgraph(List<Node> nodes)
      Returns a subgraph of the current graph based on the provided nodes.
      Specified by:
      subgraph in interface Graph
      Parameters:
      nodes - a list of nodes to include in the subgraph
      Returns:
      a subgraph of the current graph containing only the provided nodes
    • getNodes

      public List<Node> getNodes()
      Retrieves a list of nodes from the graph.
      Specified by:
      getNodes in interface Graph
      Returns:
      A list of nodes from the graph.
    • setNodes

      public void setNodes(List<Node> nodes)
      Sets the nodes of the graph.
      Specified by:
      setNodes in interface Graph
      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

      public List<String> getNodeNames()
      Returns a list of node names in the graph.
      Specified by:
      getNodeNames in interface Graph
      Returns:
      a List of Strings representing the node names
    • clear

      public void clear()
      Clears the graph by removing all vertices and edges.
      Specified by:
      clear in interface Graph
    • removeEdge

      public boolean removeEdge(Node node1, Node node2)
      Removes the edge between two given nodes.
      Specified by:
      removeEdge in interface Graph
      Parameters:
      node1 - The first node.
      node2 - The second node.
      Returns:
      true if the edge was successfully removed, false otherwise.
    • removeEdges

      public boolean removeEdges(Collection<Edge> edges)
      Removes the specified collection of edges from the graph.
      Specified by:
      removeEdges in interface Graph
      Parameters:
      edges - a collection of edges to be removed
      Returns:
      true if any edge is successfully removed, false otherwise
    • removeNodes

      public boolean removeNodes(List<Node> nodes)
      Removes the specified nodes from the graph.
      Specified by:
      removeNodes in interface Graph
      Parameters:
      nodes - a list of nodes to be removed from the graph
      Returns:
      true if the nodes were successfully removed, false otherwise
    • removeEdges

      public boolean removeEdges(Node node1, Node node2)
      Removes edges between two nodes.
      Specified by:
      removeEdges in interface Graph
      Parameters:
      node1 - the first Node object
      node2 - the second Node object
      Returns:
      true if edges between the two nodes are removed, false otherwise
    • getAllAttributes

      public Map<String,Object> getAllAttributes()
      Retrieves all the attributes stored in the object.
      Specified by:
      getAllAttributes in interface Graph
      Returns:
      a map containing the attribute names as keys and their corresponding values as values
    • getAttribute

      public Object getAttribute(String key)
      Retrieves the value associated with the specified key from the attributes map.
      Specified by:
      getAttribute in interface Graph
      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

      public void removeAttribute(String key)
      Removes the attribute with the specified key from the object.
      Specified by:
      removeAttribute in interface Graph
      Parameters:
      key - The key of the attribute to be removed. This must be a String object.
    • addAttribute

      public void addAttribute(String key, Object value)
      Adds a key-value pair to the attributes map.
      Specified by:
      addAttribute in interface Graph
      Parameters:
      key - the key of the attribute
      value - the value of the attribute
    • getAmbiguousTriples

      public Set<Triple> getAmbiguousTriples()
      Retrieves the set of ambiguous triples.
      Specified by:
      getAmbiguousTriples in interface Graph
      Returns:
      The set of ambiguous triples.
    • setAmbiguousTriples

      public void setAmbiguousTriples(Set<Triple> triples)
      Sets the set of ambiguous triples.
      Specified by:
      setAmbiguousTriples in interface Graph
      Parameters:
      triples - a set of triples to be set as ambiguous triples.
    • getUnderLines

      public Set<Triple> getUnderLines()
      Returns a set of Triple objects representing the underlines.
      Specified by:
      getUnderLines in interface Graph
      Returns:
      a set of Triple objects representing the underlines
    • getDottedUnderlines

      public Set<Triple> getDottedUnderlines()
      Returns a set of Triple objects representing dotted underlines.
      Specified by:
      getDottedUnderlines in interface Graph
      Returns:
      a set of Triple objects representing dotted underlines
    • isAmbiguousTriple

      public boolean isAmbiguousTriple(Node x, Node y, Node z)
      Checks whether a triple of nodes is ambiguous.
      Specified by:
      isAmbiguousTriple in interface Graph
      Parameters:
      x - a Node object representing the first node.
      y - a Node object representing the second node.
      z - a Node object representing the third node.
      Returns:
      true if the given triple (x, y, z) is ambiguous, false otherwise.
    • isUnderlineTriple

      public boolean isUnderlineTriple(Node x, Node y, Node z)
      Checks whether a given triple (x, y, z) is an underline triple.
      Specified by:
      isUnderlineTriple in interface Graph
      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

      public void addAmbiguousTriple(Node x, Node y, Node z)
      Adds an ambiguous triple to the list of ambiguous triples.
      Specified by:
      addAmbiguousTriple in interface Graph
      Parameters:
      x - the first Node in the triple
      y - the second Node in the triple
      z - the third Node in the triple
    • addUnderlineTriple

      public void addUnderlineTriple(Node x, Node y, Node z)
      Adds an underline triple consisting of three nodes to the graph.
      Specified by:
      addUnderlineTriple in interface Graph
      Parameters:
      x - the first node of the triple
      y - the second node of the triple
      z - the third node of the triple
    • addDottedUnderlineTriple

      public void addDottedUnderlineTriple(Node x, Node y, Node z)
      Adds a triple with dotted underline to the list of triples.
      Specified by:
      addDottedUnderlineTriple in interface Graph
      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

      public void removeAmbiguousTriple(Node x, Node y, Node z)
      Removes an ambiguous triple from the collection.
      Specified by:
      removeAmbiguousTriple in interface Graph
      Parameters:
      x - The first node of the triple.
      y - The second node of the triple.
      z - The third node of the triple.
    • removeUnderlineTriple

      public void removeUnderlineTriple(Node x, Node y, Node z)
      Removes the specified triple (x, y, z) from the list of underline triples.
      Specified by:
      removeUnderlineTriple in interface Graph
      Parameters:
      x - The first node of the triple.
      y - The second node of the triple.
      z - The third node of the triple.
    • removeDottedUnderlineTriple

      public void removeDottedUnderlineTriple(Node x, Node y, Node z)
      Removes a triple of nodes from the set of dottedUnderLineTriples.
      Specified by:
      removeDottedUnderlineTriple in interface Graph
      Parameters:
      x - the first node in the triple
      y - the second node in the triple
      z - the third node in the triple
    • setUnderLineTriples

      public void setUnderLineTriples(Set<Triple> triples)
      Sets the underline triples.
      Specified by:
      setUnderLineTriples in interface Graph
      Parameters:
      triples - the set of triples to set as underline triples
    • setDottedUnderLineTriples

      public void setDottedUnderLineTriples(Set<Triple> triples)
      Sets the dotted underline triples.
      Specified by:
      setDottedUnderLineTriples in interface Graph
      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 interface Graph