Class CompressedBitMatrix<R,C>
- java.lang.Object
-
- ubic.basecode.dataStructure.matrix.AbstractMatrix<R,C,double[]>
-
- ubic.basecode.dataStructure.matrix.CompressedBitMatrix<R,C>
-
- All Implemented Interfaces:
Serializable
,Matrix2D<R,C,double[]>
,ObjectMatrix<R,C,double[]>
public class CompressedBitMatrix<R,C> extends AbstractMatrix<R,C,double[]> implements ObjectMatrix<R,C,double[]>
Named compressed sparse bit matrix.- Author:
- xwan
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static long
BIT1
static int
BITS_PER_ELEMENT
-
Fields inherited from class ubic.basecode.dataStructure.matrix.AbstractMatrix
MAX_ROWS_TO_PRINT
-
-
Constructor Summary
Constructors Constructor Description CompressedBitMatrix(int rows, int cols, int totalBitsPerItem)
Constructs a matrix with specified rows, columns, and total bits per cell
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
bitCount(int r, int c)
Count the number of one-bits at the specified cell positionint
columns()
Get the number of columns the matrix has.double[]
get(int row, int col)
boolean
get(int row, int col, int index)
Checks the bit of the specified cell at the specified index.long[]
getAllBits(int row, int col)
Returns all of the bits for a cellint
getBitNum()
Returns the total number of bits in a matrix celldouble[]
getByKeys(R r, C c)
double[][]
getColumn(int i)
double[]
getEntry(int row, int column)
double[][]
getRow(int i)
int[]
getRowBitCount(int row)
boolean
isMissing(int i, int j)
Check if the value at a given index is missing.int
overlap(int row1, int col1, int row2, int col2)
Counts the number of one-bits that are in common between the two specified cells; i.e.void
reset(int r, int c)
int
rows()
Get the number of rows the matrix hasvoid
set(int row, int col, double[] val)
Set the matrix cell to the specified bit vectorvoid
set(int row, int col, int index)
Sets the bit of the specified cell at the specified index to 1.void
setByKeys(R r, C c, double[] v)
int
size()
ObjectMatrix<R,C,double[]>
subset(int startRow, int startCol, int numRow, int numCol)
ObjectMatrix<R,C,double[]>
subsetColumns(List<C> columns)
void
toFile(String fileName)
Save the matrix to the specified filelong
totalBitCount()
Number of ones in the entire matrix.void
unset(int row, int col, int index)
-
Methods inherited from class ubic.basecode.dataStructure.matrix.AbstractMatrix
addColumnName, addRowName, asDoubles, assign, checkColRange, checkRowRange, containsColumnName, containsRowName, getColIndexByName, getColName, getColNames, getRowIndexByName, getRowName, getRowNameMapIterator, getRowNames, hasColNames, hasMissingValues, hasRow, hasRowNames, numMissing, setColumnName, setColumnNames, setRowName, setRowNames
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface ubic.basecode.dataStructure.matrix.Matrix2D
addColumnName, asDoubles, assign, containsColumnName, containsRowName, getColIndexByName, getColName, getColNames, getRowIndexByName, getRowName, getRowNameMapIterator, getRowNames, hasColNames, hasRow, hasRowNames, numMissing, setColumnName, setColumnNames, setRowName, setRowNames
-
-
-
-
Constructor Detail
-
CompressedBitMatrix
public CompressedBitMatrix(int rows, int cols, int totalBitsPerItem)
Constructs a matrix with specified rows, columns, and total bits per cellImplementation note: this is created by maintaining one or more Double matrices; the Doubles are used as bit fields.
- Parameters:
rows
- - number of rows in the matrixcols
- - number of columns in the matrixtotalBitsPerItem
- - the number of bits for each cell
-
-
Method Detail
-
bitCount
public int bitCount(int r, int c)
Count the number of one-bits at the specified cell position- Parameters:
r
-c
-- Returns:
-
columns
public int columns()
Description copied from interface:Matrix2D
Get the number of columns the matrix has.
-
get
public double[] get(int row, int col)
- Specified by:
get
in interfaceObjectMatrix<R,C,double[]>
-
get
public boolean get(int row, int col, int index)
Checks the bit of the specified cell at the specified index.- Parameters:
row
- - matrix rowcol
- - matrix columnindex
- - bit vector index- Returns:
- true if bit is 1, false if 0.
-
getAllBits
public long[] getAllBits(int row, int col)
Returns all of the bits for a cell- Parameters:
row
- - the cell rowcol
- - the cell column- Returns:
- all the bits encoded as an array of
longs
-
getBitNum
public int getBitNum()
Returns the total number of bits in a matrix cell- Returns:
- the number of bits per cell
-
getColumn
public double[][] getColumn(int i)
- Specified by:
getColumn
in interfaceObjectMatrix<R,C,double[]>
-
getEntry
public double[] getEntry(int row, int column)
-
getRow
public double[][] getRow(int i)
- Specified by:
getRow
in interfaceObjectMatrix<R,C,double[]>
-
getRowBitCount
public int[] getRowBitCount(int row)
- Parameters:
row
-- Returns:
- - array of counts of one-bits for each cell in the row.
-
isMissing
public boolean isMissing(int i, int j)
Description copied from interface:Matrix2D
Check if the value at a given index is missing.
-
overlap
public int overlap(int row1, int col1, int row2, int col2)
Counts the number of one-bits that are in common between the two specified cells; i.e. performs an AND operation on the two bit vectors and counts the remaining 1 bits.- Parameters:
row1
- - cell 1 rowcol1
- - cell 1 columnrow2
- - cell 2 rowcol2
- - cell 2 column- Returns:
- number of bits in common
-
reset
public void reset(int r, int c)
-
rows
public int rows()
Description copied from interface:Matrix2D
Get the number of rows the matrix has
-
set
public void set(int row, int col, double[] val)
Set the matrix cell to the specified bit vector
-
set
public void set(int row, int col, int index)
Sets the bit of the specified cell at the specified index to 1.- Parameters:
row
- - matrix rowcol
- - matrix columnindex
- - bit vector index
-
size
public int size()
- Specified by:
size
in classAbstractMatrix<R,C,double[]>
-
subset
public ObjectMatrix<R,C,double[]> subset(int startRow, int startCol, int numRow, int numCol)
- Specified by:
subset
in interfaceObjectMatrix<R,C,double[]>
- Returns:
-
subsetColumns
public ObjectMatrix<R,C,double[]> subsetColumns(List<C> columns)
- Specified by:
subsetColumns
in interfaceObjectMatrix<R,C,double[]>
- Parameters:
columns
-- Returns:
-
toFile
public void toFile(String fileName) throws IOException
Save the matrix to the specified file- Parameters:
fileName
- - save file- Throws:
IOException
-
totalBitCount
public long totalBitCount()
Number of ones in the entire matrix.- Returns:
-
unset
public void unset(int row, int col, int index)
-
-