Package com.actelion.research.calc
Class Matrix
- java.lang.Object
-
- com.actelion.research.calc.Matrix
-
public class Matrix extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
OUT_SEPARATOR_COL
static java.lang.String
OUT_SEPARATOR_ROW
static double
TINY
static double
TINY04
static double
TINY08
static double
TINY16
-
Constructor Summary
Constructors Constructor Description Matrix()
Matrix(boolean row, byte[] arr)
Matrix(boolean row, double[] arr)
Matrix(boolean row, int[] dArray)
Matrix(boolean bRow, java.util.List<java.lang.Double> liDoubles)
Matrix(byte[][] arrArr)
Matrix(double[][] arrArr)
Deep copyMatrix(double[][] arrArr, boolean flat)
Matrix(float[][] arrArr)
Matrix(int[][] arrArr)
Matrix(int rows, int cols)
Matrix(Matrix ma)
Matrix(java.util.List<DoubleVec> vecDoubleVec)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Matrix
add(double v)
Matrix
add2CompleteCol(Matrix maRow)
The value in the col from the input matrix is added to all values in the corresponding col in the matrix.void
add2Row(int row, Matrix ma2, int row2)
void
addRow(double[] arr)
void
addRow(int[] arr)
void
addToElement(int i, int j, double value)
boolean
areRowsEqual(int row1, int row2)
void
assignCol(int iCol, Matrix ma)
void
assignCol(int iCol, Matrix ma, int iColMa)
void
assignRow(int iRow, double[] arr)
void
assignRow(int iRow, int[] arr)
void
assignRow(int iRow, DoubleVec dv)
void
assignRow(int iRow, java.util.Vector<java.lang.Double> vecRow)
int
cols()
boolean
containsRow(DoubleVec dv)
void
copy(int offsetRows, Matrix maSource)
This (target matrix) must have appropriate dimensions.void
copy(Matrix maSource)
Copies a matrix ma into this, the pointer to ma1 is not changed.void
copyColumn(Matrix maSource, int colSource, int colDestination)
Matrix
correlation()
Generate a correlation matrix, each column contains values of a pulling.Matrix
covariance()
Generate a covariance matrix, each column contains values of a pulling.double
det()
Matrix determinantMatrix
devide(double dDivisor)
Matrix
devide(Matrix maDivisor)
Matrix
devideCols(Matrix maDivisor)
Matrix
devideDivisorBigger(Matrix maDivisor)
void
devideRow(int row, double denominator)
Matrix
diagonalize()
boolean
equal(Matrix ma)
boolean
equal(Matrix ma, double dLimit)
boolean
equalDimension(Matrix ma)
Checks two matrices for equal dimensions.static java.lang.String
format(double val, java.text.DecimalFormat nf, int totalWidth)
static java.text.DecimalFormat
format(int digits)
double
get(int row, int col)
Matrix
getAbs()
double[][]
getArray()
int[][]
getArrayAsInt()
double[][]
getArrayCopy()
Matrix
getCenteredMatrix()
Matrix
getCenteredMatrix(Matrix maMean)
double
getCoefficientVariation()
Coefficient of variation (CV) is a normalized measure of dispersion of a probability distribution.Matrix
getCol(int col)
double[]
getColAsDouble(int col)
float[]
getColAsFloat(int iCol)
int[]
getColAsInt(int iCol)
java.util.List<java.lang.Double>
getColAsList(int col)
int
getColDim()
int
getColIndexContainingMaxVal(int row)
ScorePoint
getColIndexContainingMaxVal(int rowEnd, int colEnd)
Matrix
getColumns(int[] arrIndex)
Matrix
getColumns(java.util.List<java.lang.Integer> liIndex)
Matrix
getColumns(java.util.Vector<java.lang.Integer> vecIndices)
Deprecated.use getColumns(ListvecIndices) instead Matrix
getDeleteColsZeroVar(java.util.List<java.lang.Integer> vecIndices)
Deletes columns with zero variance.Matrix
getDiagonal()
Matrix diagonal extraction.static void
getEigenvector(Matrix A, int n, Matrix D, Matrix E)
Householder reduction according num rec 11.2.double
getEuclideanDistanceFastRows(int row1, int row2)
Skipping the sqrt.double
getEuclideanDistanceFastRows(int iRow, Matrix A, int iRowA)
Skipping the sqrt.Matrix
getFlipped()
Opposite direction to transpose.int
getID()
Matrix
getLinedCol()
java.util.List<java.lang.Double>
getList()
Matrix
getMatrix(int[] r, int[] c)
Get a submatrix.Matrix
getMatrix(int[] r, int j0, int j1)
Get a submatrix.Matrix
getMatrix(int i0, int i1, int[] c)
Get a submatrix.Matrix
getMatrix(int i0, int i1, int j0, int j1)
double
getMax()
double
getMax(int col)
get max value for that col.double
getMaximumValue()
java.awt.Point
getMaxIndex()
Matrix
getMaxMin()
max and min vals for all colsdouble
getMaxRow(int row)
int
getMaxRowIndex(int col)
int
getMaxRowIndexRND(int row)
Shuffles the indices before searching the minimum.double
getMean()
double
getMeanCol(int col)
double
getMeanCol(int iColIndex, int[] rowIndex)
Matrix
getMeanCols()
Matrix
getMeanCols(int[] rowIndex)
double
getMeanRow(int row)
Matrix
getMeanRows()
double
getMedian()
double
getMedian(int row)
Matrix
getMedianCols()
Matrix
getMergeRows(Matrix ma)
double
getMin()
double
getMin(int col)
int
getMinColIndex(int row)
ScorePoint
getMinPos()
double
getMinRow(int row)
int
getMinRowIndex(int row)
int
getMinRowIndexRND(int row)
03.10.04 MvK Shuffles the indices before searching the minimum.Matrix
getMinRows()
Matrix
getMinRowsPosCol()
double[]
getNext4NeighboursTorus(int row, int col)
double[]
getNext8NeighboursTorus(int row, int col)
Matrix
getNormalizedMatrix()
Matrix
getNormalizedMatrix(Matrix maStandardDeviation)
int
getNumElements()
int
getNumElementsEqual(double val2Compare)
int
getNumElementsLarger(double val2Compare)
static Matrix
getParsed(java.util.Vector<java.lang.String> vecStringMatrix)
Parses an vector with Strings and converts it to a Matrix.static double
getPythag(double a, double b)
pythag computes sqrt(a^2 + b^2) without destructive underflow or overflow.static double
getPythag2(double a, double b)
static Matrix
getRND(int rows, int cols)
double[]
getRow(int row)
Flat copy.float[]
getRowAsFloat(int row)
java.util.List<java.lang.Double>
getRowAsList(int row)
double[]
getRowCopy(int row)
int
getRowDim()
Matrix
getSorted()
Sorts the row of the matrix according the compareTo(...) function in DoubleVecMatrix
getSQRT()
double
getSquaredSum()
double
getStandardDeviation()
Matrix
getStandardDeviationCols()
Matrix
getStandardized()
Get the standard scores, also known as z-scores.Matrix
getSubMatrix(int indexRowStart, int indexRowEnd, int indexColStart, int indexColEnd)
Matrix
getSubMatrix(java.util.List<java.lang.Integer> liIndexRow)
double
getSum()
double
getSumCol(int col)
Matrix
getSumCols()
double
getSumRow(int row)
Matrix
getSumRows()
double
getSumSquared()
double
getSumUpperTriangle()
Matrix has to be quadratic.double
getTorus(int row, int col)
double
getTrace()
Matrix trace.Matrix
getTranspose()
double[]
getUpperTriangle()
For a quadratic matrix only.double
getVariance()
double
getVarianceCentered()
double
getVarianceCol(int col)
Matrix
getVarianceCols()
boolean
hasOnlyFinite()
void
increase(int row, int col, double v)
Matrix
log()
Log function from the class Math .Matrix
multCols(Matrix maMuiltiplicant)
Matrix
multiply(boolean transA, boolean transB, Matrix ma)
Multiplication of two matrices.Matrix
multiply(double dScalar)
double
multiply(int row1, Matrix ma2, int row2)
Matrix
multiply(Matrix ma)
Matrix
multiplyValByVal(Matrix ma)
Value by value multiplication Matrices must have the same dimensions.Matrix
plus(Matrix ma)
Matrix
pow(double exp)
static Matrix
readSerialized(java.io.File fiIn)
Matrix
removeCol(int col2Remove)
void
resize(int rowsNew, int colsNew)
Resizes the matrix, the old data are written to the new matrix, if possible.Matrix
row2Matrix(int row, int len)
int
rows()
void
set(double v)
void
set(double[][] arr)
void
set(int row, int col, double v)
void
set(Matrix ma)
void
setCol(int col, double v)
void
setCol(int col, double[] arr)
void
setFlat(double[][] arr)
void
setID(int id)
void
setRow(int iRow, double v)
void
setRow(int iRow, double[] arr)
Deep copyvoid
setRow(int iRow, int[] arr)
static void
setSeparatorCol(java.lang.String s)
static void
setSeparatorRow(java.lang.String s)
void
shuffleRows()
static double
Sign(double a, double b)
void
sortRows(int col)
Matrix
subtract(double val)
Matrix
subtract(Matrix ma)
Matrix
subtractFromCols(Matrix maDivisor)
void
swapRows(int a, int b)
double[]
toArray()
Matrix
toRow()
java.lang.String
toString()
java.lang.String
toString(int digits)
java.lang.String
toString(int rowEnd, int colEnd, int digits)
java.lang.String
toStringBinary()
java.lang.String
toStringRow(int row, int iDigits)
java.lang.String
toStringRowNumber(int iDigits, java.lang.String sSeparatorCol)
java.lang.String
toStringWithColTags(java.util.List<java.lang.String> liColTags, java.text.DecimalFormat nf, java.lang.String separator)
java.lang.String
toStringWithRowTags(java.util.List<java.lang.String> liRowTags, java.text.DecimalFormat nf, java.lang.String separator)
void
write(java.io.File fiMa)
void
write(java.io.File fiMa, boolean apppend, int digits)
void
write(java.io.File fiMa, java.text.DecimalFormat nf, boolean apppend)
void
write(java.io.OutputStream os)
void
write(java.io.OutputStream os, java.text.NumberFormat nf)
void
write(java.lang.String sFile)
void
write(java.lang.String sFile, boolean apppend)
void
write(java.lang.String sFiMa, boolean apppend, int digits)
void
write(java.lang.String sFile, boolean bApppend, int digits, int totalWidth)
java.lang.String
writeAsLineBase64Encoded()
void
writeSerialized(java.io.File fiOut)
-
-
-
Field Detail
-
TINY04
public static final double TINY04
- See Also:
- Constant Field Values
-
TINY08
public static final double TINY08
- See Also:
- Constant Field Values
-
TINY16
public static final double TINY16
-
OUT_SEPARATOR_COL
public static java.lang.String OUT_SEPARATOR_COL
-
OUT_SEPARATOR_ROW
public static java.lang.String OUT_SEPARATOR_ROW
-
TINY
public static final double TINY
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Matrix
public Matrix()
-
Matrix
public Matrix(int rows, int cols)
-
Matrix
public Matrix(Matrix ma)
-
Matrix
public Matrix(boolean row, double[] arr)
- Parameters:
row
- if true the matrix has one row. If false the matrix has one column.arr
-
-
Matrix
public Matrix(boolean row, byte[] arr)
-
Matrix
public Matrix(boolean row, int[] dArray)
-
Matrix
public Matrix(double[][] arrArr)
Deep copy- Parameters:
arrArr
-
-
Matrix
public Matrix(double[][] arrArr, boolean flat)
-
Matrix
public Matrix(float[][] arrArr)
-
Matrix
public Matrix(int[][] arrArr)
-
Matrix
public Matrix(byte[][] arrArr)
-
Matrix
public Matrix(java.util.List<DoubleVec> vecDoubleVec)
- Parameters:
vecDoubleVec
- Vector with DoubleVec
-
Matrix
public Matrix(boolean bRow, java.util.List<java.lang.Double> liDoubles)
-
-
Method Detail
-
add
public Matrix add(double v)
-
addRow
public void addRow(double[] arr)
- Parameters:
arr
- adds a row at the end of the matrix.
-
addRow
public void addRow(int[] arr)
-
add2Row
public void add2Row(int row, Matrix ma2, int row2)
- Parameters:
row
- where the data are added onma2
- matrix from where the data are takenrow2
- data row
-
addToElement
public void addToElement(int i, int j, double value)
-
add2CompleteCol
public Matrix add2CompleteCol(Matrix maRow)
The value in the col from the input matrix is added to all values in the corresponding col in the matrix.- Parameters:
maRow
- matrix with one row.
-
assignCol
public void assignCol(int iCol, Matrix ma)
-
assignCol
public void assignCol(int iCol, Matrix ma, int iColMa)
-
assignRow
public void assignRow(int iRow, java.util.Vector<java.lang.Double> vecRow)
-
assignRow
public void assignRow(int iRow, double[] arr)
-
assignRow
public void assignRow(int iRow, int[] arr)
-
assignRow
public void assignRow(int iRow, DoubleVec dv)
-
containsRow
public boolean containsRow(DoubleVec dv)
-
copy
public void copy(Matrix maSource)
Copies a matrix ma into this, the pointer to ma1 is not changed.- Parameters:
maSource
-
-
copy
public void copy(int offsetRows, Matrix maSource)
This (target matrix) must have appropriate dimensions.- Parameters:
offsetRows
-maSource
-
-
copyColumn
public void copyColumn(Matrix maSource, int colSource, int colDestination)
-
get
public final double get(int row, int col)
-
getAbs
public Matrix getAbs()
-
getArray
public final double[][] getArray()
-
getArrayAsInt
public int[][] getArrayAsInt() throws java.lang.NumberFormatException
- Throws:
java.lang.NumberFormatException
-
getArrayCopy
public double[][] getArrayCopy()
-
getCenteredMatrix
public Matrix getCenteredMatrix()
- Returns:
- column wise centered matrix.
-
getCol
public Matrix getCol(int col)
-
removeCol
public Matrix removeCol(int col2Remove)
-
getColAsDouble
public double[] getColAsDouble(int col)
-
getColAsList
public java.util.List<java.lang.Double> getColAsList(int col)
-
getColAsFloat
public float[] getColAsFloat(int iCol)
-
getColAsInt
public int[] getColAsInt(int iCol)
-
getColumns
public Matrix getColumns(java.util.Vector<java.lang.Integer> vecIndices)
Deprecated.use getColumns(ListvecIndices) instead - Parameters:
vecIndices
-- Returns:
-
getColumns
public Matrix getColumns(java.util.List<java.lang.Integer> liIndex)
-
getColumns
public Matrix getColumns(int[] arrIndex)
-
getColDim
public int getColDim()
-
cols
public int cols()
-
getDeleteColsZeroVar
public Matrix getDeleteColsZeroVar(java.util.List<java.lang.Integer> vecIndices)
Deletes columns with zero variance.- Parameters:
vecIndices
- the integer vector is filled with the indices from the input matrix which are taken for the new matrix.- Returns:
- input matrix reduced by all cols with zero variance.
-
covariance
public Matrix covariance()
Generate a covariance matrix, each column contains values of a pulling.- Returns:
- An n-by-n matrix.
-
correlation
public Matrix correlation()
Generate a correlation matrix, each column contains values of a pulling.- Returns:
- An n-by-n matrix.
-
getDiagonal
public Matrix getDiagonal()
Matrix diagonal extraction.- Returns:
- An d*1 Matrix of diagonal elements, d = min(m,n).
-
getLinedCol
public Matrix getLinedCol()
-
getList
public java.util.List<java.lang.Double> getList()
-
getMatrix
public Matrix getMatrix(int i0, int i1, int j0, int j1)
-
getMatrix
public Matrix getMatrix(int[] r, int[] c)
Get a submatrix.- Parameters:
r
- Array of row indices.c
- Array of column indices.- Returns:
- A(r(:),c(:))
- Throws:
java.lang.ArrayIndexOutOfBoundsException
- Submatrix indices
-
getMatrix
public Matrix getMatrix(int i0, int i1, int[] c)
Get a submatrix.- Parameters:
i0
- Initial row indexi1
- Final row indexc
- Array of column indices.- Returns:
- A(i0:i1,c(:))
- Throws:
java.lang.ArrayIndexOutOfBoundsException
- Submatrix indices
-
getMatrix
public Matrix getMatrix(int[] r, int j0, int j1)
Get a submatrix.- Parameters:
r
- Array of row indices.j0
- Initial column indexj1
- Final column index- Returns:
- A(r(:),j0:j1)
- Throws:
java.lang.ArrayIndexOutOfBoundsException
- Submatrix indices
-
getNumElements
public int getNumElements()
-
getNumElementsLarger
public int getNumElementsLarger(double val2Compare)
-
getNumElementsEqual
public int getNumElementsEqual(double val2Compare)
-
log
public Matrix log()
Log function from the class Math .- Returns:
- matrix with the natural logarithm (base e) of a double value.
-
diagonalize
public Matrix diagonalize()
-
devide
public Matrix devide(double dDivisor)
-
devideRow
public void devideRow(int row, double denominator)
-
getEigenvector
public static final void getEigenvector(Matrix A, int n, Matrix D, Matrix E)
Householder reduction according num rec 11.2. Followed from an Eigen value decomposition with the calculation of the Eigen vectors according num rec 11.3.- Parameters:
A
- intercept input matrixn
- number of considered eigen valuesD
-E
-
-
getMinRow
public double getMinRow(int row)
- Parameters:
row
- row- Returns:
- smallest value in specified row.
-
getMinRowIndex
public int getMinRowIndex(int row)
- Parameters:
row
- row- Returns:
- the column index of the smallest value in the row.
-
getMinRowIndexRND
public int getMinRowIndexRND(int row)
03.10.04 MvK Shuffles the indices before searching the minimum. This randomizes the search order.- Parameters:
row
- row- Returns:
- the column index of the smallest value in the row.
-
getID
public int getID()
-
getEuclideanDistanceFastRows
public double getEuclideanDistanceFastRows(int iRow, Matrix A, int iRowA)
Skipping the sqrt.- Parameters:
iRow
-A
-iRowA
-- Returns:
-
getEuclideanDistanceFastRows
public double getEuclideanDistanceFastRows(int row1, int row2)
Skipping the sqrt.- Parameters:
row1
-row2
-- Returns:
-
getMaximumValue
public double getMaximumValue()
-
getMean
public double getMean()
-
getMeanCols
public Matrix getMeanCols()
-
getMeanCols
public Matrix getMeanCols(int[] rowIndex)
-
getMeanCol
public double getMeanCol(int col)
-
getMeanRow
public double getMeanRow(int row)
-
getMeanRows
public Matrix getMeanRows()
-
getMeanCol
public double getMeanCol(int iColIndex, int[] rowIndex)
-
getMedian
public double getMedian(int row)
-
getMedian
public double getMedian()
-
getMedianCols
public Matrix getMedianCols()
-
getMaxMin
public Matrix getMaxMin()
max and min vals for all cols- Returns:
- matrix with two rows.
-
getMax
public double getMax()
- Returns:
-
getMax
public double getMax(int col)
get max value for that col.- Parameters:
col
-- Returns:
-
getMaxIndex
public java.awt.Point getMaxIndex()
- Returns:
- Point(row,col) for the largest value.
-
getMaxRow
public double getMaxRow(int row)
-
getMaxRowIndexRND
public int getMaxRowIndexRND(int row)
Shuffles the indices before searching the minimum.- Parameters:
row
- row- Returns:
- the column index of the largest value in the row.
-
getMaxRowIndex
public int getMaxRowIndex(int col)
- Parameters:
col
-- Returns:
- the row index of the largest value in the col.
-
getMin
public double getMin()
-
getMinPos
public ScorePoint getMinPos()
- Returns:
- ValPos
-
getMinRows
public Matrix getMinRows()
- Returns:
- matrix with minimum value from each row.
-
getMinRowsPosCol
public Matrix getMinRowsPosCol()
- Returns:
- matrix dimension n,2. First row contains column position of min val, second col the min value.
-
getMin
public double getMin(int col)
-
getMinColIndex
public int getMinColIndex(int row)
- Parameters:
row
-- Returns:
- column index for the field with the lowest value for the given row.
-
getColIndexContainingMaxVal
public int getColIndexContainingMaxVal(int row)
- Parameters:
row
-- Returns:
- column index for the field with the largest value for the given row.
-
getColIndexContainingMaxVal
public ScorePoint getColIndexContainingMaxVal(int rowEnd, int colEnd)
- Parameters:
rowEnd
- the values in the matrix will be considered until this row (exclusively).colEnd
- the values in the matrix will be considered until this col (exclusively).- Returns:
-
getNormalizedMatrix
public Matrix getNormalizedMatrix()
-
getUpperTriangle
public double[] getUpperTriangle()
For a quadratic matrix only.- Returns:
-
getPythag
public static double getPythag(double a, double b)
pythag computes sqrt(a^2 + b^2) without destructive underflow or overflow.- Parameters:
a
- length ab
- length b- Returns:
- double
-
getPythag2
public static double getPythag2(double a, double b)
-
areRowsEqual
public boolean areRowsEqual(int row1, int row2)
-
equal
public boolean equal(Matrix ma)
-
equal
public boolean equal(Matrix ma, double dLimit)
-
equalDimension
public boolean equalDimension(Matrix ma)
Checks two matrices for equal dimensions.- Parameters:
ma
- matrix to compare with.- Returns:
- true if the number of getColDim and the number of getRowDim are corresponding.
-
hasOnlyFinite
public boolean hasOnlyFinite()
-
multiplyValByVal
public Matrix multiplyValByVal(Matrix ma)
Value by value multiplication Matrices must have the same dimensions.- Parameters:
ma
-- Returns:
-
multiply
public Matrix multiply(double dScalar)
-
multiply
public double multiply(int row1, Matrix ma2, int row2)
-
multiply
public final Matrix multiply(boolean transA, boolean transB, Matrix ma)
Multiplication of two matrices. The algorithm checks for the correct dimensions of the matrices. If the dimensions are not corresponding a runtime exception is thrown. The left matrix is the instantiated object. Algorithm taken from Sedgewick.- Parameters:
transA
- if true the left matrix is transposed before the multiplicationtransB
- if true the right matrix is transposed before the multiplicationma
- right matrix- Returns:
- matrix with dimension getRowDim(), ma.getColDim().
-
getParsed
public static Matrix getParsed(java.util.Vector<java.lang.String> vecStringMatrix) throws java.lang.Exception
Parses an vector with Strings and converts it to a Matrix.- Parameters:
vecStringMatrix
- vector with strings.- Returns:
- Matrix
- Throws:
java.lang.Exception
-
pow
public Matrix pow(double exp)
-
det
public double det()
Matrix determinant- Returns:
- determinant
-
resize
public void resize(int rowsNew, int colsNew)
Resizes the matrix, the old data are written to the new matrix, if possible.- Parameters:
rowsNew
- new number of getRowDim.colsNew
- new number of getColDim.
-
getRow
public double[] getRow(int row)
Flat copy.- Parameters:
row
-- Returns:
-
getRowCopy
public double[] getRowCopy(int row)
-
getRowAsList
public java.util.List<java.lang.Double> getRowAsList(int row)
-
getRowAsFloat
public float[] getRowAsFloat(int row)
-
getRowDim
public int getRowDim()
-
rows
public int rows()
-
getSorted
public Matrix getSorted()
Sorts the row of the matrix according the compareTo(...) function in DoubleVec- Returns:
- sorted matrix
-
getSQRT
public Matrix getSQRT()
-
getSquaredSum
public double getSquaredSum()
-
getStandardDeviationCols
public Matrix getStandardDeviationCols()
-
getStandardDeviation
public double getStandardDeviation()
-
getVariance
public double getVariance()
-
getCoefficientVariation
public double getCoefficientVariation()
Coefficient of variation (CV) is a normalized measure of dispersion of a probability distribution. It is defined as the ratio of the standard deviation sigma to the mean mu.- Returns:
-
getVarianceCol
public double getVarianceCol(int col)
-
getVarianceCentered
public double getVarianceCentered()
-
getVarianceCols
public Matrix getVarianceCols()
- Returns:
- row with variance
-
increase
public void increase(int row, int col, double v)
-
set
public final void set(int row, int col, double v)
-
set
public void set(Matrix ma)
-
set
public void set(double[][] arr)
-
setFlat
public void setFlat(double[][] arr)
-
set
public void set(double v)
-
setID
public void setID(int id)
-
setCol
public void setCol(int col, double v)
-
setCol
public void setCol(int col, double[] arr)
-
setRow
public void setRow(int iRow, double v)
-
setRow
public void setRow(int iRow, double[] arr)
Deep copy- Parameters:
iRow
-arr
-
-
setRow
public void setRow(int iRow, int[] arr)
-
setSeparatorCol
public static void setSeparatorCol(java.lang.String s)
-
setSeparatorRow
public static void setSeparatorRow(java.lang.String s)
-
shuffleRows
public void shuffleRows()
-
swapRows
public void swapRows(int a, int b)
-
sortRows
public void sortRows(int col)
-
getStandardized
public Matrix getStandardized()
Get the standard scores, also known as z-scores.- Returns:
- matrux with standardized values.
-
getSubMatrix
public Matrix getSubMatrix(int indexRowStart, int indexRowEnd, int indexColStart, int indexColEnd)
- Parameters:
indexRowStart
- start row includedindexRowEnd
- end row includedindexColStart
- start col includedindexColEnd
- end col included- Returns:
- matrix
-
getSubMatrix
public Matrix getSubMatrix(java.util.List<java.lang.Integer> liIndexRow)
-
getSum
public double getSum()
-
getSumUpperTriangle
public double getSumUpperTriangle()
Matrix has to be quadratic.- Returns:
-
getSumCols
public Matrix getSumCols()
-
getSumRows
public Matrix getSumRows()
-
getSumCol
public double getSumCol(int col)
-
getSumRow
public double getSumRow(int row)
-
getSumSquared
public double getSumSquared()
-
getNext4NeighboursTorus
public double[] getNext4NeighboursTorus(int row, int col)
-
getNext8NeighboursTorus
public double[] getNext8NeighboursTorus(int row, int col)
-
row2Matrix
public Matrix row2Matrix(int row, int len)
-
getTorus
public double getTorus(int row, int col)
-
getTrace
public double getTrace()
Matrix trace.- Returns:
- sum of the diagonal elements.
-
getTranspose
public Matrix getTranspose()
-
getFlipped
public Matrix getFlipped()
Opposite direction to transpose.
-
toRow
public Matrix toRow()
-
toArray
public double[] toArray()
- Returns:
- deep copy.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
toStringBinary
public java.lang.String toStringBinary()
-
toString
public java.lang.String toString(int digits)
-
toString
public java.lang.String toString(int rowEnd, int colEnd, int digits)
- Parameters:
rowEnd
- exclusivecolEnd
- exclusivedigits
-- Returns:
-
toStringRow
public java.lang.String toStringRow(int row, int iDigits)
-
toStringRowNumber
public java.lang.String toStringRowNumber(int iDigits, java.lang.String sSeparatorCol)
-
subtract
public Matrix subtract(double val)
-
Sign
public static double Sign(double a, double b)
-
getRND
public static Matrix getRND(int rows, int cols)
-
write
public void write(java.lang.String sFile, boolean apppend)
-
write
public void write(java.lang.String sFile)
-
write
public void write(java.io.File fiMa)
-
write
public void write(java.io.File fiMa, boolean apppend, int digits) throws java.io.IOException
- Throws:
java.io.IOException
-
write
public void write(java.lang.String sFiMa, boolean apppend, int digits) throws java.io.IOException
- Throws:
java.io.IOException
-
write
public void write(java.io.File fiMa, java.text.DecimalFormat nf, boolean apppend)
-
write
public void write(java.io.OutputStream os)
-
writeAsLineBase64Encoded
public java.lang.String writeAsLineBase64Encoded()
-
write
public void write(java.io.OutputStream os, java.text.NumberFormat nf)
-
toStringWithColTags
public java.lang.String toStringWithColTags(java.util.List<java.lang.String> liColTags, java.text.DecimalFormat nf, java.lang.String separator)
-
toStringWithRowTags
public java.lang.String toStringWithRowTags(java.util.List<java.lang.String> liRowTags, java.text.DecimalFormat nf, java.lang.String separator)
-
writeSerialized
public void writeSerialized(java.io.File fiOut) throws java.io.IOException
- Throws:
java.io.IOException
-
readSerialized
public static Matrix readSerialized(java.io.File fiIn) throws java.io.FileNotFoundException, java.io.IOException, java.lang.ClassNotFoundException
- Throws:
java.io.FileNotFoundException
java.io.IOException
java.lang.ClassNotFoundException
-
format
public static java.text.DecimalFormat format(int digits)
-
write
public void write(java.lang.String sFile, boolean bApppend, int digits, int totalWidth)
-
format
public static java.lang.String format(double val, java.text.DecimalFormat nf, int totalWidth)
-
-