public abstract class Vec extends Object implements Cloneable, Iterable<IndexValue>, Serializable
Constructor and Description |
---|
Vec() |
Modifier and Type | Method and Description |
---|---|
Vec |
add(double c)
Returns a new vector that is the result of
this + c |
Vec |
add(Vec b)
Returns a new vector that is the result of
this + b |
void |
applyFunction(Function f)
Applies the given function to each and every value in the vector.
|
void |
applyIndexFunction(IndexFunction f)
Applies the given function to each and every value in the vector.
|
double[] |
arrayCopy()
Creates a new array that contains all the values of this vector in the
appropriate indices
|
boolean |
canBeMutated()
Indicates whether or not this vector can be mutated.
|
abstract Vec |
clone() |
void |
copyTo(Vec destination)
Copies the values of this Vector into another vector
|
void |
copyToCol(Matrix A,
int col)
Copies the values of this vector into a column of another Matrix.
|
void |
copyToRow(Matrix A,
int row)
Copies the values of this vector into a row of another Matrix
|
int |
countNaNs() |
Vec |
divide(double c)
Returns a new vector that is the result of
this / c |
double |
dot(Vec v)
Computes the dot product between two vectors, which is equivalent to
Σ thisi*vi This method should be overloaded for a serious implementation. |
boolean |
equals(Object obj) |
boolean |
equals(Object obj,
double range) |
abstract double |
get(int index)
Gets the value stored at a specific index in the vector
|
Iterator<IndexValue> |
getNonZeroIterator()
Returns an iterator that will go over the non zero values in the given
vector.
|
Iterator<IndexValue> |
getNonZeroIterator(int start)
Returns an iterator that will go over the non zero values starting from
the specified index in the given vector.
|
int |
hashCode()
Provides a hashcode for Vectors.
|
void |
increment(int index,
double val)
Increments the value stored at a specified index in the vector
|
abstract boolean |
isSparse()
Indicates whether or not this vector is optimized for sparce computation,
meaning that most values in the vector are zero - and considered
implicit.
|
Iterator<IndexValue> |
iterator() |
double |
kurtosis()
Computes the kurtosis of this vector, which is the 4th moment.
|
abstract int |
length()
Returns the length of this vector
|
double |
max()
Returns the maximum value stored in this vector
|
double |
mean()
Computes the mean value of all values stored in this vector
|
double |
median()
Returns the median value in this vector
|
double |
min()
Returns the minimum value stored in this vector
|
Vec |
multiply(double c)
Returns a new vector that is the result of
this * c |
void |
multiply(double c,
Matrix A,
Vec b)
If this is vector a, this this computes b = b + c aT*A
|
Vec |
multiply(Matrix A)
Returns a new vector that is the result of the vector matrix product
thisTA
|
void |
multiply(Matrix A,
Vec b)
If this is vector a, this this computes b = b + aT*A
|
void |
mutableAdd(double c)
Alters this vector such that
this = this + c
This method should be overloaded for a serious implementation. |
void |
mutableAdd(double c,
Vec b)
Alters this vector such that
this = this + c * b
This method should be overloaded for a serious implementation. |
void |
mutableAdd(Vec b)
Alters this vector such that
this = this + b
|
void |
mutableDivide(double c)
Mutates
this /= c
This method should be overloaded for a serious implementation. |
void |
mutableMultiply(double c)
Mutates
this *= c
This method should be overloaded for a serious implementation. |
void |
mutablePairwiseDivide(Vec b)
Mutates
this by dividing each value by the value in b
that has the same index
This method should be overloaded for a serious implementation. |
void |
mutablePairwiseMultiply(Vec b)
Mutates
this by multiplying each value by the value in b
that has the same index. |
void |
mutableSubtract(double c)
Alters this vector such that
this = this - c
|
void |
mutableSubtract(double c,
Vec b)
Alters this vector such that
this = this - c * b
|
void |
mutableSubtract(Vec b)
Alters this vector such that
this = this - b
|
int |
nnz()
Computes the number of non zero values in this vector
|
void |
normalize()
Mutates this vector to be normalized by the L2 norm
|
Vec |
normalized()
Returns a new vector that is the result of normalizing this vector by the
L2 norm
|
Vec |
pairwiseDivide(Vec b)
Returns a new vector that is the result of dividing each value in
this by the value in the same index in b |
Vec |
pairwiseMultiply(Vec b)
Returns a new vector that is the result of multiplying each value in
this by its corresponding value in b |
double |
pNorm(double p)
Returns the p-norm of this vector.
|
double |
pNormDist(double p,
Vec y)
Returns the p-norm distance between this and another vector y.
|
static Vec |
random(int length)
Creates a dense vector full of random values in the range [0, 1]
|
static Vec |
random(int length,
Random rand)
Creates a dense vector full of random values in the range [0, 1]
|
abstract void |
set(int index,
double val)
Sets the value stored at a specified index in the vector
|
double |
skewness()
Computes the skewness of this vector, which is the 3rd moment.
|
Vec |
sortedCopy()
Returns a copy of this array with the values moved around so that they are in sorted order
|
double |
standardDeviation()
Computes the standard deviation of the values in this vector
|
Vec |
subtract(double c)
Returns a new vector that is the result of
this - c |
Vec |
subtract(Vec b)
Returns a new vector that is the result of
this - b |
double |
sum()
Computes the sum of the values in this vector
|
String |
toString() |
double |
variance()
Computes the variance of the values in this vector, which is
standardDeviation() 2 |
void |
zeroOut()
Zeroes out all values in this vector
This method should be overloaded for a serious implementation. |
static Vec |
zeros(int length)
Creates a dense vector full of zeros.
|
finalize, getClass, notify, notifyAll, wait, wait, wait
forEach, spliterator
public abstract int length()
public int countNaNs()
public boolean canBeMutated()
false
, any method that contains "mutate" will not work.
true
true
if the vector supports being altered, false
other wise.public int nnz()
public abstract double get(int index)
index
- the index to accessIndexOutOfBoundsException
- if the index given is greater than or
equal to its length()
public abstract void set(int index, double val)
index
- the index to accessval
- the value to store in the indexIndexOutOfBoundsException
- if the index given is greater than or
equal to its length()
public void increment(int index, double val)
index
- the index to accessval
- the value to store in the indexIndexOutOfBoundsException
- if the index given is greater than or
equal to its length()
public Vec add(double c)
this + c
c
- the constant to addc
to this
public Vec add(Vec b)
this + b
b
- the vector to addb + this
public Vec subtract(double c)
this - c
c
- the constant to subtractthis - c
public Vec subtract(Vec b)
this - b
b
- the vector to subtract from this
this - b
public Vec pairwiseMultiply(Vec b)
this
by its corresponding value in b
b
- the vector to pairwise multiply byb
onto the
values of this
public Vec multiply(double c)
this * c
c
- the constant to multiply bythis * c
public Vec multiply(Matrix A)
A
- the matrix to multiply withpublic void multiply(Matrix A, Vec b)
A
- the matrix to multiple byb
- the vector to mutate by adding the result topublic void multiply(double c, Matrix A, Vec b)
c
- the constant factor to multiply byA
- the matrix to multiple byb
- the vector to mutate by adding the result topublic Vec pairwiseDivide(Vec b)
this
by the value in the same index in b
b
- the vector to pairwise divide bythis
by b
public Vec divide(double c)
this / c
c
- the constant to divide bythis / c
public void mutableAdd(double c)
c
- a scalar constant to add to each value in this vectorpublic void mutableAdd(double c, Vec b)
c
- a scalar constantb
- the vector to add to thispublic void mutableAdd(Vec b)
b
- the vector to add to thisArithmeticException
- if the vectors do not have the same lengthpublic void mutableSubtract(double c)
c
- the scalar constant to subtract from all values in this vectorpublic void mutableSubtract(double c, Vec b)
c
- a scalar constantb
- the vector to subtract from thisArithmeticException
- if the vectors do not have the same lengthpublic void mutableSubtract(Vec b)
b
- the vector to subtract from thisArithmeticException
- if the vectors are not the same lengthpublic void mutablePairwiseMultiply(Vec b)
this
by multiplying each value by the value in b
that has the same index.
b
- the vector to pairwise multiply bypublic void mutableMultiply(double c)
this *= c
c
- the constant to multiply bypublic void mutablePairwiseDivide(Vec b)
this
by dividing each value by the value in b
that has the same index
b
- the vector to pairwise divide bypublic void mutableDivide(double c)
this /= c
c
- the constant to divide bypublic Vec sortedCopy()
public double min()
public double max()
public double sum()
public double mean()
public double standardDeviation()
public double variance()
standardDeviation()
2public double median()
public double skewness()
public double kurtosis()
public abstract boolean isSparse()
public void copyTo(Vec destination)
destination
- the vector to store the values in.ArithmeticException
- if the vectors are not of the same lengthpublic void copyToRow(Matrix A, int row)
A
- the matrix to store the contents of this vector inrow
- the row of the matrix to store the values toArithmeticException
- if the columns of the matrix is not the same as the length of this vector.public void copyToCol(Matrix A, int col)
A
- the matrix to store the contents of this vector incol
- the column of the matrix to store the values topublic Vec normalized()
public void normalize()
public void applyFunction(Function f)
f
- the single variable function to applypublic void applyIndexFunction(IndexFunction f)
f
- the 2 dimensional index function to applypublic double pNormDist(double p, Vec y)
p
- the distance type. 2 is the common valuey
- the other vector to compare againstpublic double pNorm(double p)
p
- the norm type. 2 is a common valuepublic double dot(Vec v)
v
- the other vectorpublic boolean equals(Object obj, double range)
public double[] arrayCopy()
public Iterator<IndexValue> iterator()
iterator
in interface Iterable<IndexValue>
public Iterator<IndexValue> getNonZeroIterator()
Iterator.remove()
method.public Iterator<IndexValue> getNonZeroIterator(int start)
Iterator.remove()
method.
start
- the first index (inclusive) to start returning non-zero
values frompublic void zeroOut()
public int hashCode()
equals(java.lang.Object)
returns true.
Below is the code used for this class
int result = 1;
for (int i = 0; i < length(); i++)
{
double val = get(i);
if(val != 0)
{
long bits = Double.doubleToLongBits(val);
result = 31 * result + (int)(bits ^ (bits >>> 32));
result = 31 * result + i;
}
}
return 31* result + length();
public static Vec random(int length)
length
- the length of the random vector to createpublic static Vec random(int length, Random rand)
length
- the length of the random vector to createrand
- the source of randomnesspublic static Vec zeros(int length)
length
- the length of the vector to createCopyright © 2017. All rights reserved.