|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object mpv2.SparseVector
public class SparseVector
This class is a sparse vector implementation.
The class SparseVector class stores only the non-zero elements of the vector. Read access is fast, but write access (set a new non-zero element) need to change the whole vector.
Constructor Summary | |
---|---|
SparseVector(double[] v)
Construct a sparse vector from an array. |
|
SparseVector(int n)
Construct a length n sparse vector of zeros. |
|
SparseVector(int n,
int[] ind,
double[] vals)
Construct a length n sparse vector with non-zero indices and values supplied. |
Method Summary | |
---|---|
void |
addToArray(double factor,
double[] x)
Add this sparse vector multiplied by a factor to the given array. |
java.lang.Object |
clone()
Clone the SparseVector object. |
SparseVector |
copy()
Make a deep copy of a SparseVector. |
double[] |
get()
Get the whole vector as an array |
double |
get(int n)
Get a vector element. |
int[] |
getIndices()
Access the non-zero indices |
int |
getLength()
Returns the lengt of the sparse vector |
int |
getN()
Returns the lengt of the sparse vector |
int |
getNonZeroCount()
Returns number of non-zeros elements in sparse matrix. |
double[] |
getSubVector(int i0,
int i1)
Get a subvector as an array |
double[] |
getValues()
Access the non-zero values |
double |
innerProduct()
innerProduct of this sparse vector to itself |
double |
innerProduct(double[] v)
innerProduct of this and an array if lengths do not match, the shortest vector is extended with zeros |
double |
innerProduct(SparseVector v)
innerProduct of this and another sparse vector if lengths do not match, the shortest vector is extended with zeros |
int |
norm0()
The pseudo-zero-norm, do not count any zeros stored (which may happen) |
double |
norm1()
One norm |
double |
norm2()
Two norm |
double |
normInf()
Inf norm |
void |
print()
Print the sparse vector to stdout. |
void |
print(int w,
int d)
Print the sparse vector to stdout. |
void |
print(java.text.NumberFormat format,
int width)
Print the sparse vector to stdout. |
void |
print(java.io.PrintWriter output,
int w,
int d)
Print the sparse vector to stdout. |
void |
print(java.io.PrintWriter output,
java.text.NumberFormat format,
int width)
Print the sparse vector to stdout. |
void |
set(int n,
double val)
Set a vector element. |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SparseVector(int n)
n
- length of vectorpublic SparseVector(double[] v)
v
- array of doubles.public SparseVector(int n, int[] ind, double[] vals)
n
- length of vectorind
- indices for the non-zero valuesvals
- the non-zero valuesMethod Detail |
---|
public SparseVector copy()
public java.lang.Object clone()
clone
in class java.lang.Object
public double[] get()
public double[] getSubVector(int i0, int i1)
public double get(int n)
n
- index number
public double[] getValues()
public int[] getIndices()
public void set(int n, double val)
n
- index numberval
- the value to be put into the given entry of the dictionary.
java.lang.ArrayIndexOutOfBoundsException
public int getN()
public int getLength()
public int getNonZeroCount()
public void addToArray(double factor, double[] x)
factor
- a factor to multiply the column vector by.x
- an arraypublic int norm0()
public double norm1()
public double norm2()
public double normInf()
public double innerProduct()
public double innerProduct(double[] v)
public double innerProduct(SparseVector v)
public void print()
public void print(int w, int d)
w
- Column width.d
- Number of digits after the decimal.public void print(java.io.PrintWriter output, int w, int d)
output
- Output stream.w
- Column width.d
- Number of digits after the decimal.public void print(java.text.NumberFormat format, int width)
format
- A Formatting object for individual elements.width
- Field width for each column.DecimalFormat.setDecimalFormatSymbols(java.text.DecimalFormatSymbols)
public void print(java.io.PrintWriter output, java.text.NumberFormat format, int width)
output
- the output stream.format
- A formatting object to format the matrix elementswidth
- Column width.DecimalFormat.setDecimalFormatSymbols(java.text.DecimalFormatSymbols)
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |