Class DiscreteVariable
- All Implemented Interfaces:
- Variable,- Node,- TetradSerializable,- Serializable,- Comparable<Node>
Represents a discrete variable as a range of integer-valued categories 0, 1, ..., m - 1, where m is the number of categories for the variable. These integer-valued categories may be associated with categories that may be explicitly set. Categories that are not explicitly set take the are set to DataUtils.defaultCategory(i) for category i.
Instances of this class may currently be used only to represent nominal discrete variables. Support for ordinal discrete variables may be added in the future.
Like other variable classes, DiscreteVariable implements the Node interface. The purpose of this is to allow variables to serve as nodes in graphs.
The index value used to indicate missing data is -99.
- Version:
- $Id: $Id
- Author:
- josephramsey
- See Also:
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final intThis is the index in the data which represents missing data internally for this variable.Fields inherited from class edu.cmu.tetrad.data.AbstractVariableLAST_ID
- 
Constructor SummaryConstructorsConstructorDescriptionDiscreteVariable(DiscreteVariable variable) Copy constructor.DiscreteVariable(String name) Builds a discrete variable with the given name and an empty list of categories.DiscreteVariable(String name, int numCategories) Builds a qualitative variable with the given name and number of categories.DiscreteVariable(String name, List<String> categories) Builds a qualitative variable with the given name and array of possible categories.
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddAttribute(String key, Object value) addAttribute.voidAdds a property change listener.booleancheckValue(int category) checkValue.booleanTests whether this variable is equal to the given variable.getAllAttributes.getAttribute(String key) getAttribute.Getter for the fieldcategories.getCategory(int category) getCategory.intGetter for the fieldcenterX.intGetter for the fieldcenterY.intgetIndex.getMissingValueMarker.Getter for the fieldnodeType.Returns the node shape for this node.intgetNumCategories.booleanReturns the selection bias status for this node.inthashCode()hashCode.booleanisAccommodateNewCategories.booleanisCategoryNamesDisplayed.booleanisMissingValue(Object value) Tests whether the given value is the missing data marker.Creates a new node of the same type as this one with the given name.voidremoveAttribute(String key) removeAttribute.static DiscreteVariableGenerates a simple exemplar of this class to test serialization.voidsetCategoryNamesDisplayed(boolean categoryNamesDisplayed) Sets whether categories for this variable should be displayed.voidsetCenter(int centerX, int centerY) Sets the (x, y) coordinates of the center of this node.voidsetCenterX(int centerX) Sets the x coordinate of the center of this node.voidsetCenterY(int centerY) Sets the y coordinate of the center of this node.voidsetNodeType(NodeType nodeType) Sets the node type for this node.voidsetNodeVariableType(NodeVariableType nodeVariableType) Sets the type (domain, interventional status, interventional value..) for this node variablevoidsetSelectionBias(boolean selectionBias) Sets the selection bias status for this node.toString()toString.Methods inherited from class edu.cmu.tetrad.data.AbstractVariablecheckValue, getName, setName
- 
Field Details- 
MISSING_VALUEpublic static final int MISSING_VALUEThis is the index in the data which represents missing data internally for this variable.- See Also:
 
 
- 
- 
Constructor Details- 
DiscreteVariableBuilds a discrete variable with the given name and an empty list of categories. Use this constructor if a variable is needed to represent just a list of integer categories with no categories associated with the categories.- Parameters:
- name- a- Stringobject
 
- 
DiscreteVariableBuilds a qualitative variable with the given name and number of categories. The categories have the form 'category'.- Parameters:
- name- a- Stringobject
- numCategories- a int
 
- 
DiscreteVariableBuilds a qualitative variable with the given name and array of possible categories.- Parameters:
- name- The name of the variable.
- categories- A String[] array of categories, where the categories[i] is the category for index i.
 
- 
DiscreteVariableCopy constructor.- Parameters:
- variable- a- DiscreteVariableobject
 
 
- 
- 
Method Details- 
serializableInstanceGenerates a simple exemplar of this class to test serialization.- Returns:
- a DiscreteVariableobject
 
- 
getIndexgetIndex. - Parameters:
- category- a- Stringobject
- Returns:
- the index of the given String category, or -1 if the category is not a category for this variable.
 
- 
getNumCategoriespublic int getNumCategories()getNumCategories. - Returns:
- the number of possible categories for this variable. If categories are associated, this is just the number of string categories. If no categories are associated, this is the maximum integer in the column.
 
- 
getMissingValueMarkergetMissingValueMarker. - Specified by:
- getMissingValueMarkerin interface- Variable
- Specified by:
- getMissingValueMarkerin class- AbstractVariable
- Returns:
- the missing value marker as an Integer.
 
- 
getCategorygetCategory. - Parameters:
- category- a int
- Returns:
- the variable category specified by the given category.
 
