Class Knowledge

java.lang.Object
edu.cmu.tetrad.data.Knowledge
All Implemented Interfaces:
TetradSerializable, Serializable

public final class Knowledge extends Object implements TetradSerializable
Stores information about required and forbidden edges and common causes for use in algorithm. This information can be set edge by edge or else globally via temporal tiers. When setting temporal tiers, all edges from later tiers to earlier tiers are forbidden.

For this class, all variable names are referenced by name only. This is because the same Knowledge object is intended to plug into different graphs with MyNodes that possibly have the same names. Thus, if the Knowledge object forbids the edge X --> Y, then it forbids any edge which connects a MyNode named "X" to a MyNode named "Y", even if the underlying MyNodes themselves named "X" and "Y", respectively, are not the same.

In place of variable names, wildcard expressions containing the wildcard '*' may be substituted. These will be matched to as many myNodes as possible. The '*' wildcard matches any string of consecutive characters up until the following character is encountered. Thus, "X*a" will match "X123a" and "X45a".

Author:
josephramsey, Kevin V. Bui (kvb2@pitt.edu)
See Also:
  • Constructor Details

    • Knowledge

      public Knowledge()
    • Knowledge

      public Knowledge(Collection<String> nodes)
    • Knowledge

      public Knowledge(Knowledge knowledge)
  • Method Details

    • serializableInstance

      public static Knowledge serializableInstance()
      Generates a simple exemplar of this class to test serialization.
    • addToTier

      public void addToTier(int tier, String spec)
      Adds the given variable or wildcard cpdag to the given tier. The tier is a non-negative integer.
    • addToTiersByVarNames

      public void addToTiersByVarNames(List<String> varNames)
      Puts a variable into tier i if its name is xxx:ti for some xxx and some i.
    • addKnowledgeGroup

      public void addKnowledgeGroup(KnowledgeGroup group)
      Adds a knowledge group. Legacy method, replaced by setForbidden, setRequired with cpdags. Needed for the interface.
    • addVariable

      public void addVariable(String varName)
    • clear

      public void clear()
      Removes explicit knowledge and tier information.
    • forbiddenEdgesIterator

      public Iterator<KnowledgeEdge> forbiddenEdgesIterator()
      Iterator over the KnowledgeEdge's representing forbidden edges.
    • getKnowledgeGroups

      public List<KnowledgeGroup> getKnowledgeGroups()
      Returns:
      a shallow copy of the list of group rules.
    • getVariables

      public List<String> getVariables()
      Get a list of variables.
      Returns:
      a copy of the list of variable, in alphabetical order.
    • getVariablesNotInTiers

      public List<String> getVariablesNotInTiers()
      Returns:
      the list of edges not in any tier.
    • getTier

      public List<String> getTier(int tier)
      Parameters:
      tier - the index of the desired tier
      Returns:
      a copy of this tier
    • getNumTiers

      public int getNumTiers()
      Returns:
      the number of temporal tiers
    • isDefaultToKnowledgeLayout

      public boolean isDefaultToKnowledgeLayout()
    • setDefaultToKnowledgeLayout

      public void setDefaultToKnowledgeLayout(boolean defaultToKnowledgeLayout)
    • isForbidden

      public boolean isForbidden(String var1, String var2)
      Determines whether the edge var1 --> var2 is forbidden.
    • isForbiddenByGroups

      public boolean isForbiddenByGroups(String var1, String var2)
      Legacy.
    • isForbiddenByTiers

      public boolean isForbiddenByTiers(String var1, String var2)
      Determines whether the edge var1 --> var2 is forbidden by the temporal tiers.
    • isRequired

      public boolean isRequired(String var1, String var2)
      Determines whether the edge var1 --> var2 is required.
    • isRequiredByGroups

      public boolean isRequiredByGroups(String var1, String var2)
      Legacy.
    • isEmpty

      public boolean isEmpty()
      true if there is no background knowledge recorded.
    • isTierForbiddenWithin

      public boolean isTierForbiddenWithin(int tier)
      Checks whether it is the case that any variable is forbidden by any other variable within a given tier.
    • isViolatedBy

      public boolean isViolatedBy(Graph graph)
    • noEdgeRequired

      public boolean noEdgeRequired(String x, String y)
    • removeFromTiers

      public void removeFromTiers(String spec)
      Removes the given variable by name or search string from all tiers.
    • removeKnowledgeGroup

      public void removeKnowledgeGroup(int index)
      Removes the knowledge group at the given index.
    • requiredEdgesIterator

      public Iterator<KnowledgeEdge> requiredEdgesIterator()
      Iterator over the KnowledgeEdge's representing required edges.
    • setForbidden

      public void setForbidden(String var1, String var2)
      Marks the edge var1 --> var2 as forbid.
    • removeForbidden

      public void removeForbidden(String var1, String var2)
      Marks the edge var1 --> var2 as not forbid.
    • setRequired

      public void setRequired(String var1, String var2)
      Marks the edge var1 --> var2 as required.
    • removeRequired

      public void removeRequired(String var1, String var2)
      Marks the edge var1 --> var2 as not required.
    • setKnowledgeGroup

      public void setKnowledgeGroup(int index, KnowledgeGroup group)
      Legacy, do not use.
    • setTier

      public void setTier(int tier, List<String> vars)
      Sets the variable in a given tier to the specified list.
    • setTierForbiddenWithin

      public void setTierForbiddenWithin(int tier, boolean forbidden)
      Forbids any variable from being parent of any other variable within the given tier, or cancels this forbidding.
    • getMaxTierForbiddenWithin

      public int getMaxTierForbiddenWithin()
      Returns:
      the largest indes of a tier in which every variable is forbidden by every other variable, or -1 if there is not such tier.
    • copy

      public Knowledge copy()
      Makes a shallow copy.
    • isInWhichTier

      public int isInWhichTier(Node node)
      Returns the index of the tier of node if it's in a tier, otherwise -1.
    • getListOfRequiredEdges

      public List<KnowledgeEdge> getListOfRequiredEdges()
    • getListOfExplicitlyRequiredEdges

      public List<KnowledgeEdge> getListOfExplicitlyRequiredEdges()
    • getListOfForbiddenEdges

      public List<KnowledgeEdge> getListOfForbiddenEdges()
    • getListOfExplicitlyForbiddenEdges

      public List<KnowledgeEdge> getListOfExplicitlyForbiddenEdges()
    • isOnlyCanCauseNextTier

      public boolean isOnlyCanCauseNextTier(int tier)
    • setOnlyCanCauseNextTier

      public void setOnlyCanCauseNextTier(int tier, boolean onlyCausesNext)
    • hashCode

      public int hashCode()
      Computes a hashcode.
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Two Knowledge objects are equal just in case their forbidden and required edges are equal, and their tiers are equal.
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
      Returns:
      the contents of this Knowledge object in String form.