|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.strbio.math.DMatrix
public class DMatrix
a class to encapsulate a 2-D matrix of doubles. Can do a bunch of math/statistics functions, and save/load from a file. The binary loading methods are usually 3-4 times faster than ascii; saves go at about the same speed (sometimes ascii is faster than binary due to superior buffering).
Version 1.33, 7/7/99 - added equals Version 1.32, 4/16/99 - some error conditions (i.e. min() when there's no data) return Double.NaN, instead of (incorrect) 0.0. Version 1.31, 1/25/99 - made save/load methods non-final, changed most instances of PrintfStream to generic Printf Version 1.3, 10/29/98 - added makeInverseTransform() Version 1.2, 5/18/98 - added saveBinary, more load() methods. load(filename) now autodetects binary/ascii files. Version 1.13, 5/11/98 - added constructors from IMatrix, int[][]. Version 1.12, 4/29/98 - added saveDplot Version 1.11, 4/28/98 - fixed a couple of saving bugs, normalize(), removed norm(). Version 1.1, 4/9/98 - added add(double), makeTransform(), and print() Version 1.0, 3/30/98 - original version
IMatrix
,
DVector
,
DHalfMatrix
Field Summary | |
---|---|
double[][] |
data
data contains the actual matrix itself; it's public so that it can be manipulated directly (for speed, such as that is in java) and so that you can do something like 'dm.data[0][0] = tmp' as well as 'tmp = dm.data[0][0]' without needing 2 different functions. |
Constructor Summary | |
---|---|
DMatrix()
makes a blank 0x0 matrix; you can assign a double[][] to the data directly, or load data in from a file |
|
DMatrix(DMatrix x)
copies another DMatrix. |
|
DMatrix(double[][] x)
makes a new DMatrix object out of a double[][] array. |
|
DMatrix(IMatrix x)
copies an IMatrix, making a copy of the data, and casting to doubles. |
|
DMatrix(int[][] x)
makes a new DMatrix object out of an int[][] array, copying the data and casting to doubles. |
|
DMatrix(int c,
int r)
makes an emptry DMatrix object with a specified number of columns and rows. |
Method Summary | |
---|---|
void |
add(DMatrix x)
Adds another DMatrix to this one. |
static DMatrix |
add(DMatrix a,
DMatrix b)
Adds two DMatrix's and returns a new DMatrix containing the sum. |
void |
add(double x)
Adds a double to every value in this DMatrix. |
double |
average()
Returns the average value in the matrix. |
int |
cols()
returns the number of columns in the encapsulated array. |
double |
covar(DMatrix y)
Returns the covariance of values in this matrix with those in another matrix. |
void |
diffuse()
This does a single round of 'diffusive smoothing' on the matrix. |
static DMatrix |
divide(DMatrix a,
int b)
Divides a DMatrix by a double, and returns a new DMatrix containing the result. |
void |
divide(double x)
Divides this DMatrix by a specified double. |
boolean |
equals(java.lang.Object x)
mathematical objects are equal if their contents are. |
DMatrix |
inverse()
Returns the inverse of this matrix. |
boolean |
isEmpty()
Does the matrix contain all zeroes? |
void |
load(java.io.BufferedReader infile)
Load Ascii from an open BufferedReader. |
void |
load(java.io.DataInputStream infile)
Load binary matrix from an open DataInputStream. |
void |
load(java.lang.String filename)
Loads matrix from a file; file type (text/binary) is autodetected. |
static DMatrix |
makeInverseTransform(double x,
double y,
double z,
double phi,
double theta,
double psi)
Return an inverse transformation matrix given 3 transformation coordinates and 3 Euler rotation angles. |
static DMatrix |
makeTransform(double x,
double y,
double z,
double phi,
double theta,
double psi)
Return a transformation matrix given 3 transformation coordinates and 3 Euler rotation angles. |
double |
max()
What's the maximum value in the matrix? |
double |
mean()
Returns the mean value in the matrix. |
double |
min()
What's the minimum value in the matrix? |
DMatrix |
multiply(DMatrix x)
Multiples this DMatrix by another DMatrix, and returns another DMatrix containing the result. |
static DMatrix |
multiply(DMatrix a,
DMatrix b)
Multiplies two DMatrix's, and returns another DMatrix containing the result. |
static DMatrix |
multiply(DMatrix a,
double b)
Multiplies a DMatrix by a double and returns a new DMatrix containing the result. |
void |
multiply(double x)
Multiplies all values in this DMatrix by a specified double. |
static DMatrix |
multiply(double b,
DMatrix a)
Multiplies a DMatrix by a double and returns a new DMatrix containing the result. |
void |
normalize()
Rescale matrix so the average is one. |
double |
pearson(DMatrix y)
Returns the Pearson correlation coefficient R of values in this matrix with values in another matrix. |
void |
print(Printf outfile)
prints in ascii to an open Printf, with a nicer format than 'save'. |
void |
print(java.lang.String filename)
prints in ascii to a new file, with a nicer format than 'save'. |
void |
rescale(double offset,
double scale)
Rescales every value in this DMatrix: data[i][j] -> (data[i][j] + offset) * scale |
void |
rescaleTo(double newMean,
double newSD)
Rescales to a given mean and standard deviation. |
int |
rows()
returns the number of rows in the encapsulated array. |
void |
save(Printf outfile)
Save to an open Printf. |
void |
save(java.lang.String filename)
Saves to a new text file. |
void |
saveBinary(java.io.DataOutputStream outfile)
Save in binary format to an open DataOutputStream. |
void |
saveBinary(java.lang.String filename)
Saves to a new binary file. |
void |
saveDplot(java.lang.String filename)
Saves in Dplot (ASGL) format to a new text file. |
void |
setValue(double x)
Sets every value in the matrix to a specified double. |
void |
setValueAt(int c,
int r,
double d)
Sets the data at a given column/row. |
void |
smooth(double minValid,
int maxTolerance)
This function smooths the matrix by averaging over adjacent blocks. |
void |
smoothPeriodic(double minValid,
int maxTolerance)
This function smooths the matrix by averaging over adjacent blocks. |
double |
stdev()
Returns the standard deviation of a distribution containing all values in the matrix. |
double |
stdevp()
Returns the standard deviation of a distribution containing all values in the matrix. |
void |
subtract(DMatrix x)
Subtracts another DMatrix from this one. |
static DMatrix |
subtract(DMatrix a,
DMatrix b)
Subtracts one DMatrix's from another returns a new DMatrix containing the difference. |
void |
subtract(double x)
Subtracts a double to every value in this DMatrix. |
DMatrix |
transpose()
Returns the transpose of this DMatrix. |
double |
valueAt(int c,
int r)
Returns the data at a given column/row. |
double |
zScore(double x)
Shows how many standard deviations (of this matrix) a given double is below the average (of this matrix) |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public double[][] data
Constructor Detail |
---|
public DMatrix(int c, int r)
c
- columnsr
- rowspublic DMatrix()
public DMatrix(double[][] x)
public DMatrix(DMatrix x)
public DMatrix(int[][] x)
public DMatrix(IMatrix x)
Method Detail |
---|
public boolean equals(java.lang.Object x)
equals
in class java.lang.Object
public final int cols()
public final int rows()
public final double valueAt(int c, int r)
c
- columnr
- rowpublic final void setValueAt(int c, int r, double d)
c
- columnr
- rowd
- value to set the data topublic final void setValue(double x)
public final DMatrix inverse()
public final void add(DMatrix x)
public final void add(double x)
public static final DMatrix add(DMatrix a, DMatrix b)
public final void subtract(DMatrix x)
public final void subtract(double x)
public static final DMatrix subtract(DMatrix a, DMatrix b)
public final void multiply(double x)
public static final DMatrix multiply(DMatrix a, double b)
public static final DMatrix multiply(double b, DMatrix a)
public final DMatrix multiply(DMatrix x)
java.lang.IllegalArgumentException
- if the
number of rows/columns in the two matrices don't
match up (the number of rows and columns in B
must match the number of columns and rows in A).public static final DMatrix multiply(DMatrix a, DMatrix b)
java.lang.IllegalArgumentException
- if the
number of rows/columns in the two matrices don't
match up (the number of rows and columns in B
must match the number of columns and rows in A).public final void divide(double x)
public static final DMatrix divide(DMatrix a, int b)
public final void rescale(double offset, double scale)
offset
- value added to datascale
- data is multiplied by this after offset is addedpublic final void rescaleTo(double newMean, double newSD)
average()
,
stdev()
public final DMatrix transpose()
public final boolean isEmpty()
public final double max()
public final double min()
public final void normalize()
DVector.normalize()
public final double average()
public final double mean()
public final double stdev()
public final double stdevp()
public final double covar(DMatrix y)
java.lang.IllegalArgumentException
- if the matrices are not the same size.public final double pearson(DMatrix y)
java.lang.IllegalArgumentException
- if the matrices are not the same size.public final double zScore(double x)
public final void smooth(double minValid, int maxTolerance)
minValid
- N, include at least this many samples before averaging.maxTolerance
- don't expand the rectangle more than this
many units. 0 = 1x1 maximum, 1 = 3x3 maximum, etc.public final void smoothPeriodic(double minValid, int maxTolerance)
minValid
- N, include at least this many samples before averaging.maxTolerance
- don't expand the circle more than this
many units. 0 = 0 units away, 1 = 1 units away, etc.public final void diffuse()
public static final DMatrix makeTransform(double x, double y, double z, double phi, double theta, double psi)
DVector.transform(org.strbio.math.DMatrix)
public static final DMatrix makeInverseTransform(double x, double y, double z, double phi, double theta, double psi)
DVector.transform(org.strbio.math.DMatrix)
public void print(Printf outfile) throws java.io.IOException
java.io.IOException
save(org.strbio.io.Printf)
public void print(java.lang.String filename) throws java.io.IOException
java.io.IOException
save(org.strbio.io.Printf)
public void save(Printf outfile) throws java.io.IOException
java.io.IOException
Printf
public void saveBinary(java.io.DataOutputStream outfile) throws java.io.IOException
java.io.IOException
public final void saveDplot(java.lang.String filename) throws java.io.IOException
filename
- the file name.
java.io.IOException
public void load(java.io.BufferedReader infile) throws java.io.IOException
java.io.IOException
public void load(java.io.DataInputStream infile) throws java.io.IOException
java.io.IOException
public void save(java.lang.String filename) throws java.io.IOException
filename
- the file name.
java.io.IOException
public void saveBinary(java.lang.String filename) throws java.io.IOException
filename
- the file name.
java.io.IOException
public void load(java.lang.String filename) throws java.io.IOException
filename
- the file name.
java.io.IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |