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".

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

    • Knowledge

      public Knowledge()

      Constructor for Knowledge.

    • Knowledge

      public Knowledge(Collection<String> nodes)

      Constructor for Knowledge.

      Parameters:
      nodes - a Collection object
    • Knowledge

      public Knowledge(Knowledge knowledge)

      Constructor for Knowledge.

      Parameters:
      knowledge - a Knowledge object
  • Method Details

    • serializableInstance

      public static Knowledge serializableInstance()
      Generates a simple exemplar of this class to test serialization.
      Returns:
      a Knowledge object
    • 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.
      Parameters:
      tier - a int
      spec - a String object
    • 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.
      Parameters:
      varNames - a List object
    • addKnowledgeGroup

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

      public void addVariable(String varName)

      addVariable.

      Parameters:
      varName - a String object
    • clear

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

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

      public List<KnowledgeGroup> getKnowledgeGroups()

      Getter for the field knowledgeGroups.

      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()

      getVariablesNotInTiers.

      Returns:
      the list of edges not in any tier.
    • getTier

      public List<String> getTier(int tier)

      getTier.

      Parameters:
      tier - the index of the desired tier
      Returns:
      a copy of this tier
    • getNumTiers

      public int getNumTiers()

      getNumTiers.

      Returns:
      the number of temporal tiers
    • isDefaultToKnowledgeLayout

      public boolean isDefaultToKnowledgeLayout()

      isDefaultToKnowledgeLayout.

      Returns:
      a boolean
    • setDefaultToKnowledgeLayout

      public void setDefaultToKnowledgeLayout(boolean defaultToKnowledgeLayout)

      Setter for the field defaultToKnowledgeLayout.

      Parameters:
      defaultToKnowledgeLayout - a boolean
    • isForbidden

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

      public boolean isForbiddenByGroups(String var1, String var2)
      Legacy.
      Parameters:
      var1 - a String object
      var2 - a String object
      Returns:
      a boolean
    • isForbiddenByTiers

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

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

      public boolean isRequiredByGroups(String var1, String var2)
      Legacy.
      Parameters:
      var1 - a String object
      var2 - a String object
      Returns:
      a boolean
    • isEmpty

      public boolean isEmpty()
      true if there is no background knowledge recorded.
      Returns:
      a boolean
    • 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.
      Parameters:
      tier - a int
      Returns:
      a boolean
    • isViolatedBy

      public boolean isViolatedBy(Graph graph)

      isViolatedBy.

      Parameters:
      graph - a Graph object
      Returns:
      a boolean
    • noEdgeRequired

      public boolean noEdgeRequired(String x, String y)

      noEdgeRequired.

      Parameters:
      x - a String object
      y - a String object
      Returns:
      a boolean
    • removeFromTiers

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

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

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

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

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

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

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

      public void setKnowledgeGroup(int index, KnowledgeGroup group)
      Legacy, do not use.
      Parameters:
      index - a int
      group - a KnowledgeGroup object
    • setTier

      public void setTier(int tier, List<String> vars)
      Sets the variable in a given tier to the specified list.
      Parameters:
      tier - a int
      vars - a List object
    • 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.
      Parameters:
      tier - a int
      forbidden - a boolean
    • getMaxTierForbiddenWithin

      public int getMaxTierForbiddenWithin()

      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.
      Returns:
      a Knowledge object
    • isInWhichTier

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

      public List<KnowledgeEdge> getListOfRequiredEdges()

      getListOfRequiredEdges.

      Returns:
      a List object
    • getListOfExplicitlyRequiredEdges

      public List<KnowledgeEdge> getListOfExplicitlyRequiredEdges()

      getListOfExplicitlyRequiredEdges.

      Returns:
      a List object
    • getListOfForbiddenEdges

      public List<KnowledgeEdge> getListOfForbiddenEdges()

      getListOfForbiddenEdges.

      Returns:
      a List object
    • getListOfExplicitlyForbiddenEdges

      public List<KnowledgeEdge> getListOfExplicitlyForbiddenEdges()

      getListOfExplicitlyForbiddenEdges.

      Returns:
      a List object
    • isOnlyCanCauseNextTier

      public boolean isOnlyCanCauseNextTier(int tier)

      isOnlyCanCauseNextTier.

      Parameters:
      tier - a int
      Returns:
      a boolean
    • setOnlyCanCauseNextTier

      public void setOnlyCanCauseNextTier(int tier, boolean onlyCausesNext)

      setOnlyCanCauseNextTier.

      Parameters:
      tier - a int
      onlyCausesNext - a boolean
    • hashCode

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

      public boolean equals(Object o)
      Compares this Knowledge object with the specified object for equality.
      Overrides:
      equals in class Object
      Parameters:
      o - the object to compare this Knowledge with
      Returns:
      true if the specified object is equal to this Knowledge, false otherwise
    • toString

      public String toString()

      toString.

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