Package edu.cmu.tetrad.data
Class Knowledge
java.lang.Object
edu.cmu.tetrad.data.Knowledge
- All Implemented Interfaces:
TetradSerializable
,Serializable
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addKnowledgeGroup
(KnowledgeGroup group) Adds a knowledge group.void
Adds the given variable or wildcard cpdag to the given tier.void
addToTiersByVarNames
(List<String> varNames) Puts a variable into tier i if its name is xxx:ti for some xxx and some i.void
addVariable
(String varName) void
clear()
Removes explicit knowledge and tier information.copy()
Makes a shallow copy.boolean
Two Knowledge objects are equal just in case their forbidden and required edges are equal, and their tiers are equal.Iterator over the KnowledgeEdge's representing forbidden edges.int
int
getTier
(int tier) Get a list of variables.int
hashCode()
Computes a hashcode.boolean
boolean
isEmpty()
true if there is no background knowledge recorded.boolean
isForbidden
(String var1, String var2) Determines whether the edge var1 --> var2 is forbidden.boolean
isForbiddenByGroups
(String var1, String var2) Legacy.boolean
isForbiddenByTiers
(String var1, String var2) Determines whether the edge var1 --> var2 is forbidden by the temporal tiers.int
isInWhichTier
(Node node) Returns the index of the tier of node if it's in a tier, otherwise -1.boolean
isOnlyCanCauseNextTier
(int tier) boolean
isRequired
(String var1, String var2) Determines whether the edge var1 --> var2 is required.boolean
isRequiredByGroups
(String var1, String var2) Legacy.boolean
isTierForbiddenWithin
(int tier) Checks whether it is the case that any variable is forbidden by any other variable within a given tier.boolean
isViolatedBy
(Graph graph) boolean
noEdgeRequired
(String x, String y) void
removeForbidden
(String var1, String var2) Marks the edge var1 --> var2 as not forbid.void
removeFromTiers
(String spec) Removes the given variable by name or search string from all tiers.void
removeKnowledgeGroup
(int index) Removes the knowledge group at the given index.void
removeRequired
(String var1, String var2) Marks the edge var1 --> var2 as not required.Iterator over the KnowledgeEdge's representing required edges.static Knowledge
Generates a simple exemplar of this class to test serialization.void
setDefaultToKnowledgeLayout
(boolean defaultToKnowledgeLayout) void
setForbidden
(String var1, String var2) Marks the edge var1 --> var2 as forbid.void
setKnowledgeGroup
(int index, KnowledgeGroup group) Legacy, do not use.void
setOnlyCanCauseNextTier
(int tier, boolean onlyCausesNext) void
setRequired
(String var1, String var2) Marks the edge var1 --> var2 as required.void
Sets the variable in a given tier to the specified list.void
setTierForbiddenWithin
(int tier, boolean forbidden) Forbids any variable from being parent of any other variable within the given tier, or cancels this forbidding.toString()
-
Constructor Details
-
Knowledge
public Knowledge() -
Knowledge
-
Knowledge
-
-
Method Details
-
serializableInstance
Generates a simple exemplar of this class to test serialization. -
addToTier
Adds the given variable or wildcard cpdag to the given tier. The tier is a non-negative integer. -
addToTiersByVarNames
Puts a variable into tier i if its name is xxx:ti for some xxx and some i. -
addKnowledgeGroup
Adds a knowledge group. Legacy method, replaced by setForbidden, setRequired with cpdags. Needed for the interface. -
addVariable
-
clear
public void clear()Removes explicit knowledge and tier information. -
forbiddenEdgesIterator
Iterator over the KnowledgeEdge's representing forbidden edges. -
getKnowledgeGroups
- Returns:
- a shallow copy of the list of group rules.
-
getVariables
Get a list of variables.- Returns:
- a copy of the list of variable, in alphabetical order.
-
getVariablesNotInTiers
- Returns:
- the list of edges not in any tier.
-
getTier
- 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
Determines whether the edge var1 --> var2 is forbidden. -
isForbiddenByGroups
Legacy. -
isForbiddenByTiers
Determines whether the edge var1 --> var2 is forbidden by the temporal tiers. -
isRequired
Determines whether the edge var1 --> var2 is required. -
isRequiredByGroups
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
-
noEdgeRequired
-
removeFromTiers
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
Iterator over the KnowledgeEdge's representing required edges. -
setForbidden
Marks the edge var1 --> var2 as forbid. -
removeForbidden
Marks the edge var1 --> var2 as not forbid. -
setRequired
Marks the edge var1 --> var2 as required. -
removeRequired
Marks the edge var1 --> var2 as not required. -
setKnowledgeGroup
Legacy, do not use. -
setTier
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
Makes a shallow copy. -
isInWhichTier
Returns the index of the tier of node if it's in a tier, otherwise -1. -
getListOfRequiredEdges
-
getListOfExplicitlyRequiredEdges
-
getListOfForbiddenEdges
-
getListOfExplicitlyForbiddenEdges
-
isOnlyCanCauseNextTier
public boolean isOnlyCanCauseNextTier(int tier) -
setOnlyCanCauseNextTier
public void setOnlyCanCauseNextTier(int tier, boolean onlyCausesNext) -
hashCode
public int hashCode()Computes a hashcode. -
equals
Two Knowledge objects are equal just in case their forbidden and required edges are equal, and their tiers are equal. -
toString
-