- 
getCategoriesGetter for the field categories.- Returns:
- a copy of the array containing the categories for this variable. The string at index i is the category for index i.
 
- 
checkValuepublic boolean checkValue(int category) checkValue. - Parameters:
- category- a category to be checked
- Returns:
- true if the given category is legal.
 
- 
isMissingValueTests whether the given value is the missing data marker.Tests whether the given value is the missing data marker. Determines whether the given value is the missing value marker. - Specified by:
- isMissingValuein interface- Variable
- Specified by:
- isMissingValuein class- AbstractVariable
- Parameters:
- value- The object value one wants to check as a missing value.
- Returns:
- true iff the given object is equals to getMissingValueMarker().
 
- 
isCategoryNamesDisplayedpublic boolean isCategoryNamesDisplayed()isCategoryNamesDisplayed. - Returns:
- true iff categories for this variable should be displayed.
 
- 
setCategoryNamesDisplayedpublic void setCategoryNamesDisplayed(boolean categoryNamesDisplayed) Sets whether categories for this variable should be displayed.- Parameters:
- categoryNamesDisplayed- a boolean
 
- 
hashCodepublic int hashCode()hashCode. 
- 
equalsTests whether this variable is equal to the given variable.
- 
getNodeTypeGetter for the field nodeType.- Specified by:
- getNodeTypein interface- Node
- Returns:
- a NodeTypeobject
 
- 
setNodeTypeSets the node type for this node.- Specified by:
- setNodeTypein interface- Node
- Parameters:
- nodeType- the node type for this node.
 
- 
setSelectionBiaspublic void setSelectionBias(boolean selectionBias) Description copied from class:AbstractVariableSets the selection bias status for this node.- Specified by:
- setSelectionBiasin interface- Node
- Overrides:
- setSelectionBiasin class- AbstractVariable
- Parameters:
- selectionBias- the selection bias status for this node.
 
- 
getSelectionBiaspublic boolean getSelectionBias()Description copied from interface:NodeReturns the selection bias status for this node.- Specified by:
- getSelectionBiasin interface- Node
- Returns:
- the selection bias status for this node.
 
- 
isAccommodateNewCategoriespublic boolean isAccommodateNewCategories()isAccommodateNewCategories. - Returns:
- a boolean
 
- 
getCenterXpublic int getCenterX()Getter for the field centerX.- Specified by:
- getCenterXin interface- Node
- Returns:
- the x coordinate of the center of the node.
 
- 
setCenterXpublic void setCenterX(int centerX) Sets the x coordinate of the center of this node.Sets the x coordinate of the center of this node. - Specified by:
- setCenterXin interface- Node
- Parameters:
- centerX- This coordinate.
 
- 
getCenterYpublic int getCenterY()Getter for the field centerY.- Specified by:
- getCenterYin interface- Node
- Returns:
- the y coordinate of the center of the node.
 
- 
setCenterYpublic void setCenterY(int centerY) Sets the y coordinate of the center of this node.Sets the y coordinate of the center of this node. - Specified by:
- setCenterYin interface- Node
- Parameters:
- centerY- This coordinate.
 
- 
setCenterpublic void setCenter(int centerX, int centerY) Sets the (x, y) coordinates of the center of this node.Sets the (x, y) coordinates of the center of this node. 
- 
addPropertyChangeListenerAdds a property change listener.Adds a property change listener. - Specified by:
- addPropertyChangeListenerin interface- Node
- Parameters:
- l- This listener.
 
- 
toStringtoString. - Specified by:
- toStringin interface- Node
- Overrides:
- toStringin class- AbstractVariable
- Returns:
- the name of the variable followed by its list of categories.
 
- 
likeCreates a new node of the same type as this one with the given name.- Specified by:
- likein interface- Node
- Specified by:
- likein class- AbstractVariable
- Parameters:
- name- the name of the new node.
- Returns:
- the new node.
 
- 
getNodeVariableTypeReturns the node shape for this node.- Specified by:
- getNodeVariableTypein interface- Node
- Returns:
- the intervention type
 
- 
setNodeVariableTypeSets the type (domain, interventional status, interventional value..) for this node variable- Specified by:
- setNodeVariableTypein interface- Node
- Parameters:
- nodeVariableType- the type (domain, interventional status, interventional value..) for this node variable
 
- 
getAllAttributesgetAllAttributes. - Specified by:
- getAllAttributesin interface- Node
- Returns:
- a Mapobject
 
- 
getAttributegetAttribute. - Specified by:
- getAttributein interface- Node
- Parameters:
- key- a- Stringobject
- Returns:
- a Objectobject
 
- 
removeAttributeremoveAttribute. - Specified by:
- removeAttributein interface- Node
- Parameters:
- key- a- Stringobject
 
- 
addAttributeaddAttribute. - Specified by:
- addAttributein interface- Node
- Parameters:
- key- a- Stringobject
- value- a- Objectobject
 
 
-