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. Precondition: The proposed name of the node cannot already be used by any other node in the same graph.

      Nodes may be added into the getModel time step only. That is, node.getLag() must be 0.

      Specified by:
      addNode in interface Graph
      Parameters:
      node - a Node object
      Returns:
      true if nodes were added, false if not.
    • removeNode

      public boolean removeNode(Node node)
      Removes a node from the graph.
      Specified by:
      removeNode in interface Graph
      Parameters:
      node - a Node object
      Returns:
      true if the node was removed, false if not.
    • addEdge

      public boolean addEdge(Edge edge)
      Adds the specified edge to the graph, provided it is not already in the graph.
      Specified by:
      addEdge in interface Graph
      Parameters:
      edge - a Edge object
      Returns:
      true if the edge was added, false if not.
    • removeEdge

      public boolean removeEdge(Edge edge)
      Removes the given edge from the graph.
      Specified by:
      removeEdge in interface Graph
      Parameters:
      edge - a Edge object
      Returns:
      true if the edge was removed, false if not.
    • 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 --> to the graph.
      Specified by:
      addDirectedEdge in interface Graph
      Parameters:
      node1 - a Node object
      node2 - a Node object
      Returns:
      a boolean
    • addUndirectedEdge

      public boolean addUndirectedEdge(Node node1, Node node2)
      Adds an undirected edge --- to the graph.
      Specified by:
      addUndirectedEdge in interface Graph
      Parameters:
      node1 - a Node object
      node2 - a Node object
      Returns:
      a boolean
    • addNondirectedEdge

      public boolean addNondirectedEdge(Node node1, Node node2)
      Adds a nondirected edges o-o to the graph.
      Specified by:
      addNondirectedEdge in interface Graph
      Parameters:
      node1 - a Node object
      node2 - a Node object
      Returns:
      a boolean
    • addPartiallyOrientedEdge

      public boolean addPartiallyOrientedEdge(Node node1, Node node2)
      Adds a partially oriented edge o-> to the graph.
      Specified by:
      addPartiallyOrientedEdge in interface Graph
      Parameters:
      node1 - a Node object
      node2 - a Node object
      Returns:
      a boolean
    • addBidirectedEdge

      public boolean addBidirectedEdge(Node node1, Node node2)
      Adds a bidirected edges <-> to the graph.
      Specified by:
      addBidirectedEdge in interface Graph
      Parameters:
      node1 - a Node object
      node2 - a Node object
      Returns:
      a boolean
    • isDefNoncollider

      public boolean isDefNoncollider(Node node1, Node node2, Node node3)
      Added by ekorber, 2004/6/9.
      Specified by:
      isDefNoncollider in interface Graph
      Parameters:
      node1 - a Node object
      node2 - a Node object
      node3 - a Node object
      Returns:
      true if node 2 is a definite noncollider between 1 and 3
    • isDefCollider

      public boolean isDefCollider(Node node1, Node node2, Node node3)
      Added by ekorber, 2004/6/9.
      Specified by:
      isDefCollider in interface Graph
      Parameters:
      node1 - a Node object
      node2 - a Node object
      node3 - a Node object
      Returns:
      true if node 2 is a definite collider between 1 and 3
    • getChildren

      public List<Node> getChildren(Node node)

      getChildren.

      Specified by:
      getChildren in interface Graph
      Parameters:
      node - a Node object
      Returns:
      a mutable list of children for a node.
    • getDegree

      public int getDegree()

      getDegree.

      Specified by:
      getDegree in interface Graph
      Returns:
      a int
    • getEdge

      public Edge getEdge(Node node1, Node node2)

      getEdge.

      Specified by:
      getEdge in interface Graph
      Parameters:
      node1 - a Node object
      node2 - a Node object
      Returns:
      the edge connecting node1 and node2, provided a unique such edge exists.
    • getDirectedEdge

      public Edge getDirectedEdge(Node node1, Node node2)

      getDirectedEdge.

      Specified by:
      getDirectedEdge in interface Graph
      Parameters:
      node1 - a Node object
      node2 - a Node object
      Returns:
      the directed edge from node1 to node2, if there is one.
    • getParents

      public List<Node> getParents(Node node)

      getParents.

      Specified by:
      getParents in interface Graph
      Parameters:
      node - a Node object
      Returns:
      the list of parents for a node.
    • getIndegree

      public int getIndegree(Node node)

      getIndegree.

      Specified by:
      getIndegree in interface Graph
      Parameters:
      node - a Node object
      Returns:
      the number of arrow endpoints adjacent to a node.
    • getDegree

      public int getDegree(Node node)

      getDegree.

      Specified by:
      getDegree in interface Graph
      Parameters:
      node - a Node object
      Returns:
      the number of arrow endpoints adjacent to a node.
    • getOutdegree

      public int getOutdegree(Node node)

      getOutdegree.

      Specified by:
      getOutdegree in interface Graph
      Parameters:
      node - a Node object
      Returns:
      the number of null endpoints adjacent to an edge.
    • isAdjacentTo

      public boolean isAdjacentTo(Node node1, Node node2)

      isAdjacentTo.

      Specified by:
      isAdjacentTo in interface Graph
      Parameters:
      node1 - a Node object
      node2 - a Node object
      Returns:
      true iff node1 is adjacent to node2 in the graph.
    • isChildOf

      public boolean isChildOf(Node node1, Node node2)

      isChildOf.

      Specified by:
      isChildOf in interface Graph
      Parameters:
      node1 - a Node object
      node2 - a Node object
      Returns:
      true iff node1 is a child of node2 in the graph.
    • isParentOf

      public boolean isParentOf(Node node1, Node node2)
      Determines whether node1 is a parent of node2.
      Specified by:
      isParentOf in interface Graph
      Parameters:
      node1 - a Node object
      node2 - a Node object
      Returns:
      a boolean
    • transferNodesAndEdges

      public void transferNodesAndEdges(Graph graph) throws IllegalArgumentException
      Transfers nodes and edges from one graph to another. One way this is used is to change graph types. One constructs a new graph based on the old graph, and this method is called to transfer the nodes and edges of the old graph to the new graph.
      Specified by:
      transferNodesAndEdges in interface Graph
      Parameters:
      graph - the graph from which nodes and edges are to be pilfered.
      Throws:
      IllegalArgumentException - This exception is thrown if adding some node.
    • transferAttributes

      public void transferAttributes(Graph graph) throws IllegalArgumentException

      transferAttributes.

      Specified by:
      transferAttributes in interface Graph
      Parameters:
      graph - a Graph object
      Throws:
      IllegalArgumentException - if any.
    • paths

      public Paths paths()

      paths.

      Specified by:
      paths in interface Graph
      Returns:
      a Paths object
    • isParameterizable

      public boolean isParameterizable(Node node)

      isParameterizable.

      Specified by:
      isParameterizable in interface Graph
      Parameters:
      node - a Node object
      Returns:
      true if the given node is parameterizable.
    • isTimeLagModel

      public boolean isTimeLagModel()

      isTimeLagModel.

      Specified by:
      isTimeLagModel in interface Graph
      Returns:
      a boolean
    • getTimeLagGraph

      public TimeLagGraph getTimeLagGraph()

      getTimeLagGraph.

      Specified by:
      getTimeLagGraph in interface Graph
      Returns:
      a TimeLagGraph object
    • getSepset

      public Set<Node> getSepset(Node n1, Node n2)

      getSepset.

      Specified by:
      getSepset in interface Graph
      Parameters:
      n1 - a Node object
      n2 - a Node object
      Returns:
      a Set object
    • isExogenous

      public boolean isExogenous(Node node)

      isExogenous.

      Specified by:
      isExogenous in interface Graph
      Parameters:
      node - a Node object
      Returns:
      true iff the given node is exogenous in the graph.
    • getAdjacentNodes

      public List<Node> getAdjacentNodes(Node node)

      getAdjacentNodes.

      Specified by:
      getAdjacentNodes in interface Graph
      Parameters:
      node - a Node object
      Returns:
      a mutable list of nodes adjacent to the given node.
    • getEndpoint

      public Endpoint getEndpoint(Node node1, Node node2)

      getEndpoint.

      Specified by:
      getEndpoint in interface Graph
      Parameters:
      node1 - a Node object
      node2 - a Node object
      Returns:
      the endpoint along the edge from node to node2 at the node2 end.
    • setEndpoint

      public boolean setEndpoint(Node from, Node to, Endpoint endPoint) throws IllegalArgumentException
      Sets the endpoint type at the 'to' end of the edge from 'from' to 'to' to the given endpoint. Note: NOT CONSTRAINT SAFE
      Specified by:
      setEndpoint in interface Graph
      Parameters:
      from - a Node object
      to - a Node object
      endPoint - a Endpoint object
      Returns:
      a boolean
      Throws:
      IllegalArgumentException
    • getNodesInTo

      public List<Node> getNodesInTo(Node node, Endpoint endpoint)
      Nodes adjacent to the given node with the given proximal endpoint.
      Specified by:
      getNodesInTo in interface Graph
      Parameters:
      node - a Node object
      endpoint - a Endpoint object
      Returns:
      a List object
    • getNodesOutTo

      public List<Node> getNodesOutTo(Node node, Endpoint endpoint)
      Nodes adjacent to the given node with the given distal endpoint.
      Specified by:
      getNodesOutTo in interface Graph
      Parameters:
      node - a Node object
      endpoint - a Endpoint object
      Returns:
      a List object
    • addPropertyChangeListener

      public void addPropertyChangeListener(PropertyChangeListener l)
      Adds a PropertyChangeListener to the graph.
      Specified by:
      addPropertyChangeListener in interface Graph
      Parameters:
      l - a PropertyChangeListener object
    • getEdges

      public Set<Edge> getEdges()

      getEdges.

      Specified by:
      getEdges in interface Graph
      Returns:
      a Set object
    • containsEdge

      public boolean containsEdge(Edge edge)
      Determines whether this graph contains the given edge.
      Specified by:
      containsEdge in interface Graph
      Parameters:
      edge - a Edge object
      Returns:
      true iff the graph contain 'edge'.
    • containsNode

      public boolean containsNode(Node node)
      Determines whether this graph contains the given node.
      Specified by:
      containsNode in interface Graph
      Parameters:
      node - a Node object
      Returns:
      true iff the graph contains 'node'.
    • getEdges

      public List<Edge> getEdges(Node node)

      getEdges.

      Specified by:
      getEdges in interface Graph
      Parameters:
      node - a Node object
      Returns:
      the list of edges connected to a particular node. No particular ordering of the edges in the list is guaranteed.
    • getEdges

      public List<Edge> getEdges(Node node1, Node node2)

      getEdges.

      Specified by:
      getEdges in interface Graph
      Parameters:
      node1 - a Node object
      node2 - a Node object
      Returns:
      the edges connecting node1 and node2.
    • hashCode

      public int hashCode()

      hashCode.

      Overrides:
      hashCode in class Object
      Returns:
      a int
    • equals

      public boolean equals(Object o)
      Determines whether this graph is equal to some other graph, in the sense that they contain the same nodes and the sets of edges defined over these nodes in the two graphs are isomorphic typewise. That is, if node A and B exist in both graphs, and if there are, e.g., three edges between A and B in the first graph, two of which are directed edges and one of which is an undirected edge, then in the second graph there must also be two directed edges and one undirected edge between nodes A and B.
      Specified by:
      equals in interface Graph
      Overrides:
      equals in class Object
      Parameters:
      o - a Object object
      Returns:
      a boolean
    • fullyConnect

      public void fullyConnect(Endpoint endpoint)
      Removes all edges from the graph and fully connects it using #-# edges, where # is the given endpoint.
      Specified by:
      fullyConnect in interface Graph
      Parameters:
      endpoint - a Endpoint object
    • reorientAllWith

      public void reorientAllWith(Endpoint endpoint)
      Reorients all edges in the graph with the given endpoint.
      Specified by:
      reorientAllWith in interface Graph
      Parameters:
      endpoint - a Endpoint object
    • getNode

      public Node getNode(String name)

      getNode.

      Specified by:
      getNode in interface Graph
      Parameters:
      name - a String object
      Returns:
      the node with the given string name. In case of accidental duplicates, the first node encountered with the given name is returned. In case no node exists with the given name, null is returned.
    • getNumNodes

      public int getNumNodes()

      getNumNodes.

      Specified by:
      getNumNodes in interface Graph
      Returns:
      a int
    • getNumEdges

      public int getNumEdges()

      getNumEdges.

      Specified by:
      getNumEdges in interface Graph
      Returns:
      a int
    • getNumEdges

      public int getNumEdges(Node node)

      getNumEdges.

      Specified by:
      getNumEdges in interface Graph
      Parameters:
      node - a Node object
      Returns:
      the number of edges in the graph which are connected to a particular node.
    • subgraph

      public Graph subgraph(List<Node> nodes)
      Constructs and returns a subgraph consisting of a given subset of the nodes of this graph together with the edges between them.
      Specified by:
      subgraph in interface Graph
      Parameters:
      nodes - a List object
      Returns:
      a Graph object
    • getNodes

      public List<Node> getNodes()

      getNodes.

      Specified by:
      getNodes in interface Graph
      Returns:
      a List object
    • setNodes

      public void setNodes(List<Node> nodes)

      setNodes.

      Specified by:
      setNodes in interface Graph
      Parameters:
      nodes - a List object
    • getNodeNames

      public List<String> getNodeNames()

      getNodeNames.

      Specified by:
      getNodeNames in interface Graph
      Returns:
      a List object
    • clear

      public void clear()

      clear.

      Specified by:
      clear in interface Graph
    • removeEdge

      public boolean removeEdge(Node node1, Node node2)
      Removes the edge connecting the two given nodes, provided there is exactly one such edge.
      Specified by:
      removeEdge in interface Graph
      Parameters:
      node1 - a Node object
      node2 - a Node object
      Returns:
      a boolean
    • removeEdges

      public boolean removeEdges(Collection<Edge> edges)
      Iterates through the list and removes any permissible edges found. The order in which edges are added is the order in which they are presented in the iterator.
      Specified by:
      removeEdges in interface Graph
      Parameters:
      edges - a Collection object
      Returns:
      true if edges were added, false if not.
    • removeNodes

      public boolean removeNodes(List<Node> nodes)
      Iterates through the list and removes any permissible nodes found. The order in which nodes are removed is the order in which they are presented in the iterator.
      Specified by:
      removeNodes in interface Graph
      Parameters:
      nodes - a List object
      Returns:
      true if nodes were added, false if not.
    • removeEdges

      public boolean removeEdges(Node node1, Node node2)
      Removes all edges connecting node A to node B. In most cases, this will remove at most one edge, but since multiple edges are permitted in some graph implementations, the number will in some cases be greater than one.
      Specified by:
      removeEdges in interface Graph
      Parameters:
      node1 - a Node object
      node2 - a Node object
      Returns:
      true if edges were removed, false if not.
    • getAllAttributes

      public Map<String,Object> getAllAttributes()

      getAllAttributes.

      Specified by:
      getAllAttributes in interface Graph
      Returns:
      a Map object
    • getAttribute

      public Object getAttribute(String key)

      getAttribute.

      Specified by:
      getAttribute in interface Graph
      Parameters:
      key - a String object
      Returns:
      a Object object
    • removeAttribute

      public void removeAttribute(String key)

      removeAttribute.

      Specified by:
      removeAttribute in interface Graph
      Parameters:
      key - a String object
    • addAttribute

      public void addAttribute(String key, Object value)

      addAttribute.

      Specified by:
      addAttribute in interface Graph
      Parameters:
      key - a String object
      value - a Object object
    • getAmbiguousTriples

      public Set<Triple> getAmbiguousTriples()

      Getter for the field ambiguousTriples.

      Specified by:
      getAmbiguousTriples in interface Graph
      Returns:
      a Set object
    • setAmbiguousTriples

      public void setAmbiguousTriples(Set<Triple> triples)

      setAmbiguousTriples.

      Specified by:
      setAmbiguousTriples in interface Graph
      Parameters:
      triples - a Set object
    • getUnderLines

      public Set<Triple> getUnderLines()

      getUnderLines.

      Specified by:
      getUnderLines in interface Graph
      Returns:
      a Set object
    • getDottedUnderlines

      public Set<Triple> getDottedUnderlines()

      getDottedUnderlines.

      Specified by:
      getDottedUnderlines in interface Graph
      Returns:
      a Set object
    • isAmbiguousTriple

      public boolean isAmbiguousTriple(Node x, Node y, Node z)
      States whether r-s-r is an underline triple or not.

      States whether r-s-r is an underline triple or not.

      Specified by:
      isAmbiguousTriple in interface Graph
      Parameters:
      x - a Node object
      y - a Node object
      z - a Node object
      Returns:
      a boolean
    • isUnderlineTriple

      public boolean isUnderlineTriple(Node x, Node y, Node z)
      States whether r-s-r is an underline triple or not.

      States whether r-s-r is an underline triple or not.

      Specified by:
      isUnderlineTriple in interface Graph
      Parameters:
      x - a Node object
      y - a Node object
      z - a Node object
      Returns:
      a boolean
    • addAmbiguousTriple

      public void addAmbiguousTriple(Node x, Node y, Node z)

      addAmbiguousTriple.

      Specified by:
      addAmbiguousTriple in interface Graph
      Parameters:
      x - a Node object
      y - a Node object
      z - a Node object
    • addUnderlineTriple

      public void addUnderlineTriple(Node x, Node y, Node z)

      addUnderlineTriple.

      Specified by:
      addUnderlineTriple in interface Graph
      Parameters:
      x - a Node object
      y - a Node object
      z - a Node object
    • addDottedUnderlineTriple

      public void addDottedUnderlineTriple(Node x, Node y, Node z)

      addDottedUnderlineTriple.

      Specified by:
      addDottedUnderlineTriple in interface Graph
      Parameters:
      x - a Node object
      y - a Node object
      z - a Node object
    • removeAmbiguousTriple

      public void removeAmbiguousTriple(Node x, Node y, Node z)

      removeAmbiguousTriple.

      Specified by:
      removeAmbiguousTriple in interface Graph
      Parameters:
      x - a Node object
      y - a Node object
      z - a Node object
    • removeUnderlineTriple

      public void removeUnderlineTriple(Node x, Node y, Node z)

      removeUnderlineTriple.

      Specified by:
      removeUnderlineTriple in interface Graph
      Parameters:
      x - a Node object
      y - a Node object
      z - a Node object
    • removeDottedUnderlineTriple

      public void removeDottedUnderlineTriple(Node x, Node y, Node z)

      removeDottedUnderlineTriple.

      Specified by:
      removeDottedUnderlineTriple in interface Graph
      Parameters:
      x - a Node object
      y - a Node object
      z - a Node object
    • setUnderLineTriples

      public void setUnderLineTriples(Set<Triple> triples)

      setUnderLineTriples.

      Specified by:
      setUnderLineTriples in interface Graph
      Parameters:
      triples - a Set object
    • setDottedUnderLineTriples

      public void setDottedUnderLineTriples(Set<Triple> triples)

      setDottedUnderLineTriples.

      Specified by:
      setDottedUnderLineTriples in interface Graph
      Parameters:
      triples - a Set object
    • removeTriplesNotInGraph

      public void removeTriplesNotInGraph()

      removeTriplesNotInGraph.

      Specified by:
      removeTriplesNotInGraph in interface Graph