|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.strbio.math.DVector
public class DVector
a class to encapsulate a 1-D array of doubles. Can do a bunch of math functions, and save/load from a file.
Version 1.21, 7/7/99 - added equals Version 1.2, 7/6/99 - added findNClosest, append, reverse Version 1.13, 6/7/99 - added print, changed some PrintfStream to Printf Version 1.12, 6/2/99 - added median, print Version 1.11, 4/16/99 - some error conditions (i.e. min() when there's no data) return Double.NaN, instead of (incorrect) 0.0. Version 1.1, 9/30/98 - added linearFit Version 1.01, 5/11/98 - added constructors from IVector, int[]. Version 1.0, 3/30/98 - original version.
IVector
,
DMatrix
Field Summary | |
---|---|
double[] |
data
data contains the actual array 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 'dv.data[0] = tmp' as well as 'tmp = dv.data[0]' without needing 2 different functions. |
Constructor Summary | |
---|---|
DVector()
makes a blank vector of dimension 0; you can assign a int[] to the data directly, or load data in from a file |
|
DVector(double[] x)
makes a new DVector object out of a int[] array. |
|
DVector(DVector x)
copies another DVector. |
|
DVector(int dim)
makes an emptry DVector object with a specified dimension All data should be zeroed out... this is not done explicitly, but relies on Java's default values. |
|
DVector(int[] x)
makes a new DVector object out of a int[] array. |
|
DVector(IVector x)
copies an IVector, copying the data and casting to doubles. |
Method Summary | |
---|---|
void |
add(DVector x)
Adds another DVector to this one. |
static DVector |
add(DVector a,
DVector b)
Adds two DVector's and returns a new DVector containing the sum. |
void |
append(DVector x)
appends the contents of another DVector to this one. |
static DVector |
append(DVector x,
DVector y)
Returns a new DVector containing the first argument appended to the second. |
double |
average()
Returns the average value in the array. |
double |
averageRW()
Returns the average value in the array, weighting each value using reciprocal weighting. |
double |
covar(DVector y)
Returns the covariance of values in this array with those in another array. |
DVector |
cross(DVector x)
Returns the cross product of multiplying this with another vector. |
static DVector |
cross(DVector x,
DVector y)
Returns the cross product of multiplying two vectors. |
int |
dimension()
returns the dimension the encapsulated array. |
double |
distance(DVector x)
Returns the distance between this point and one pointed two by another DVector. |
static double |
distance(DVector a,
DVector b)
Returns the distance between two points pointed to by DVectors a and b. |
void |
divide(double x)
Divides this DVector by a specified double. |
static DVector |
divide(DVector a,
double b)
Divides a DVector by a double, and returns a new DVector containing the result. |
double |
dot(DVector x)
Returns the dot product of multiplying this with another vector. |
static double |
dot(DVector x,
DVector y)
Returns the dot product of multiplying two vectors. |
boolean |
equals(java.lang.Object x)
mathematical objects are equal if their contents are. |
IVector |
findNClosest(int n,
double v)
What are the indices of the N closest values to a given double? |
int |
length()
returns the dimension the encapsulated array. |
double[] |
linearFit(DVector y)
This will return the best linear fit to a bunch of points, assuming that this DVector contains x's, and DVectory y contains y's. |
void |
load(java.io.BufferedReader infile)
Load from an open BufferedReader. |
void |
load(java.lang.String filename)
Loads from a text file. |
DVector |
makeZScores()
returns a vector containing the Z scores for all data in the array. |
double |
max()
What's the maximum value in the array? |
double |
median()
Returns the median value in the array. |
double |
min()
What's the minimum value in the array? |
void |
multiply(DMatrix x)
Multplies this DVector by a DMatrix. |
static DVector |
multiply(DMatrix b,
DVector a)
Multplies a DVector by a DMatrix, and returns a new DVector with the result. |
void |
multiply(double x)
Multiplies all values in this DVector by a specified int. |
static DVector |
multiply(double b,
DVector a)
Multiplies a DVector by an int and returns a new DVector containing the result. |
static DVector |
multiply(DVector a,
DMatrix b)
Multplies a DVector by a DMatrix, and returns a new DVector with the result. |
static DVector |
multiply(DVector a,
double b)
Multiplies a DVector by an int and returns a new DVector containing the result. |
double |
norm()
What's the norm of this array? |
double |
normalize()
Rescale array so the norm is one. |
double |
pearson(DVector y)
Returns the Pearson correlation coefficient R of values in this array with values in another array. |
void |
print(Printf outfile)
prints in ascii to an open Printf, with a nicer format than 'save'. |
void |
reverse()
reverses the order of data in the vector. |
static DVector |
reverse(DVector x)
returns a vector which is the reverse of this one. |
void |
save(Printf outfile)
Save to an open Printf. |
void |
save(java.lang.String filename)
Saves to a new text file. |
void |
setValue(double x)
Sets every value in the array to a specified double. |
void |
setValueAt(int x,
double d)
Sets the data at a given index. |
IVector |
sort()
returns a vector of indices to sort an DVector (small -> large). |
double |
stdev()
Returns the standard deviation of a distribution containing all values in the array. |
double |
stdevp()
Returns the standard deviation of a distribution containing all values in the array. |
void |
subtract(DVector x)
Subtracts another DVector from this one. |
static DVector |
subtract(DVector a,
DVector b)
Subtracts one DVector's from another returns a new DVector containing the difference. |
void |
transform(DMatrix x)
transforms this vector using a transformation DMatrix. |
double |
valueAt(int x)
Returns the data at a given index. |
double |
zScore(double x)
Shows how many standard deviations (of this array) a given double is below the average (of this array) |
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 DVector(int dim)
dim
- dimensionpublic DVector()
public DVector(double[] x)
public DVector(DVector x)
public DVector(int[] x)
public DVector(IVector x)
Method Detail |
---|
public boolean equals(java.lang.Object x)
equals
in class java.lang.Object
public final int length()
public final int dimension()
public final double valueAt(int x)
x
- indexpublic final void setValueAt(int x, double d)
x
- indexd
- value to set the data topublic final void setValue(double x)
public final void add(DVector x)
public static final DVector add(DVector a, DVector b)
public final void append(DVector x)
public static final DVector append(DVector x, DVector y)
public final void reverse()
public static final DVector reverse(DVector x)
public final void subtract(DVector x)
public static final DVector subtract(DVector a, DVector b)
public final void multiply(double x)
public static final DVector multiply(DVector a, double b)
public static final DVector multiply(double b, DVector a)
public final void multiply(DMatrix x)
public static final DVector multiply(DVector a, DMatrix b)
public static final DVector multiply(DMatrix b, DVector a)
public final void divide(double x)
public static final DVector divide(DVector a, double b)
public final double norm()
public final double normalize()
DMatrix.normalize()
public static final double distance(DVector a, DVector b)
public final double distance(DVector x)
public final double dot(DVector x)
public static final double dot(DVector x, DVector y)
public final DVector cross(DVector x)
public static final DVector cross(DVector x, DVector y)
public final double average()
public final double averageRW()
public final double median()
public final double stdev()
public final double stdevp()
public final double covar(DVector y)
java.lang.IllegalArgumentException
- if the arrays are not the same size.public final double pearson(DVector y)
java.lang.IllegalArgumentException
- if the arrays are not the same size.public final double[] linearFit(DVector y)
public final double zScore(double x)
makeZScores()
public final double max()
public final double min()
public final IVector findNClosest(int n, double v)
public final DVector makeZScores()
zScore(double)
public final void transform(DMatrix x)
DMatrix.makeTransform(double, double, double, double, double, double)
public IVector sort()
public void print(Printf outfile) 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 load(java.io.BufferedReader infile) throws java.io.IOException
java.io.IOException
BufferedReader
public void save(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 |