Class Vector

java.lang.Object
edu.cmu.tetrad.util.Vector
All Implemented Interfaces:
TetradSerializable, Serializable

public class Vector extends Object implements TetradSerializable
Vector wrapping matrix library.
Version:
$Id: $Id
Author:
josephramsey
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Vector(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 Type
    Method
    Description
    void
    assign(double value)
    assign.
    void
    assign(Vector vector)
    assign.
    void
    assignPart(int[] range1, Vector from)
    Updates the specified elements of a data structure with values from the given vector.
    copy.
    diag.
    static Matrix
    diag(Vector diag)
    Generates a diagonal matrix using the elements of the given vector.
    double
    dot(Vector v2)
    dot.
    double
    dotProduct.
    boolean
    double
    Calculates the Euclidean norm (magnitude) of the vector.
    double
    get(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.SimpleMatrix
    Retrieves the SimpleMatrix instance associated with this Vector.
    like.
    minus.
    plus.
    scalarMult(double scalar)
    scalarMult.
    static Vector
    Generates a simple exemplar of this class to test serialization.
    void
    set(int j, double v)
    set.
    int
    size.
    double
    sum()
    Computes the sum of all elements in this vector.
    double[]
    toArray.
    toString.

    Methods inherited from class java.lang.Object

    getClass, hashCode, notify, notifyAll, wait, wait, wait
  • 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

      public static Vector serializableInstance()
      Generates a simple exemplar of this class to test serialization.
      Returns:
      a Vector object
    • diag

      public static Matrix diag(Vector 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 - the Vector containing the diagonal elements of the matrix
      Returns:
      a square Matrix with the specified diagonal elements
    • assign

      public void assign(double value)

      assign.

      Parameters:
      value - a double
    • assign

      public void assign(Vector vector)

      assign.

      Parameters:
      vector - a Vector object
    • copy

      public Vector copy()

      copy.

      Returns:
      a Vector object
    • diag

      public Matrix diag()

      diag.

      Returns:
      a Matrix object
    • dotProduct

      public double dotProduct(Vector v2)

      dotProduct.

      Parameters:
      v2 - a Vector object
      Returns:
      a double
    • get

      public double get(int i)

      get.

      Parameters:
      i - a int
      Returns:
      a double
    • like

      public Vector like()

      like.

      Returns:
      a Vector object
    • minus

      public Vector minus(Vector mb)

      minus.

      Parameters:
      mb - a Vector object
      Returns:
      a Vector object
    • plus

      public Vector plus(Vector mb)

      plus.

      Parameters:
      mb - a Vector object
      Returns:
      a Vector object
    • scalarMult

      public Vector scalarMult(double scalar)

      scalarMult.

      Parameters:
      scalar - a double
      Returns:
      a Vector object
    • set

      public void set(int j, double v)

      set.

      Parameters:
      j - a int
      v - a double
    • size

      public int size()

      size.

      Returns:
      a int
    • toArray

      public double[] toArray()

      toArray.

      Returns:
      an array of objects
    • toString

      public String toString()

      toString.

      Overrides:
      toString in class Object
      Returns:
      a String object
    • getSelection

      public Vector getSelection(int[] selection)

      viewSelection.

      Parameters:
      selection - an array of objects
      Returns:
      a Vector object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • dot

      public double dot(Vector v2)

      dot.

      Parameters:
      v2 - a Vector object
      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

      public Vector getPart(int from, int to)
      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 to to
      to - the ending index (exclusive) of the range; must be less than or equal to the size of the vector
      Returns:
      a new Vector object containing the elements from the specified range
      Throws:
      IllegalArgumentException - if from is negative, to exceeds the vector size, or from is greater than to
    • 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

      public void assignPart(int[] range1, Vector from)
      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 updated
      from - a Vector containing the values to be added to the elements at the specified indices