Package edu.cmu.tetrad.data
Class CovarianceMatrixOnTheFly
java.lang.Object
edu.cmu.tetrad.data.CovarianceMatrixOnTheFly
- 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
ConstructorsConstructorDescriptionCovarianceMatrixOnTheFly(DataSet dataSet) Constructs a new covariance matrix from the given data set.CovarianceMatrixOnTheFly(DataSet dataSet, boolean verbose) Constructor for CovarianceMatrixOnTheFly. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidclearSelection.copy()copy.static voiddemean.final intgetDimension.final KnowledgeGetter for the fieldknowledge.final MatrixGetter for the fieldmatrix.final MatrixgetMatrix(int[] rows) Getter for the fieldmatrix.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.getSelection(int[] rows, int[] cols, int[] dataRows) getSelection.final intgetSize()getSize.final ICovarianceMatrixgetSubmatrix(int[] indices) getSubmatrix.final ICovarianceMatrixgetSubmatrix(int[] indices, int[] dataRows) getSubmatrix.final CovarianceMatrixOnTheFlygetSubmatrix(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.final doublegetValue(int i, int j, int[] rows) getValue.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.booleanisVerbose.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.voidsetVerbose(boolean verbose) Setter for the fieldverbose.final StringtoString()Prints out the matrix
-
Constructor Details
-
CovarianceMatrixOnTheFly
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:
dataSet- aDataSetobject- Throws:
IllegalArgumentException- if this is not a continuous data set.
-
CovarianceMatrixOnTheFly
Constructor for CovarianceMatrixOnTheFly.
- Parameters:
dataSet- aDataSetobjectverbose- a boolean
-
-
Method Details
-
demean
demean.
- Parameters:
data- an array of objectsmeans- aVectorobject
-
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.
- Parameters:
indices- an array of objectsdataRows- an array of objects- Returns:
- a
ICovarianceMatrixobject
-
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
-
getValue
public final double getValue(int i, int j, int[] rows) getValue.
- Parameters:
i- a intj- a introws- an array of objects- Returns:
- a double
-
getSize
public final int getSize()getSize.
- Specified by:
getSizein interfaceICovarianceMatrix- Returns:
- the size of the square matrix.
-
getMatrix
Getter for the field
matrix.- Specified by:
getMatrixin interfaceICovarianceMatrix- Returns:
- a copy of the covariance matrix.
-
setMatrix
Sets the covariance matrix.- Specified by:
setMatrixin interfaceICovarianceMatrix- Parameters:
matrix- the matrix to set
-
getMatrix
Getter for the field
matrix.- Parameters:
rows- an array of objects- Returns:
- a
Matrixobject
-
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.
-
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:
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.
-
getSelection
getSelection.
- Parameters:
rows- an array of objectscols- an array of objectsdataRows- an array of objects- Returns:
- a
Matrixobject
-
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.
-