Package edu.cmu.tetrad.data
Class CovarianceMatrix
java.lang.Object
edu.cmu.tetrad.data.CovarianceMatrix
- All Implemented Interfaces:
DataModel,ICovarianceMatrix,KnowledgeTransferable,VariableSource,TetradSerializable,Serializable
- Direct Known Subclasses:
CorrelationMatrix
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
ConstructorsConstructorDescriptionCovarianceMatrix(CovarianceMatrix covMatrix) Copy constructor.CovarianceMatrix(DataSet dataSet) Constructs a new covariance matrix from the given data set.CovarianceMatrix(DataSet dataSet, boolean biasCorrected) Constructor for CovarianceMatrix.CovarianceMatrix(ICovarianceMatrix covMatrix) Constructor for CovarianceMatrix.CovarianceMatrix(List<Node> variables, double[][] matrix, int sampleSize) Constructor for CovarianceMatrix.CovarianceMatrix(List<Node> variables, Matrix matrix, int sampleSize) Protected constructor to construct a new covariance matrix using the supplied continuous variables and the the given symmetric, positive definite matrix and sample size. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidclearSelection.copy()copy.final intgetDimension.final KnowledgeGetter for the fieldknowledge.final MatrixgetMatrix.final StringgetName()Gets the name of the covariance matrix.final intThe 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 intgetSize()getSize.final ICovarianceMatrixgetSubmatrix(int[] indices) getSubmatrix.final CovarianceMatrixgetSubmatrix(String[] submatrixVarNames) getSubmatrix.final ICovarianceMatrixgetSubmatrix(List<String> submatrixVarNames) getSubmatrix.final doublegetValue(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 StringgetVariableName(int index) Retrieves the name of the variable at the specified index from the covariance matrix.getVariableNames.Getter for the fieldvariables.booleanisContinuous.booleanisDiscrete.booleanisMixed()isMixed.final booleanisSelected(Node variable) Checks if the specified node is selected in the covariance matrix.booleanisSingular.voidremoveVariables(List<String> remaining) Removes variables from the covariance matrix, retaining only the variables specified in the provided list.final voidSelects a specified variable in the covariance matrix.static ICovarianceMatrixGenerates a simple exemplar of this class to test serialization.final voidsetKnowledge(Knowledge knowledge) Sets the knowledge associated with the ICovarianceMatrix.voidSets the covariance matrix.final voidSets the name of the covariance matrix.final voidsetSampleSize(int sampleSize) Sets the sample size used in the covariance matrix.voidsetValue(int i, int j, double v) Sets the value of the covariance matrix at the specified indices.voidsetVariables(List<Node> variables) Sets the list of Node variables for the covariance matrix.final StringtoString()Prints out the matrix
-
Constructor Details
-
CovarianceMatrix
Constructs a new covariance matrix from the given data set.- Parameters:
dataSet- aDataSetobject- Throws:
IllegalArgumentException- if this is not a continuous data set.
-
CovarianceMatrix
Constructor for CovarianceMatrix.
- Parameters:
dataSet- aDataSetobjectbiasCorrected- a boolean
-
CovarianceMatrix
Protected constructor to construct a new covariance matrix using the supplied continuous variables and the the given symmetric, positive definite matrix and sample size. The number of variables must equal the dimension of the array.- Parameters:
variables- the list of variables (in order) for the covariance matrix.matrix- an square array of containing covariances.sampleSize- the sample size of the data for these covariances.- Throws:
IllegalArgumentException- if the given matrix is not symmetric (to a tolerance of 1.e-5) and positive definite, if the number of variables does not equal the dimension of m, or if the sample size is not positive.
-
CovarianceMatrix
Constructor for CovarianceMatrix.
- Parameters:
variables- aListobjectmatrix- an array of objectssampleSize- a int
-
CovarianceMatrix
Copy constructor.- Parameters:
covMatrix- aCovarianceMatrixobject
-
CovarianceMatrix
Constructor for CovarianceMatrix.
- Parameters:
covMatrix- aICovarianceMatrixobject
-
-
Method Details
-
serializableInstance
Generates a simple exemplar of this class to test serialization.- Returns:
- a
ICovarianceMatrixobject
-
getVariables
Getter for the field
variables.- Specified by:
getVariablesin interfaceICovarianceMatrix- Specified by:
getVariablesin interfaceVariableSource- Returns:
- the list of variables (unmodifiable).
-
setVariables
Sets the list of Node variables for the covariance matrix.- Specified by:
setVariablesin interfaceICovarianceMatrix- Parameters:
variables- a list of Node objects representing the variables to be set in the covariance matrix
-
getVariableNames
getVariableNames.
- Specified by:
getVariableNamesin interfaceICovarianceMatrix- Specified by:
getVariableNamesin interfaceVariableSource- Returns:
- the variable names, in order.
-
getVariableName
Retrieves the name of the variable at the specified index from the covariance matrix.- Specified by:
getVariableNamein 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:
getDimensionin 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:
getSampleSizein interfaceICovarianceMatrix- Returns:
- The sample size (> 0).
-
setSampleSize
public final void setSampleSize(int sampleSize) Sets the sample size used in the covariance matrix.- Specified by:
setSampleSizein interfaceICovarianceMatrix- Parameters:
sampleSize- the sample size to be set
-
getName
Gets the name of the covariance matrix.- Specified by:
getNamein interfaceDataModel- Specified by:
getNamein interfaceICovarianceMatrix- Returns:
- a
Stringobject
-
setName
Sets the name of the covariance matrix.Sets the name of the covariance matrix.
- Specified by:
setNamein interfaceDataModel- Specified by:
setNamein interfaceICovarianceMatrix- Parameters:
name- the new name of the covariance matrix
-
getKnowledge
Getter for the field
knowledge.- Specified by:
getKnowledgein interfaceICovarianceMatrix- Specified by:
getKnowledgein interfaceKnowledgeTransferable- Returns:
- the knowledge associated with this data.
-
setKnowledge
Sets the knowledge associated with the ICovarianceMatrix.Associates knowledge with this data.
- Specified by:
setKnowledgein interfaceICovarianceMatrix- Specified by:
setKnowledgein interfaceKnowledgeTransferable- Parameters:
knowledge- the knowledge to set
-
getSubmatrix
getSubmatrix.
- Specified by:
getSubmatrixin interfaceICovarianceMatrix- Parameters:
indices- an array of objects- Returns:
- a submatrix of the covariance matrix with variables in the given order.
-
getSubmatrix
getSubmatrix.
- Specified by:
getSubmatrixin interfaceICovarianceMatrix- Parameters:
submatrixVarNames- aListobject- Returns:
- a
ICovarianceMatrixobject
-
getSubmatrix
getSubmatrix.
- Specified by:
getSubmatrixin interfaceICovarianceMatrix- Parameters:
submatrixVarNames- an array ofStringobjects- 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:
getValuein 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:
getSizein interfaceICovarianceMatrix- Returns:
- the size of the square matrix.
-
getMatrix
getMatrix.
- Specified by:
getMatrixin interfaceICovarianceMatrix- Returns:
- a the covariance matrix (not a copy).
-
setMatrix
Sets the covariance matrix.- Specified by:
setMatrixin interfaceICovarianceMatrix- Parameters:
matrix- the matrix to set
-
select
Selects a specified variable in the covariance matrix.- Specified by:
selectin interfaceICovarianceMatrix- Parameters:
variable- the node variable to be selected
-
clearSelection
public final void clearSelection()clearSelection.
- Specified by:
clearSelectionin interfaceICovarianceMatrix
-
isSelected
Checks if the specified node is selected in the covariance matrix.- Specified by:
isSelectedin interfaceICovarianceMatrix- Parameters:
variable- the node to check for selection- Returns:
- true if the node is selected, false otherwise
-
getSelectedVariableNames
getSelectedVariableNames.
- Specified by:
getSelectedVariableNamesin interfaceICovarianceMatrix- Returns:
- a
Listobject
-
toString
Prints out the matrix -
isContinuous
public boolean isContinuous()isContinuous.
- Specified by:
isContinuousin interfaceDataModel- Returns:
- true if the data model is continuous, false otherwise.
-
isDiscrete
public boolean isDiscrete()isDiscrete.
- Specified by:
isDiscretein interfaceDataModel- Returns:
- true if the data model is discrete, false otherwise.
-
isMixed
public boolean isMixed()isMixed.
-
getSelection
Returns a submatrix based on the specified rows and columns.- Specified by:
getSelectionin 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
Matrixobject containing the selected rows and columns.
-
getVariable
Retrieves a Node instance from the covariance matrix corresponding to the specified variable name.- Specified by:
getVariablein interfaceDataModel- Specified by:
getVariablein interfaceICovarianceMatrix- Parameters:
name- the name of the variable to retrieve- Returns:
- the Node associated with the specified variable name
-
copy
copy.
-
setValue
public void setValue(int i, int j, double v) Sets the value of the covariance matrix at the specified indices.- Specified by:
setValuein 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:
removeVariablesin interfaceICovarianceMatrix- Parameters:
remaining- a list of variable names to retain in the covariance matrix.
-
isSingular
public boolean isSingular()isSingular.
- Returns:
- a boolean
-