Package edu.cmu.tetrad.util
Class Vector
java.lang.Object
edu.cmu.tetrad.util.Vector
- All Implemented Interfaces:
TetradSerializable,Serializable
Vector wrapping matrix library.
- Version:
- $Id: $Id
- Author:
- josephramsey
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionVector(double[] data) Constructs a new Vector object from an array of double values.Vector(int size) Constructs a new Vector object with the specified size.Vector(org.apache.commons.math3.linear.RealVector v) Creates a new Vector object from a RealVector object.Vector(org.ejml.simple.SimpleMatrix v) Constructs a new Vector object using a SimpleMatrix instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidassign(double value) assign.voidassign.voidassignPart(int[] range1, Vector from) Updates the specified elements of a data structure with values from the given vector.copy()copy.diag()diag.static MatrixGenerates a diagonal matrix using the elements of the given vector.doubledot.doubledotProduct(Vector v2) dotProduct.booleandoubleCalculates the Euclidean norm (magnitude) of the vector.doubleget(int i) get.getPart(int from, int to) Extracts a subvector from the current vector from specified indices.getSelection(int[] selection) viewSelection.org.ejml.simple.SimpleMatrixRetrieves the SimpleMatrix instance associated with this Vector.like()like.minus.plus.scalarMult(double scalar) scalarMult.static VectorGenerates a simple exemplar of this class to test serialization.voidset(int j, double v) set.intsize()size.doublesum()Computes the sum of all elements in this vector.double[]toArray()toArray.toString()toString.
-
Constructor Details
-
Vector
public Vector(double[] data) Constructs a new Vector object from an array of double values.- Parameters:
data- the array of double values used to initialize the Vector object
-
Vector
public Vector(org.apache.commons.math3.linear.RealVector v) Creates a new Vector object from a RealVector object.- Parameters:
v- the RealVector object to be used for creating the Vector object
-
Vector
public Vector(org.ejml.simple.SimpleMatrix v) Constructs a new Vector object using a SimpleMatrix instance.- Parameters:
v- the SimpleMatrix instance used to initialize the Vector object; it must contain exactly one column, otherwise an IllegalArgumentException is thrown- Throws:
IllegalArgumentException- if the number of columns in the provided SimpleMatrix is not equal to one
-
Vector
public Vector(int size) Constructs a new Vector object with the specified size.- Parameters:
size- the size of the vector- Throws:
IllegalArgumentException- if the size is negative
-
-
Method Details
-
serializableInstance
Generates a simple exemplar of this class to test serialization.- Returns:
- a
Vectorobject
-
diag
Generates a diagonal matrix using the elements of the given vector. The vector's elements will populate the diagonal entries of the resulting square matrix, with all other entries set to zero.- Parameters:
diag- theVectorcontaining the diagonal elements of the matrix- Returns:
- a square
Matrixwith the specified diagonal elements
-
assign
public void assign(double value) assign.
- Parameters:
value- a double
-
assign
assign.
- Parameters:
vector- aVectorobject
-
copy
copy.
- Returns:
- a
Vectorobject
-
diag
diag.
- Returns:
- a
Matrixobject
-
dotProduct
dotProduct.
- Parameters:
v2- aVectorobject- Returns:
- a double
-
get
public double get(int i) get.
- Parameters:
i- a int- Returns:
- a double
-
like
like.
- Returns:
- a
Vectorobject
-
minus
minus.
-
plus
plus.
-
scalarMult
scalarMult.
- Parameters:
scalar- a double- Returns:
- a
Vectorobject
-
set
public void set(int j, double v) set.
- Parameters:
j- a intv- a double
-
size
public int size()size.
- Returns:
- a int
-
toArray
public double[] toArray()toArray.
- Returns:
- an array of objects
-
toString
toString.
-
getSelection
viewSelection.
- Parameters:
selection- an array of objects- Returns:
- a
Vectorobject
-
equals
-
dot
dot.
- Parameters:
v2- aVectorobject- Returns:
- a double
-
getSimpleMatrix
public org.ejml.simple.SimpleMatrix getSimpleMatrix()Retrieves the SimpleMatrix instance associated with this Vector.- Returns:
- the SimpleMatrix representing the data contained within this Vector
-
sum
public double sum()Computes the sum of all elements in this vector.- Returns:
- the sum of all elements as a double
-
getPart
Extracts a subvector from the current vector from specified indices.- Parameters:
from- the starting index (inclusive) of the range; must be non-negative and less than or equal tototo- the ending index (exclusive) of the range; must be less than or equal to the size of the vector- Returns:
- a new
Vectorobject containing the elements from the specified range - Throws:
IllegalArgumentException- iffromis negative,toexceeds the vector size, orfromis greater thanto
-
euclideanNorm
public double euclideanNorm()Calculates the Euclidean norm (magnitude) of the vector. The Euclidean norm is computed as the square root of the sum of the squares of all elements in the vector.- Returns:
- the Euclidean norm of the vector as a double
-
assignPart
Updates the specified elements of a data structure with values from the given vector.- Parameters:
range1- an array of indices specifying the positions in the data structure to be updatedfrom- a Vector containing the values to be added to the elements at the specified indices
-