public class DenseVector extends Object implements Vector
double
based vector
representation.Constructor and Description |
---|
DenseVector(Collection<? extends Number> data)
Constructs a vector, initialized by a collection, with order defined by
its iterator.
|
DenseVector(DenseVector vector)
Copy constructor.
|
DenseVector(double... data)
Constructs a vector, initialized by a
double[] . |
DenseVector(Double[] data)
Constructs a vector, initialized by a
Double[] . |
DenseVector(int length)
Constructs a vector.
|
DenseVector(int[] data)
Constructs a vector, initialized by a
int[] . |
DenseVector(int length,
double value)
Constructs a vector, initialized by repeating a value.
|
DenseVector(List<Double> data)
Constructs a vector, initialized by a
List<Double> . |
DenseVector(Matrix A)
Constructs a vector from a column or row matrix.
|
DenseVector(Vector v)
Casts any vector to a
DenseVector . |
Modifier and Type | Method and Description |
---|---|
DenseVector |
add(DenseVector that) |
DenseVector |
add(double scalar)
Add a constant to all entries in this vector.
|
Vector |
add(Vector that)
\(this + that\)
|
double |
angle(Vector that)
Measure the angle, \(\theta\), between
this and that . |
DenseVector |
deepCopy()
The implementation returns an instance created from
this by the copy
constructor of the class, or just this if the instance itself is
immutable. |
DenseVector |
divide(DenseVector that) |
Vector |
divide(Vector that)
Divide
this by that , entry-by-entry. |
boolean |
equals(Object obj) |
double |
get(int i)
Get the value at position i.
|
int |
hashCode() |
double |
innerProduct(DenseVector that) |
double |
innerProduct(Vector that)
Inner product in the Euclidean space is the dot product.
|
DenseVector |
minus(DenseVector that) |
DenseVector |
minus(double scalar)
Subtract a constant from all entries in this vector.
|
Vector |
minus(Vector that)
\(this - that\)
|
DenseVector |
multiply(DenseVector that) |
Vector |
multiply(Vector that)
Multiply
this by that , entry-by-entry. |
double |
norm()
Compute the length or magnitude or Euclidean norm of a vector, namely, \(\|v\|\).
|
double |
norm(double p)
Gets the \(L^p\)-norm \(\|v\|_p\) of this vector.
|
DenseVector |
opposite()
Get the opposite of this vector.
|
DenseVector |
pow(double scalar)
Take the exponentiation of all entries in this vector, entry-by-entry.
|
DenseVector |
scaled(double c)
Scale this vector by a constant, entry-by-entry.
|
DenseVector |
scaled(Real c)
Scale this vector by a constant, entry-by-entry.
|
void |
set(int from,
DenseVector replacement)
Replaces a sub-vector
v[from : replacement.length] by a
replacement starting at position from . |
void |
set(int i,
double value)
Change the value of an entry in this vector.
|
int |
size()
Get the length of this vector.
|
double[] |
toArray()
Cast this vector into a 1D
double[] . |
String |
toString() |
DenseVector |
ZERO()
Get a 0-vector that has the same length as this vector.
|
public DenseVector(int length)
length
- the length of this vectorpublic DenseVector(int length, double value)
length
- the length of this vectorvalue
- the initial valuepublic DenseVector(double... data)
double[]
.data
- an 1D arraypublic DenseVector(Double[] data)
Double[]
.data
- an 1D arraypublic DenseVector(List<Double> data)
List<Double>
.data
- an 1D arraypublic DenseVector(Collection<? extends Number> data)
data
- a collection of Numberpublic DenseVector(int[] data)
int[]
.data
- an 1D arraypublic DenseVector(Matrix A)
A
- a column or row matrixpublic DenseVector(Vector v)
DenseVector
.v
- a vectorpublic DenseVector(DenseVector vector)
vector
- a vectorpublic int size()
Vector
public void set(int i, double value)
Vector
public void set(int from, DenseVector replacement)
v[from : replacement.length]
by a
replacement starting at position from
.from
- the starting position of the replacementreplacement
- a vector for substitutionIllegalArgumentException
- if the replacement length exceeds the
end of this vectorpublic double get(int i)
Vector
public Vector add(Vector that)
Vector
add
in interface Vector
add
in interface AbelianGroup<Vector>
that
- a vectorpublic DenseVector add(DenseVector that)
public Vector minus(Vector that)
Vector
minus
in interface Vector
minus
in interface AbelianGroup<Vector>
that
- a vectorpublic DenseVector minus(DenseVector that)
public DenseVector scaled(double c)
Vector
vector.scaled(1. / vector.norm())
public DenseVector scaled(Real c)
Vector
vector.scaled(1. / vector.norm())
scaled
in interface Vector
scaled
in interface VectorSpace<Vector,Real>
c
- a constantpublic DenseVector opposite()
Vector
opposite
in interface Vector
opposite
in interface AbelianGroup<Vector>
public Vector multiply(Vector that)
Vector
this
by that
, entry-by-entry.public DenseVector multiply(DenseVector that)
public Vector divide(Vector that)
Vector
this
by that
, entry-by-entry.public DenseVector divide(DenseVector that)
public DenseVector add(double scalar)
Vector
public DenseVector minus(double scalar)
Vector
public DenseVector pow(double scalar)
Vector
public double norm(double p)
Vector
Double.POSITIVE_INFINITY
), \(\|v\|_p =
\max|v_i|\).Double.NEGATIVE_INFINITY
), \(\|v\|_p =
\min|v_i|\).norm
in interface Vector
p
- p ≥ 1, or Double.POSITIVE_INFINITY
or
Double.NEGATIVE_INFINITY
public double norm()
Vector
norm
in interface Vector
norm
in interface BanachSpace<Vector,Real>
public double angle(Vector that)
Vector
this
and that
.
That is,
\[
this \cdot that = \|this\| \times \|that\| \times \cos \theta
\]public double innerProduct(Vector that)
Vector
innerProduct
in interface Vector
innerProduct
in interface HilbertSpace<Vector,Real>
that
- a vectorpublic double innerProduct(DenseVector that)
public DenseVector ZERO()
Vector
ZERO
in interface Vector
ZERO
in interface AbelianGroup<Vector>
public double[] toArray()
Vector
double[]
.public DenseVector deepCopy()
DeepCopyable
this
by the copy
constructor of the class, or just this
if the instance itself is
immutable.deepCopy
in interface Vector
deepCopy
in interface DeepCopyable
Copyright © 2010-2020 NM FinTech Ltd.. All Rights Reserved.