Package edu.cmu.tetrad.data
Class CorrelationMatrixOnTheFly
java.lang.Object
edu.cmu.tetrad.data.CorrelationMatrixOnTheFly
- All Implemented Interfaces:
DataModel
,ICovarianceMatrix
,KnowledgeTransferable
,VariableSource
,TetradSerializable
,Serializable
Stores a covariance matrix together with variable names and sample size, intended as a representation of a data set.
When constructed from a continuous data set, the matrix is not checked for positive definiteness; however, when a
covariance matrix is supplied, its positive definiteness is always checked. If the sample size is less than the
number of variables, the positive definiteness is "spot-checked"--that is, checked for various submatrices.
- Version:
- $Id: $Id
- Author:
- josephramsey
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new covariance matrix from the given data set. -
Method Summary
Modifier and TypeMethodDescriptionfinal void
clearSelection.copy()
copy.final int
getDimension.final Knowledge
getKnowledge.final Matrix
getMatrix.final String
getName()
Gets the name of the covariance matrix.final int
The size of the sample used to calculated this covariance matrix.getSelectedVariableNames.getSelection
(int[] rows, int[] cols) Returns a submatrix based on the specified rows and columns.final int
getSize()
getSize.final ICovarianceMatrix
getSubmatrix
(int[] indices) getSubmatrix.getSubmatrix
(String[] submatrixVarNames) getSubmatrix.final ICovarianceMatrix
getSubmatrix
(List<String> submatrixVarNames) getSubmatrix.final double
getValue
(int i, int j) Retrieves the value from the covariance matrix at the specified row and column indices.getVariable
(String name) Retrieves a Node instance from the covariance matrix corresponding to the specified variable name.final String
getVariableName
(int index) Retrieves the name of the variable at the specified index from the covariance matrix.getVariableNames.Getter for the fieldvariables
.boolean
isContinuous.boolean
isDiscrete.boolean
isMixed()
isMixed.final boolean
isSelected
(Node variable) Checks if the specified node is selected in the covariance matrix.boolean
isVerbose.void
removeVariables
(List<String> remaining) Removes variables from the covariance matrix, retaining only the variables specified in the provided list.final void
Selects a specified variable in the covariance matrix.static ICovarianceMatrix
Generates a simple exemplar of this class to test serialization.final void
setKnowledge
(Knowledge knowledge) Sets the knowledge associated with the ICovarianceMatrix.void
Sets the covariance matrix.final void
Sets the name of the covariance matrix.final void
setSampleSize
(int sampleSize) Sets the sample size used in the covariance matrix.void
setValue
(int i, int j, double v) Sets the value of the covariance matrix at the specified indices.void
setVariables
(List<Node> variables) Sets the list of Node variables for the covariance matrix.void
setVerbose
(boolean verbose) Setter for the fieldverbose
.final String
toString()
Prints out the matrix
-
Constructor Details
-
CorrelationMatrixOnTheFly
Constructs a new covariance matrix from the given data set. If dataSet is a BoxDataSet with a VerticalDoubleDataBox, the data will be mean-centered by the constructor; is non-mean-centered version of the data is needed, the data should be copied before being send into the constructor.- Parameters:
cov
- aICovarianceMatrix
object- Throws:
IllegalArgumentException
- if this is not a continuous data set.
-
-
Method Details
-
serializableInstance
Generates a simple exemplar of this class to test serialization.- Returns:
- a
ICovarianceMatrix
object
-
getVariables
Getter for the field
variables
.- Specified by:
getVariables
in interfaceICovarianceMatrix
- Specified by:
getVariables
in interfaceVariableSource
- Returns:
- the list of variables (unmodifiable).
-
setVariables
Sets the list of Node variables for the covariance matrix.- Specified by:
setVariables
in interfaceICovarianceMatrix
- Parameters:
variables
- a list of Node objects representing the variables to be set in the covariance matrix
-
getVariableNames
getVariableNames.
- Specified by:
getVariableNames
in interfaceICovarianceMatrix
- Specified by:
getVariableNames
in interfaceVariableSource
- Returns:
- the variable names, in order.
-
getVariableName
Retrieves the name of the variable at the specified index from the covariance matrix.- Specified by:
getVariableName
in interfaceICovarianceMatrix
- Parameters:
index
- the index of the variable whose name is to be retrieved- Returns:
- the name of the variable at the specified index
-
getDimension
public final int getDimension()getDimension.
- Specified by:
getDimension
in interfaceICovarianceMatrix
- Returns:
- the dimension of the covariance matrix.
-
getSampleSize
public final int getSampleSize()The size of the sample used to calculated this covariance matrix.- Specified by:
getSampleSize
in interfaceICovarianceMatrix
- Returns:
- The sample size (> 0).
-
setSampleSize
public final void setSampleSize(int sampleSize) Sets the sample size used in the covariance matrix.- Specified by:
setSampleSize
in interfaceICovarianceMatrix
- Parameters:
sampleSize
- the sample size to be set
-
getName
-
setName
Sets the name of the covariance matrix.Sets the name of the covariance matrix.
- Specified by:
setName
in interfaceDataModel
- Specified by:
setName
in interfaceICovarianceMatrix
- Parameters:
name
- the new name of the covariance matrix
-
getKnowledge
getKnowledge.
- Specified by:
getKnowledge
in interfaceICovarianceMatrix
- Specified by:
getKnowledge
in interfaceKnowledgeTransferable
- Returns:
- the knowledge associated with this data.
-
setKnowledge
Sets the knowledge associated with the ICovarianceMatrix.Associates knowledge with this data.
- Specified by:
setKnowledge
in interfaceICovarianceMatrix
- Specified by:
setKnowledge
in interfaceKnowledgeTransferable
- Parameters:
knowledge
- the knowledge to set
-
getSubmatrix
getSubmatrix.
- Specified by:
getSubmatrix
in interfaceICovarianceMatrix
- Parameters:
indices
- an array of objects- Returns:
- a submatrix of the covariance matrix with variables in the given order.
-
getSubmatrix
getSubmatrix.
- Specified by:
getSubmatrix
in interfaceICovarianceMatrix
- Parameters:
submatrixVarNames
- aList
object- Returns:
- a
ICovarianceMatrix
object
-
getSubmatrix
getSubmatrix.
- Specified by:
getSubmatrix
in interfaceICovarianceMatrix
- Parameters:
submatrixVarNames
- an array ofString
objects- Returns:
- a submatrix of this matrix, with variables in the given order.
-
getValue
public final double getValue(int i, int j) Retrieves the value from the covariance matrix at the specified row and column indices.- Specified by:
getValue
in interfaceICovarianceMatrix
- Parameters:
i
- the row indexj
- the column index- Returns:
- the value at the specified indices in the matrix
-
getSize
public final int getSize()getSize.
- Specified by:
getSize
in interfaceICovarianceMatrix
- Returns:
- the size of the square matrix.
-
getMatrix
getMatrix.
- Specified by:
getMatrix
in interfaceICovarianceMatrix
- Returns:
- a copy of the covariance matrix.
-
setMatrix
Sets the covariance matrix.- Specified by:
setMatrix
in interfaceICovarianceMatrix
- Parameters:
matrix
- the matrix to set
-
select
Selects a specified variable in the covariance matrix.- Specified by:
select
in interfaceICovarianceMatrix
- Parameters:
variable
- the node variable to be selected
-
clearSelection
public final void clearSelection()clearSelection.
- Specified by:
clearSelection
in interfaceICovarianceMatrix
-
isSelected
Checks if the specified node is selected in the covariance matrix.- Specified by:
isSelected
in interfaceICovarianceMatrix
- Parameters:
variable
- the node to check for selection- Returns:
- true if the node is selected, false otherwise
-
getSelectedVariableNames
getSelectedVariableNames.
- Specified by:
getSelectedVariableNames
in interfaceICovarianceMatrix
- Returns:
- a
List
object
-
toString
-
isContinuous
public boolean isContinuous()isContinuous.
- Specified by:
isContinuous
in interfaceDataModel
- Returns:
- true if the data model is continuous, false otherwise.
-
isDiscrete
public boolean isDiscrete()isDiscrete.
- Specified by:
isDiscrete
in interfaceDataModel
- Returns:
- true if the data model is discrete, false otherwise.
-
isMixed
-
isVerbose
public boolean isVerbose()isVerbose.
- Returns:
- a boolean
-
setVerbose
public void setVerbose(boolean verbose) Setter for the field
verbose
.- Parameters:
verbose
- a boolean
-
getSelection
Returns a submatrix based on the specified rows and columns.- Specified by:
getSelection
in interfaceICovarianceMatrix
- Parameters:
rows
- an array of integers representing the row indices to be included in the selection.cols
- an array of integers representing the column indices to be included in the selection.- Returns:
- a
Matrix
object containing the selected rows and columns.
-
getVariable
Retrieves a Node instance from the covariance matrix corresponding to the specified variable name.- Specified by:
getVariable
in interfaceDataModel
- Specified by:
getVariable
in interfaceICovarianceMatrix
- Parameters:
name
- the name of the variable to retrieve- Returns:
- the Node associated with the specified variable name
-
copy
-
setValue
public void setValue(int i, int j, double v) Sets the value of the covariance matrix at the specified indices.- Specified by:
setValue
in interfaceICovarianceMatrix
- Parameters:
i
- the row indexj
- the column indexv
- the value to set at the specified indices
-
removeVariables
Removes variables from the covariance matrix, retaining only the variables specified in the provided list.- Specified by:
removeVariables
in interfaceICovarianceMatrix
- Parameters:
remaining
- a list of variable names to retain in the covariance matrix.
-