Class TeyssierScorer

java.lang.Object
edu.cmu.tetrad.search.TeyssierScorer

public class TeyssierScorer extends Object
Implements a scorer extending Teyssier, M., and Koller, D. (2012). Ordering-based search: A simple and effective algorithm for learning Bayesian networks. arXiv preprint arXiv:1207.1429. You give it a score function and a variable ordering, and it computes the score. You can move any variable left or right, and it will keep track of the score using the Teyssier and Kohler method. You can move a variable to a new position, and you can bookmark a state and come back to it.
Author:
josephramsey, bryanandrews
  • Constructor Details

  • Method Details

    • moveToEnd

      public void moveToEnd(Node z)
    • setUseScore

      public void setUseScore(boolean useScore)
      Parameters:
      useScore - True if the score should be used; false if the test should be used.
    • setCachingScores

      public void setCachingScores(boolean cachingScores)
      Parameters:
      cachingScores - True if scores should be cached (potentially expensive for memory); false if not (potentially expensive for time).
    • setKnowledge

      public void setKnowledge(Knowledge knowledge)
      Parameters:
      knowledge - Knowledge of forbidden edges.
    • setUseRaskuttiUhler

      public void setUseRaskuttiUhler(boolean useRaskuttiUhler)
      Parameters:
      useRaskuttiUhler - True if Pearl's method for building a DAG should be used.
    • setUseBackwardScoring

      public void setUseBackwardScoring(boolean useBackwardScoring)
    • score

      public double score(List<Node> order, Graph mag)
    • score

      public double score(List<Node> order)
      Scores the given permutation. This needs to be done initially before any move or tuck operations are performed.
      Parameters:
      order - The permutation to score.
      Returns:
      The score of it.
    • score

      public double score()
      Returns:
      The score of the current permutation.
    • swaptuck

      public boolean swaptuck(Node x, Node y, Node z, boolean doZ)
      Performs a tuck operation.
    • swaptuck

      public boolean swaptuck(Node x, Node y)
    • tuckWithoutMovingAncestors

      public void tuckWithoutMovingAncestors(Node x, Node y)
    • tuck

      public boolean tuck(Node k, Node j)
    • tuck

      public boolean tuck(Node k, int j)
    • moveTo

      public void moveTo(Node v, int toIndex)
      Moves v to a new index.
      Parameters:
      v - The variable to move.
      toIndex - The index to move v to.
    • swap

      public boolean swap(Node m, Node n)
      Swaps m and n in the permutation.
      Parameters:
      m - The first variable.
      n - The second variable.
      Returns:
      True iff the swap was done.
    • coveredEdge

      public boolean coveredEdge(Node x, Node y)
      Returns true iff x->y or y->x is a covered edge. x->y is a covered edge if parents(x) = parents(y) \ {x}
      Parameters:
      x - The first variable.
      y - The second variable.
      Returns:
      True iff x->y or y->x is a covered edge.
    • getPi

      public List<Node> getPi()
      Returns:
      A copy of the current permutation.
    • getOrderShallow

      public List<Node> getOrderShallow()
      Returns the current permutation without making a copy. Could be dangerous!
      Returns:
      the current permutation.
    • index

      public int index(Node v)
      Return the index of v in the current permutation.
      Parameters:
      v - The variable.
      Returns:
      Its index.
    • getParents

      public Set<Node> getParents(int p)
      Returns the parents of the node at index p.
      Parameters:
      p - The index of the node.
      Returns:
      Its parents.
    • getChildren

      public Set<Node> getChildren(int p)
    • getParents

      public Set<Node> getParents(Node v)
      Returns the parents of a node v.
      Parameters:
      v - The variable.
      Returns:
      Its parents.
    • getChildren

      public Set<Node> getChildren(Node v)
    • getAdjacentNodes

      public Set<Node> getAdjacentNodes(Node v)
      Returns the nodes adjacent to v.
      Parameters:
      v - The variable.
      Returns:
      Its adjacent nodes.
    • getAncestralNodes

      public Set<Node> getAncestralNodes(Node v)
    • getGraph

      public Graph getGraph(boolean cpDag)
      Returns the DAG build for the current permutation, or its CPDAG.
      Parameters:
      cpDag - True iff the CPDAG should be returned, False if the DAG.
      Returns:
      This graph.
    • orientbk

      public void orientbk(Knowledge bk, Graph graph, List<Node> variables)
    • findCompelled

      public Graph findCompelled()
    • getAdjacencies

      public List<NodePair> getAdjacencies()
      Returns a list of adjacent node pairs in the current graph.
      Returns:
      This list.
    • getAdjMap

      public Map<Node,Set<Node>> getAdjMap()
    • getChildMap

      public Map<Node,Set<Node>> getChildMap()
    • getAncestors

      public Set<Node> getAncestors(Node node)
    • getDescendants

      public Set<Node> getDescendants(Node node)
    • getEdges

      public List<OrderedPair<Node>> getEdges()
      Returns a list of edges for the current graph as a list of ordered pairs.
      Returns:
      This list.
    • getNumEdges

      public int getNumEdges()
      Returns:
      The number of edges in the current graph.
    • get

      public Node get(int j)
      Returns the node at index j in pi.
      Parameters:
      j - The index.
      Returns:
      The node at that index.
    • bookmark

      public void bookmark(int key)
      Bookmarks the current pi as index key.
      Parameters:
      key - This bookmark may be retrieved using the index 'key', an integer. This bookmark will be stored until it is retrieved and then removed.
    • bookmark

      public void bookmark()
      Bookmarks the current pi with index Integer.MIN_VALUE.
    • goToBookmark

      public void goToBookmark(int key)
      Retrieves the bookmarked state for index 'key' and removes that bookmark.
      Parameters:
      key - The integer key for this bookmark.
    • goToBookmark

      public void goToBookmark()
      Retries the bookmark with key = Integer.MIN_VALUE and removes the bookmark.
    • clearBookmarks

      public void clearBookmarks()
      Clears all bookmarks.
    • size

      public int size()
      Returns:
      The size of pi, the current permutation.
    • shuffleVariables

      public void shuffleVariables()
      Shuffles the current permutation and rescores it.
    • getShuffledVariables

      public List<Node> getShuffledVariables()
    • adjacent

      public boolean adjacent(Node a, Node b)
      Returns True iff a is adjacent to b in the current graph.
      Parameters:
      a - The first node.
      b - The second node.
      Returns:
      True iff adj(a, b).
    • ancestorAdjacent

      public boolean ancestorAdjacent(Node a, Node b)
    • collider

      public boolean collider(Node a, Node b, Node c)
      Returns true iff [a, b, c] is a collider.
      Parameters:
      a - The first node.
      b - The second node.
      c - The third node.
      Returns:
      True iff a->b<-c in the current DAG.
    • ancestralCollider

      public boolean ancestralCollider(Node a, Node b, Node c)
    • triangle

      public boolean triangle(Node a, Node b, Node c)
      Returns true iff [a, b, c] is a triangle.
      Parameters:
      a - The first node.
      b - The second node.
      c - The third node.
      Returns:
      True iff adj(a, b) and adj(b, c) and adj(a, c).
    • clique

      public boolean clique(List<Node> W)
      True iff the nodes in W form a clique in the current DAG.
      Parameters:
      W - The nodes.
      Returns:
      True iff these nodes form a clique.
    • getPrefix

      public Set<Node> getPrefix(int i)
    • getScoreObject

      public Score getScoreObject()
    • getTestObject

      public IndependenceTest getTestObject()
    • getSkeleton

      public Set<Set<Node>> getSkeleton()
    • parent

      public boolean parent(Node k, Node j)