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 Summary
FieldsModifier and TypeFieldDescriptionstatic final int
This is the index in the data which represents missing data internally for this variable.Fields inherited from class edu.cmu.tetrad.data.AbstractVariable
LAST_ID
-
Constructor Summary
ConstructorsConstructorDescriptionDiscreteVariable
(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 Summary
Modifier and TypeMethodDescriptionvoid
addAttribute
(String key, Object value) addAttribute.void
Adds a property change listener.boolean
checkValue
(int category) checkValue.boolean
Tests whether this variable is equal to the given variable.getAllAttributes.getAttribute
(String key) getAttribute.Getter for the fieldcategories
.getCategory
(int category) getCategory.int
Getter for the fieldcenterX
.int
Getter for the fieldcenterY
.int
getIndex.getMissingValueMarker.Getter for the fieldnodeType
.Returns the node shape for this node.int
getNumCategories.boolean
Returns the selection bias status for this node.int
hashCode()
hashCode.boolean
isAccommodateNewCategories.boolean
isCategoryNamesDisplayed.boolean
isMissingValue
(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.void
removeAttribute
(String key) removeAttribute.static DiscreteVariable
Generates a simple exemplar of this class to test serialization.void
setCategoryNamesDisplayed
(boolean categoryNamesDisplayed) Sets whether categories for this variable should be displayed.void
setCenter
(int centerX, int centerY) Sets the (x, y) coordinates of the center of this node.void
setCenterX
(int centerX) Sets the x coordinate of the center of this node.void
setCenterY
(int centerY) Sets the y coordinate of the center of this node.void
setNodeType
(NodeType nodeType) Sets the node type for this node.void
setNodeVariableType
(NodeVariableType nodeVariableType) Sets the type (domain, interventional status, interventional value..) for this node variablevoid
setSelectionBias
(boolean selectionBias) Sets the selection bias status for this node.toString()
toString.Methods inherited from class edu.cmu.tetrad.data.AbstractVariable
checkValue, getName, setName
-
Field Details
-
MISSING_VALUE
public static final int MISSING_VALUEThis is the index in the data which represents missing data internally for this variable.- See Also:
-
-
Constructor Details
-
DiscreteVariable
-
DiscreteVariable
-
DiscreteVariable
-
DiscreteVariable
Copy constructor.- Parameters:
variable
- aDiscreteVariable
object
-
-
Method Details
-
serializableInstance
Generates a simple exemplar of this class to test serialization.- Returns:
- a
DiscreteVariable
object
-
getIndex
-
getNumCategories
public 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.
-
getMissingValueMarker
getMissingValueMarker.
- Specified by:
getMissingValueMarker
in interfaceVariable
- Specified by:
getMissingValueMarker
in classAbstractVariable
- Returns:
- the missing value marker as an Integer.
-
getCategory
getCategory.
- Parameters:
category
- a int- Returns:
- the variable category specified by the given category.
-
getCategories
-
checkValue
public boolean checkValue(int category) checkValue.
- Parameters:
category
- a category to be checked- Returns:
- true if the given category is legal.
-
isMissingValue
Tests 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:
isMissingValue
in interfaceVariable
- Specified by:
isMissingValue
in classAbstractVariable
- Parameters:
value
- The object value one wants to check as a missing value.- Returns:
- true iff the given object is equals to
getMissingValueMarker()
.
-
isCategoryNamesDisplayed
public boolean isCategoryNamesDisplayed()isCategoryNamesDisplayed.
- Returns:
- true iff categories for this variable should be displayed.
-
setCategoryNamesDisplayed
public void setCategoryNamesDisplayed(boolean categoryNamesDisplayed) Sets whether categories for this variable should be displayed.- Parameters:
categoryNamesDisplayed
- a boolean
-
hashCode
-
equals
-
getNodeType
Getter for the field
nodeType
.- Specified by:
getNodeType
in interfaceNode
- Returns:
- a
NodeType
object
-
setNodeType
Sets the node type for this node.- Specified by:
setNodeType
in interfaceNode
- Parameters:
nodeType
- the node type for this node.
-
setSelectionBias
public void setSelectionBias(boolean selectionBias) Description copied from class:AbstractVariable
Sets the selection bias status for this node.- Specified by:
setSelectionBias
in interfaceNode
- Overrides:
setSelectionBias
in classAbstractVariable
- Parameters:
selectionBias
- the selection bias status for this node.
-
getSelectionBias
public boolean getSelectionBias()Description copied from interface:Node
Returns the selection bias status for this node.- Specified by:
getSelectionBias
in interfaceNode
- Returns:
- the selection bias status for this node.
-
isAccommodateNewCategories
public boolean isAccommodateNewCategories()isAccommodateNewCategories.
- Returns:
- a boolean
-
getCenterX
public int getCenterX()Getter for the field
centerX
.- Specified by:
getCenterX
in interfaceNode
- Returns:
- the x coordinate of the center of the node.
-
setCenterX
public 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:
setCenterX
in interfaceNode
- Parameters:
centerX
- This coordinate.
-
getCenterY
public int getCenterY()Getter for the field
centerY
.- Specified by:
getCenterY
in interfaceNode
- Returns:
- the y coordinate of the center of the node.
-
setCenterY
public 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:
setCenterY
in interfaceNode
- Parameters:
centerY
- This coordinate.
-
setCenter
-
addPropertyChangeListener
Adds a property change listener.Adds a property change listener.
- Specified by:
addPropertyChangeListener
in interfaceNode
- Parameters:
l
- This listener.
-
toString
toString.
- Specified by:
toString
in interfaceNode
- Overrides:
toString
in classAbstractVariable
- Returns:
- the name of the variable followed by its list of categories.
-
like
-
getNodeVariableType
Returns the node shape for this node.- Specified by:
getNodeVariableType
in interfaceNode
- Returns:
- the intervention type
-
setNodeVariableType
Sets the type (domain, interventional status, interventional value..) for this node variable- Specified by:
setNodeVariableType
in interfaceNode
- Parameters:
nodeVariableType
- the type (domain, interventional status, interventional value..) for this node variable
-
getAllAttributes
-
getAttribute
-
removeAttribute
removeAttribute.
- Specified by:
removeAttribute
in interfaceNode
- Parameters:
key
- aString
object
-
addAttribute
-