public class VecPaired<V extends Vec,P> extends 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 |
double[] |
arrayCopy()
Creates a new array that contains all the values of this vector in the
appropriate indices
|
Vec |
clone() |
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) |
static Vec |
extractTrueVec(Vec b)
This method is used assuming multiple VecPaired are used together.
|
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.
|
P |
getPair() |
V |
getVector() |
int |
hashCode()
Provides a hashcode for Vectors.
|
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.
|
double |
kurtosis()
Computes the kurtosis of this vector, which is the 4th moment.
|
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
|
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(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.
|
void |
set(int index,
double val)
Sets the value stored at a specified index in the vector
|
void |
setPair(P pair) |
void |
setVector(V 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(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
Vec.standardDeviation() 2 |
static <V extends Vec,P extends Comparable<P>> |
vecPairedComparator() |
applyFunction, applyIndexFunction, canBeMutated, copyTo, copyToCol, copyToRow, countNaNs, getNonZeroIterator, increment, iterator, multiply, multiply, mutableSubtract, mutableSubtract, random, random, subtract, zeroOut, zeros
finalize, getClass, notify, notifyAll, wait, wait, wait
forEach, spliterator
public P getPair()
public void setPair(P pair)
public V getVector()
public void setVector(V vector)
public int length()
Vec
public int nnz()
Vec
public double get(int index)
Vec
public void set(int index, double val)
Vec
public Vec add(double c)
Vec
this + c
public Vec add(Vec b)
Vec
this + b
public Vec subtract(Vec b)
Vec
this - b
public Vec pairwiseMultiply(Vec b)
Vec
this
by its corresponding value in b
pairwiseMultiply
in class Vec
b
- the vector to pairwise multiply byb
onto the
values of this
public Vec multiply(double c)
Vec
this * c
public void multiply(double c, Matrix A, Vec b)
Vec
public Vec pairwiseDivide(Vec b)
Vec
this
by the value in the same index in b
pairwiseDivide
in class Vec
b
- the vector to pairwise divide bythis
by b
public Vec divide(double c)
Vec
this / c
public void mutableAdd(double c)
Vec
mutableAdd
in class Vec
c
- a scalar constant to add to each value in this vectorpublic void mutableAdd(Vec b)
Vec
mutableAdd
in class Vec
b
- the vector to add to thispublic void mutableSubtract(Vec b)
Vec
mutableSubtract
in class Vec
b
- the vector to subtract from thispublic void mutablePairwiseMultiply(Vec b)
Vec
this
by multiplying each value by the value in b
that has the same index.
mutablePairwiseMultiply
in class Vec
b
- the vector to pairwise multiply bypublic void mutableMultiply(double c)
Vec
this *= c
mutableMultiply
in class Vec
c
- the constant to multiply bypublic void mutablePairwiseDivide(Vec b)
Vec
this
by dividing each value by the value in b
that has the same index
mutablePairwiseDivide
in class Vec
b
- the vector to pairwise divide bypublic void mutableDivide(double c)
Vec
this /= c
mutableDivide
in class Vec
c
- the constant to divide bypublic Vec sortedCopy()
Vec
sortedCopy
in class Vec
public double min()
Vec
public double max()
Vec
public double sum()
Vec
public double mean()
Vec
public double standardDeviation()
Vec
standardDeviation
in class Vec
public double variance()
Vec
Vec.standardDeviation()
2public double median()
Vec
public double skewness()
Vec
public double kurtosis()
Vec
public Vec normalized()
Vec
normalized
in class Vec
public void normalize()
Vec
public double pNormDist(double p, Vec y)
Vec
public double pNorm(double p)
Vec
public double dot(Vec v)
Vec
public double[] arrayCopy()
Vec
public void mutableAdd(double c, Vec b)
Vec
mutableAdd
in class Vec
c
- a scalar constantb
- the vector to add to thispublic Iterator<IndexValue> getNonZeroIterator()
Vec
Iterator.remove()
method.getNonZeroIterator
in class Vec
public static Vec extractTrueVec(Vec b)
b
- a Vec, that may or may not be an instance of VecPaired
public static <V extends Vec,P extends Comparable<P>> Comparator<VecPaired<V,P>> vecPairedComparator()
public int hashCode()
Vec
Vec.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 boolean isSparse()
Vec
Copyright © 2017. All rights reserved.