Search Results for

    Show / Hide Table of Contents

    Class Vector

    Base class for vectors. DenseVector, SparseVector, and ApproximateSparseVector all inherit from this base class.

    Inheritance
    Object
    Vector
    DenseVector
    PiecewiseVector
    SparseVector
    Implements
    IList<Double>
    ICollection<Double>
    IReadOnlyList<Double>
    IReadOnlyCollection<Double>
    IEnumerable<Double>
    IEnumerable
    SettableTo<Vector>
    ICloneable
    CanSetAllElementsTo<Double>
    SettableToPower<Vector>
    SettableToProduct<Vector>
    SettableToProduct<Vector, Vector>
    SettableToWeightedSum<Vector>
    Inherited Members
    Object.Equals(Object, Object)
    Object.GetType()
    Object.MemberwiseClone()
    Object.ReferenceEquals(Object, Object)
    Namespace: Microsoft.ML.Probabilistic.Math
    Assembly: Microsoft.ML.Probabilistic.dll
    Syntax
    [Serializable]
    [DataContract]
    public abstract class Vector : IList<double>, ICollection<double>, IReadOnlyList<double>, IReadOnlyCollection<double>, IEnumerable<double>, IEnumerable, SettableTo<Vector>, ICloneable, CanSetAllElementsTo<double>, SettableToPower<Vector>, SettableToProduct<Vector>, SettableToProduct<Vector, Vector>, SettableToWeightedSum<Vector>
    Remarks

    This class includes factory methods for instantiating Vectors of different Sparsity specifications. Beyond this initial construction, application code does not need to know the the sparsity, and most operations can be done via this general base class which will handle sparsity correctly.

    Properties

    Count

    Number of elements in vector

    Declaration
    public virtual int Count { get; protected set; }
    Property Value
    Type Description
    Int32

    IsApproximate

    True if this vector is approximate (sparse only)

    Declaration
    public bool IsApproximate { get; }
    Property Value
    Type Description
    Boolean

    IsDense

    True if this vector is dense

    Declaration
    public bool IsDense { get; }
    Property Value
    Type Description
    Boolean

    IsExact

    True if this vector is exact (dense or sparse)

    Declaration
    public bool IsExact { get; }
    Property Value
    Type Description
    Boolean

    IsReadOnly

    Is read only

    Declaration
    public virtual bool IsReadOnly { get; }
    Property Value
    Type Description
    Boolean

    IsSparse

    True if is this vector is sparse (exact or approximate)

    Declaration
    public bool IsSparse { get; }
    Property Value
    Type Description
    Boolean

    Item[Int32]

    Gets and sets an element.

    Declaration
    public virtual double this[int index] { get; set; }
    Parameters
    Type Name Description
    Int32 index
    Property Value
    Type Description
    Double

    Sparsity

    The Sparsity specification of this vector.

    Declaration
    public Sparsity Sparsity { get; protected set; }
    Property Value
    Type Description
    Sparsity

    Methods

    All(Converter<Double, Boolean>)

    Tests if all elements in the vector satisfy the specified condition.

    Declaration
    public abstract bool All(Converter<double, bool> fun)
    Parameters
    Type Name Description
    Converter<Double, Boolean> fun
    Returns
    Type Description
    Boolean

    Any(Vector, Func<Double, Double, Boolean>)

    Test if any corresponding elements in this and that vector satisfy a condition

    Declaration
    public virtual bool Any(Vector that, Func<double, double, bool> fun)
    Parameters
    Type Name Description
    Vector that
    Func<Double, Double, Boolean> fun
    Returns
    Type Description
    Boolean

    Any(Converter<Double, Boolean>)

    Tests if any elements in the vector satisfy the specified condition.

    Declaration
    public abstract bool Any(Converter<double, bool> fun)
    Parameters
    Type Name Description
    Converter<Double, Boolean> fun
    Returns
    Type Description
    Boolean

    Append(Vector)

    Return a new vector which is the concatenation of this vector and a second vector.

    Declaration
    public virtual Vector Append(Vector second)
    Parameters
    Type Name Description
    Vector second

    Second vector

    Returns
    Type Description
    Vector

    Append(Double)

    Appends an item to a vector - returns a new vector

    Declaration
    public virtual Vector Append(double item)
    Parameters
    Type Name Description
    Double item
    Returns
    Type Description
    Vector

    CheckCompatible(Vector, String)

    Checks that a given vector is the same size as this vector. Throws an exception if not with the given string

    Declaration
    protected virtual void CheckCompatible(Vector that, string paramName)
    Parameters
    Type Name Description
    Vector that

    The vector to check

    String paramName

    Clone()

    Clones this vector - return as a vector

    Declaration
    public virtual Vector Clone()
    Returns
    Type Description
    Vector

    Concat(Vector, Vector)

    Create a vector by concatenating two vectors.

    Declaration
    public static Vector Concat(Vector first, Vector second)
    Parameters
    Type Name Description
    Vector first

    First vector

    Vector second

    Second vector

    Returns
    Type Description
    Vector

    A new vector with all elements of the first vector followed by all elements of the second vector.

    Constant(Int32, Double)

    Create a dense vector of given length with elements all equal to a specified value

    Declaration
    public static Vector Constant(int count, double value)
    Parameters
    Type Name Description
    Int32 count

    Number of elements in vector

    Double value

    value for each element

    Returns
    Type Description
    Vector

    Constant(Int32, Double, Sparsity)

    Create a vector of given length with elements all equal to a specified value

    Declaration
    public static Vector Constant(int count, double value, Sparsity sparsity)
    Parameters
    Type Name Description
    Int32 count

    Number of elements in vector

    Double value

    value for each element

    Sparsity sparsity

    The Sparsity specification.

    Returns
    Type Description
    Vector

    Contains(Double)

    Returns true if the Vector contains the specified item value

    Declaration
    public virtual bool Contains(double item)
    Parameters
    Type Name Description
    Double item
    Returns
    Type Description
    Boolean

    Copy(Vector)

    Create a vector as a copy of another vector.

    Declaration
    public static Vector Copy(Vector that)
    Parameters
    Type Name Description
    Vector that

    The source vector - can be dense or sparse

    Returns
    Type Description
    Vector
    Remarks

    Sparsity of created vector matches that of source vector

    Copy(Vector, Sparsity)

    Create a vector as a copy of another vector with a given target sparsity

    Declaration
    public static Vector Copy(Vector that, Sparsity sparsity)
    Parameters
    Type Name Description
    Vector that

    The source vector - can be dense or sparse

    Sparsity sparsity

    The Sparsity specification.

    Returns
    Type Description
    Vector

    CopyTo(Double[], Int32)

    Copies this vector to the given array starting at the specified index in the target array

    Declaration
    public virtual void CopyTo(double[] array, int index)
    Parameters
    Type Name Description
    Double[] array

    The target array

    Int32 index

    The start index in the target array

    CountAll(Converter<Double, Boolean>)

    Returns the number of elements in the vector which satisfy a given condition.

    Declaration
    public abstract int CountAll(Converter<double, bool> fun)
    Parameters
    Type Name Description
    Converter<Double, Boolean> fun

    The condition for the elements to satisfy.

    Returns
    Type Description
    Int32

    The number of elements in the vector which satisfy the condition.

    EnsureDense(Vector)

    Declaration
    protected DenseVector EnsureDense(Vector vector)
    Parameters
    Type Name Description
    Vector vector
    Returns
    Type Description
    DenseVector

    Equals(Object)

    Determines object equality.

    Declaration
    public override bool Equals(object obj)
    Parameters
    Type Name Description
    Object obj

    Another (DenseVector) object.

    Returns
    Type Description
    Boolean

    True if equal.

    Overrides
    Object.Equals(Object)

    EqualsAll(Double)

    Tests if all elements are equal to a given value.

    Declaration
    public virtual bool EqualsAll(double value)
    Parameters
    Type Name Description
    Double value

    The value to test against.

    Returns
    Type Description
    Boolean

    True if all elements are equal to value.

    FindAll(Converter<Double, Boolean>)

    Returns an enumeration over the indices and values of all elements which satisfy the specified condition. Indices are returned in sorted order.

    Declaration
    public abstract IEnumerable<ValueAtIndex<double>> FindAll(Converter<double, bool> fun)
    Parameters
    Type Name Description
    Converter<Double, Boolean> fun

    A function to check if the condition is satisfied.

    Returns
    Type Description
    IEnumerable<ValueAtIndex<Double>>

    An enumeration over the indices and values of all elements which satisfy the specified condition.

    FindFirstIndex(Converter<Double, Boolean>)

    Returns the index of the first element that satisfies satisfy a given condition.

    Declaration
    public abstract int FindFirstIndex(Converter<double, bool> fun)
    Parameters
    Type Name Description
    Converter<Double, Boolean> fun

    The condition for the element to satisfy.

    Returns
    Type Description
    Int32

    The zero-based index of the first occurrence of an element that matches the conditions defined by match, if found; otherwise, �1.

    FindLastIndex(Converter<Double, Boolean>)

    Returns the index of the last element that satisfiessatisfy a given condition.

    Declaration
    public abstract int FindLastIndex(Converter<double, bool> fun)
    Parameters
    Type Name Description
    Converter<Double, Boolean> fun

    The condition for the element to satisfy.

    Returns
    Type Description
    Int32

    The zero-based index of the last occurrence of an element that matches the conditions defined by match, if found; otherwise, �1.

    FromArray(Double[])

    Constructs a dense vector from an array.

    Declaration
    public static Vector FromArray(params double[] data)
    Parameters
    Type Name Description
    Double[] data

    1D array of elements.

    Returns
    Type Description
    Vector
    Remarks

    The array data is copied into new storage. The size of the vector is taken from the array.

    FromArray(Double[], Sparsity)

    Constructs a vector from an array.

    Declaration
    public static Vector FromArray(double[] data, Sparsity sparsity)
    Parameters
    Type Name Description
    Double[] data

    1D array of elements.

    Sparsity sparsity

    The Sparsity specification.

    Returns
    Type Description
    Vector
    Remarks

    The array data is copied into new storage. The size of the vector is taken from the array.

    FromArray(Int32, Double[], Int32)

    Constructs a vector from part of an array.

    Declaration
    public static Vector FromArray(int count, double[] data, int start)
    Parameters
    Type Name Description
    Int32 count

    The number of elements in the vector.

    Double[] data

    Storage for the vector elements.

    Int32 start

    The starting index in the array for the vector elements.

    Returns
    Type Description
    Vector
    Remarks

    Throws an exception if Data is null, start < 0, or count < 0.

    FromArray(Int32, Double[], Int32, Sparsity)

    Constructs a vector from part of an array.

    Declaration
    public static Vector FromArray(int count, double[] data, int start, Sparsity sparsity)
    Parameters
    Type Name Description
    Int32 count

    The number of elements in the vector.

    Double[] data

    Storage for the vector elements.

    Int32 start

    The starting index in the array for the vector elements.

    Sparsity sparsity

    The Sparsity specification.

    Returns
    Type Description
    Vector
    Remarks

    Throws an exception if Data is null, start < 0, or count < 0.

    FromList(IList<Double>)

    Constructs a vector from a list. Maintains sparsity.

    Declaration
    public static Vector FromList(IList<double> list)
    Parameters
    Type Name Description
    IList<Double> list

    List to create vector from.

    Returns
    Type Description
    Vector

    GetEnumerator()

    Gets a typed enumerator which yields the vector elements

    Declaration
    public virtual IEnumerator<double> GetEnumerator()
    Returns
    Type Description
    IEnumerator<Double>

    GetHashCode()

    Gets a hash code for the instance.

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    Int32

    The code.

    Overrides
    Object.GetHashCode()

    GreaterThan(Vector)

    Tests if this vector is strictly greater than a second vector.

    Declaration
    public virtual bool GreaterThan(Vector that)
    Parameters
    Type Name Description
    Vector that

    The value to test against.

    Returns
    Type Description
    Boolean

    True if each element is strictly greater than the corresponding element of that.

    GreaterThan(Double)

    Tests if all elements are strictly greater than a given value.

    Declaration
    public virtual bool GreaterThan(double value)
    Parameters
    Type Name Description
    Double value

    The value to test against.

    Returns
    Type Description
    Boolean

    True if all elements are strictly greater than value.

    GreaterThanOrEqual(Vector)

    Tests if this vector is than or equal to a second vector.

    Declaration
    public virtual bool GreaterThanOrEqual(Vector that)
    Parameters
    Type Name Description
    Vector that

    The value to test against.

    Returns
    Type Description
    Boolean

    True if each element is greater than or equal to the corresponding element of that.

    GreaterThanOrEqual(Double)

    Tests if all elements are greater than or equal to a given value.

    Declaration
    public virtual bool GreaterThanOrEqual(double value)
    Parameters
    Type Name Description
    Double value

    The value to test against.

    Returns
    Type Description
    Boolean

    True if all elements are greater than or equal to value.

    IndexAtCumulativeSum(Double)

    Returns the index of the first element at which the sum of all elements so far is greater than a particular value. Useful for finding the median of a Discrete distribution.

    Declaration
    public virtual int IndexAtCumulativeSum(double targetSum)
    Parameters
    Type Name Description
    Double targetSum

    The sum of interest

    Returns
    Type Description
    Int32

    The index of the element where targetSum is exceeded or -1 if targetSum cannot be exceeded.

    IndexOf(Double)

    Returns the index of the first occurence of the given value in the array. Returns -1 if the value is not in the array

    Declaration
    public virtual int IndexOf(double item)
    Parameters
    Type Name Description
    Double item

    The item to check for

    Returns
    Type Description
    Int32

    Its index in the array

    IndexOfAll(Converter<Double, Boolean>)

    Returns an enumeration over the indices of all elements which satisfy the specified condition. Indices are returned in sorted order.

    Declaration
    public IEnumerable<int> IndexOfAll(Converter<double, bool> fun)
    Parameters
    Type Name Description
    Converter<Double, Boolean> fun

    A function to check if the condition is satisfied.

    Returns
    Type Description
    IEnumerable<Int32>

    An enumeration over the indices of all elements which satisfy the specified condition.

    IndexOfMaximum()

    Returns the index of the maximum element.

    Declaration
    public virtual int IndexOfMaximum()
    Returns
    Type Description
    Int32

    The index of the maximum element.

    IndexOfMinimum()

    Returns the index of the minimum element.

    Declaration
    public virtual int IndexOfMinimum()
    Returns
    Type Description
    Int32

    The index of the minimum element.

    Inner(Vector)

    Returns the inner product of this vector with another vector.

    Declaration
    public virtual double Inner(Vector that)
    Parameters
    Type Name Description
    Vector that

    Second vector, which must have the same size as this.

    Returns
    Type Description
    Double

    Their inner product.

    Inner(Vector, Converter<Double, Double>)

    Returns the inner product of a function of this vector with a second vector.

    Declaration
    public virtual double Inner(Vector that, Converter<double, double> fun)
    Parameters
    Type Name Description
    Vector that

    Second vector, which must have the same size as this.

    Converter<Double, Double> fun

    Function to convert the elements of the second vector

    Returns
    Type Description
    Double

    Their inner product.

    Inner(Converter<Double, Double>, Vector, Converter<Double, Double>)

    Returns the inner product of a function of this vector with a function of a second vector.

    Declaration
    public virtual double Inner(Converter<double, double> thisFun, Vector that, Converter<double, double> thatFun)
    Parameters
    Type Name Description
    Converter<Double, Double> thisFun

    Function to convert the elements of this vector

    Vector that

    Second vector, which must have the same size as this.

    Converter<Double, Double> thatFun

    Function to convert the elements of that vector

    Returns
    Type Description
    Double

    Their inner product.

    InnerProduct(Vector, Vector)

    Returns the inner product of two vectors.

    Declaration
    public static double InnerProduct(Vector a, Vector b)
    Parameters
    Type Name Description
    Vector a
    Vector b
    Returns
    Type Description
    Double

    The inner product.

    LessThan(Vector)

    Tests if this vector is strictly less than a second vector.

    Declaration
    public virtual bool LessThan(Vector that)
    Parameters
    Type Name Description
    Vector that

    The value to test against.

    Returns
    Type Description
    Boolean

    True if each element is strictly less than the corresponding element of that.

    LessThan(Double)

    Tests if all elements are strictly less than a given value.

    Declaration
    public virtual bool LessThan(double value)
    Parameters
    Type Name Description
    Double value

    The value to test against.

    Returns
    Type Description
    Boolean

    True if all elements are strictly less than value.

    LessThanOrEqual(Vector)

    Tests if this vector is less than or equal to a second vector.

    Declaration
    public virtual bool LessThanOrEqual(Vector that)
    Parameters
    Type Name Description
    Vector that

    The value to test against.

    Returns
    Type Description
    Boolean

    True if each element is strictly less than or equal to the corresponding element of that.

    LessThanOrEqual(Double)

    Tests if all elements are less than or equal to a given value.

    Declaration
    public virtual bool LessThanOrEqual(double value)
    Parameters
    Type Name Description
    Double value

    The value to test against.

    Returns
    Type Description
    Boolean

    True if all elements are less than or equal to value.

    LogSumExp()

    Returns the log of the sum of exponentials of the elements of the vector computed to high accuracy

    Declaration
    public virtual double LogSumExp()
    Returns
    Type Description
    Double

    Max()

    Returns the maximum of the elements in the vector

    Declaration
    public virtual double Max()
    Returns
    Type Description
    Double

    Max(Converter<Double, Double>)

    Returns the maximum of a function of the elements in the vector

    Declaration
    public virtual double Max(Converter<double, double> fun)
    Parameters
    Type Name Description
    Converter<Double, Double> fun
    Returns
    Type Description
    Double

    MaxDiff(Vector)

    Returns the maximum absolute difference between this vector and another vector.

    Declaration
    public virtual double MaxDiff(Vector that)
    Parameters
    Type Name Description
    Vector that

    The second vector.

    Returns
    Type Description
    Double

    max(abs(this[i] - that[i])). Matching infinities or NaNs do not count.
    If this and that are not the same size, returns infinity.

    Remarks

    This routine is typically used instead of Equals, since Equals is susceptible to roundoff errors.

    MaxDiff(Vector, Double)

    Returns the maximum relative difference between this vector and another.

    Declaration
    public virtual double MaxDiff(Vector that, double rel)
    Parameters
    Type Name Description
    Vector that

    The second vector.

    Double rel

    An offset to avoid division by zero.

    Returns
    Type Description
    Double

    max(abs(this[i] - that[i])/(abs(this[i]) + rel)). Matching infinities or NaNs do not count.
    If this and that are not the same size, returns infinity.

    Remarks

    This routine is typically used instead of Equals, since Equals is susceptible to roundoff errors.

    Median()

    Returns the minimum of the elements in the vector

    Declaration
    public virtual double Median()
    Returns
    Type Description
    Double

    Min()

    Returns the minimum of the elements in the vector

    Declaration
    public virtual double Min()
    Returns
    Type Description
    Double

    Min(Converter<Double, Double>)

    Returns the minimum of a function of the elements in the vector

    Declaration
    public virtual double Min(Converter<double, double> fun)
    Parameters
    Type Name Description
    Converter<Double, Double> fun
    Returns
    Type Description
    Double

    Outer(Vector)

    Returns the outer product of this vector with another vector.

    Declaration
    public virtual Matrix Outer(Vector that)
    Parameters
    Type Name Description
    Vector that

    Second vector.

    Returns
    Type Description
    Matrix

    Their outer product.

    PredivideBy(LowerTriangularMatrix)

    Gets the solution to Ax=b, where A is a lower triangular matrix, and b is this vector. Equivalent to the left-division x = A\b.

    Declaration
    public virtual Vector PredivideBy(LowerTriangularMatrix A)
    Parameters
    Type Name Description
    LowerTriangularMatrix A

    A lower triangular matrix.

    Returns
    Type Description
    Vector

    this

    Remarks

    this is used as the right-hand side vector b, and it also receives the solution. Throws an exception if A is singular.

    PredivideBy(PositiveDefiniteMatrix)

    Premultiply this vector by the inverse of a positive definite matrix

    Declaration
    public virtual Vector PredivideBy(PositiveDefiniteMatrix A)
    Parameters
    Type Name Description
    PositiveDefiniteMatrix A
    Returns
    Type Description
    Vector

    PredivideBy(UpperTriangularMatrix)

    Gets the solution to Ax=b, where A is an upper triangular matrix, and b is this vector. Equivalent to the left-division x = A\b.

    Declaration
    public virtual Vector PredivideBy(UpperTriangularMatrix A)
    Parameters
    Type Name Description
    UpperTriangularMatrix A

    An upper triangular matrix.

    Returns
    Type Description
    Vector

    this

    Remarks

    this is used as the right-hand side vector b, and it also receives the solution. Throws an exception if A is singular.

    PredivideByTranspose(LowerTriangularMatrix)

    Gets the solution to A'x=b, where A is a lower triangular matrix, and b is this vector. Equivalent to the left-division x = A'\b.

    Declaration
    public virtual Vector PredivideByTranspose(LowerTriangularMatrix A)
    Parameters
    Type Name Description
    LowerTriangularMatrix A

    A lower triangular matrix.

    Returns
    Type Description
    Vector

    this

    Remarks

    this is used as the right-hand side vector b, and it also receives the solution. Throws an exception if A is singular.

    Reduce(Double, Vector, Vector, Func<Double, Double, Double, Double, Double>)

    Reduce method. Operates on this vector and two other vectors

    Declaration
    public virtual double Reduce(double initial, Vector a, Vector b, Func<double, double, double, double, double> fun)
    Parameters
    Type Name Description
    Double initial

    Initial value

    Vector a

    A second vector

    Vector b

    A third vector

    Func<Double, Double, Double, Double, Double> fun
    Returns
    Type Description
    Double

    Reduce(Double, Vector, Func<Double, Double, Double, Double>)

    Reduce method. Operates on this vector and that vector

    Declaration
    public virtual double Reduce(double initial, Vector that, Func<double, double, double, double> fun)
    Parameters
    Type Name Description
    Double initial

    Initial value

    Vector that

    A second vector

    Func<Double, Double, Double, Double> fun

    Reduction function taking partial result, current element, and current element of that

    Returns
    Type Description
    Double

    Reduce(Double, Func<Double, Double, Double>)

    Reduce method. Operates on this vector

    Declaration
    public virtual double Reduce(double initial, Func<double, double, double> fun)
    Parameters
    Type Name Description
    Double initial

    Initial value

    Func<Double, Double, Double> fun

    Reduction function taking partial result and current element

    Returns
    Type Description
    Double

    Scale(Double)

    Multiplies this vector by a scalar.

    Declaration
    public virtual void Scale(double scale)
    Parameters
    Type Name Description
    Double scale

    The scalar.

    Remarks

    this receives the product. This method is a synonym for SetToProduct(this, scale)

    SetAllElementsTo(Double)

    Sets all elements to a given value.

    Declaration
    public virtual void SetAllElementsTo(double value)
    Parameters
    Type Name Description
    Double value

    The new value.

    SetSubvector(Int32, Vector)

    Set a subvector of this to another vector.

    Declaration
    public virtual void SetSubvector(int startIndex, Vector that)
    Parameters
    Type Name Description
    Int32 startIndex

    The index of the first element of this to copy to.

    Vector that

    A vector whose length is at most this.Count - startIndex.

    SetTo(Vector)

    Copies values from a Vector to this vector

    Declaration
    public virtual void SetTo(Vector that)
    Parameters
    Type Name Description
    Vector that

    SetTo(IEnumerable<Double>)

    Copies values from an Enumerable to this vector

    Declaration
    public virtual void SetTo(IEnumerable<double> that)
    Parameters
    Type Name Description
    IEnumerable<Double> that

    SetTo(Double[])

    Copies values from an array.

    Declaration
    public virtual void SetTo(double[] values)
    Parameters
    Type Name Description
    Double[] values

    An array whose length matches this.Count.

    SetToDiagonal(Matrix)

    Sets this vector to the diagonal of a matrix.

    Declaration
    public virtual void SetToDiagonal(Matrix m)
    Parameters
    Type Name Description
    Matrix m

    A matrix with Rows==Cols==this.Count.

    SetToDifference(Vector, Vector)

    Sets this vector to the difference of two vectors

    Declaration
    public virtual Vector SetToDifference(Vector a, Vector b)
    Parameters
    Type Name Description
    Vector a

    First vector, which must have the same size as this.

    Vector b

    Second vector, which must have the same size as this.

    Returns
    Type Description
    Vector

    this

    Remarks

    this receives the difference, and must already be the correct size. a and/or b may be the same object as this. If this and a/b occupy distinct yet overlapping portions of the same source array, the results are undefined.

    SetToDifference(Vector, Double)

    Set this vector to another vector minus a constant

    Declaration
    public virtual Vector SetToDifference(Vector a, double b)
    Parameters
    Type Name Description
    Vector a

    The other vector

    Double b

    The constant

    Returns
    Type Description
    Vector
    Remarks

    Assumes the vectors are compatible

    SetToDifference(Double, Vector)

    Set this vector to a constant minus another vector

    Declaration
    public virtual Vector SetToDifference(double a, Vector b)
    Parameters
    Type Name Description
    Double a

    The constant

    Vector b

    The other vector

    Returns
    Type Description
    Vector
    Remarks

    Assumes the vectors are compatible

    SetToFunction(Vector, Vector, Func<Double, Double, Double>)

    Sets the elements of this vector to a function of the elements of two vectors

    Declaration
    public virtual Vector SetToFunction(Vector a, Vector b, Func<double, double, double> fun)
    Parameters
    Type Name Description
    Vector a

    The first vector

    Vector b

    The second vector

    Func<Double, Double, Double> fun

    The function which maps two doubles to a double

    Returns
    Type Description
    Vector
    Remarks

    Assumes the vectors are compatible

    SetToFunction(Vector, Converter<Double, Double>)

    Sets the elements of this vector to a function of the elements of a given vector

    Declaration
    public virtual Vector SetToFunction(Vector that, Converter<double, double> fun)
    Parameters
    Type Name Description
    Vector that

    The given vector

    Converter<Double, Double> fun

    The function which maps doubles to doubles

    Returns
    Type Description
    Vector
    Remarks

    Assumes the vectors are compatible

    SetToPower(Vector, Double)

    Sets this vector to the elementwise power of another vector.

    Declaration
    public virtual void SetToPower(Vector that, double exponent)
    Parameters
    Type Name Description
    Vector that

    A vector, which must have the same size as this. Can be this.

    Double exponent

    A scalar.

    Remarks

    this receives the product, and must already be the correct size.
    If this and that occupy distinct yet overlapping portions of the same source array, the results are undefined.

    SetToProduct(Matrix, Vector)

    Set this vector to the product of a matrix by a vector (i.e. A*x).

    Declaration
    public virtual Vector SetToProduct(Matrix A, Vector x)
    Parameters
    Type Name Description
    Matrix A

    A matrix.

    Vector x

    A vector. Cannot be this.

    Returns
    Type Description
    Vector

    this

    Remarks

    this receives the product, and must already be the correct size. If this and A/x occupy overlapping portions of the same source array, the results are undefined.

    SetToProduct(Vector, Matrix)

    Sets this vector to the product of a vector by a matrix (i.e. x*A).

    Declaration
    public virtual Vector SetToProduct(Vector x, Matrix A)
    Parameters
    Type Name Description
    Vector x

    A vector. Cannot be this.

    Matrix A

    A matrix.

    Returns
    Type Description
    Vector

    this

    Remarks

    this receives the product, and must already be the correct size. If this and A/x occupy overlapping portions of the same source array, the results are undefined.

    SetToProduct(Vector, Vector)

    Sets this vector to the elementwise product of two other vectors.

    Declaration
    public virtual void SetToProduct(Vector a, Vector b)
    Parameters
    Type Name Description
    Vector a

    Must have the same size as this. Can be this.

    Vector b

    Must have the same size as this. Can be this.

    Remarks

    this receives the product, and must already be the correct size.
    If this and a occupy distinct yet overlapping portions of the same source array, the results are undefined.

    SetToProduct(Vector, Double)

    Sets this vector to a vector times a scalar.

    Declaration
    public virtual Vector SetToProduct(Vector a, double b)
    Parameters
    Type Name Description
    Vector a

    A vector, which must have the same size as this. Can be this.

    Double b

    A scalar.

    Returns
    Type Description
    Vector

    this

    Remarks

    this receives the product, and must already be the correct size.
    If this and a occupy distinct yet overlapping portions of the same source array, the results are undefined.

    SetToRatio(Vector, Vector)

    Sets this vector to the elementwise ratio of two other vectors.

    Declaration
    public virtual Vector SetToRatio(Vector a, Vector b)
    Parameters
    Type Name Description
    Vector a

    Must have the same size as this. Can be this.

    Vector b

    Must have the same size as this. Can be this.

    Returns
    Type Description
    Vector

    this

    Remarks

    this receives the product, and must already be the correct size.
    If this and a occupy distinct yet overlapping portions of the same source array, the results are undefined.

    SetToSubarray(Double[], Int32)

    Copies values from an array.

    Declaration
    public virtual void SetToSubarray(double[] values, int startIndex)
    Parameters
    Type Name Description
    Double[] values

    An array whose length is at least this.Count + startIndex.

    Int32 startIndex

    The index of the first value in values to copy.

    SetToSubvector(Vector, Int32)

    Copies value from a vector.

    Declaration
    public virtual void SetToSubvector(Vector that, int startIndex)
    Parameters
    Type Name Description
    Vector that

    A vector whose length is at least this.Count + startIndex.

    Int32 startIndex

    The index of the first value in that to copy.

    SetToSum(Vector, Vector)

    Sets this vector to the elementwise sum of two other vectors.

    Declaration
    public virtual Vector SetToSum(Vector a, Vector b)
    Parameters
    Type Name Description
    Vector a

    First vector, which must have the same size as this.

    Vector b

    Second vector, which must have the same size as this.

    Returns
    Type Description
    Vector

    this

    Remarks

    this receives the sum, and must already be the correct size. a and/or b may be the same object as this. If this and a/b occupy distinct yet overlapping portions of the same source array, the results are undefined.

    SetToSum(Vector, Double)

    Sets this vector to another vector plus a scalar.

    Declaration
    public virtual Vector SetToSum(Vector a, double b)
    Parameters
    Type Name Description
    Vector a

    A vector, which must have the same size as this. Can be the same object as this.

    Double b

    A scalar.

    Returns
    Type Description
    Vector

    this

    Remarks

    this receives the sum, and must already be the correct size. If this and a occupy distinct yet overlapping portions of the same source array, the results are undefined.

    SetToSum(Double, Vector, Double, Vector)

    Set this vector to a linear combination of two other vectors

    Declaration
    public virtual void SetToSum(double aScale, Vector a, double bScale, Vector b)
    Parameters
    Type Name Description
    Double aScale

    The multiplier for vector a

    Vector a

    First vector, which must have the same size as this.

    Double bScale

    The multiplier for vector b

    Vector b

    Second vector, which must have the same size as this.

    Remarks

    this receives the sum, and must already be the correct size. a and/or b may be the same object as this. If this and a/b occupy distinct yet overlapping portions of the same source array, the results are undefined.

    Subvector(Vector, Int32, Int32)

    Copy a subvector.

    Declaration
    public static Vector Subvector(Vector source, int startIndex, int count)
    Parameters
    Type Name Description
    Vector source

    A vector whose length is at least count + startIndex.

    Int32 startIndex

    The index of the first value in source to copy.

    Int32 count

    The number of elements to copy.

    Returns
    Type Description
    Vector

    A Vector of length count

    Subvector(Int32, Int32)

    Create a subvector of this vector

    Declaration
    public virtual Vector Subvector(int startIndex, int count)
    Parameters
    Type Name Description
    Int32 startIndex
    Int32 count
    Returns
    Type Description
    Vector

    Sum()

    Returns the sum of all elements.

    Declaration
    public virtual double Sum()
    Returns
    Type Description
    Double

    Sum(Converter<Double, Double>)

    Returns the sum of a function of all elements.

    Declaration
    public virtual double Sum(Converter<double, double> fun)
    Parameters
    Type Name Description
    Converter<Double, Double> fun
    Returns
    Type Description
    Double

    Sum(Converter<Double, Double>, Vector, Converter<Double, Boolean>)

    Returns the sum of a function of this vector filtered by a function of a second vector.

    Declaration
    public virtual double Sum(Converter<double, double> fun, Vector that, Converter<double, bool> cond)
    Parameters
    Type Name Description
    Converter<Double, Double> fun

    Function to convert the elements of this vector

    Vector that

    Second vector, which must have the same size as this.

    Converter<Double, Boolean> cond

    Function to convert the elements of that vector to give the filter condition

    Returns
    Type Description
    Double

    The filtered and mapped sum

    SumI()

    Returns the sum of over zero-based index * element.

    Declaration
    public virtual double SumI()
    Returns
    Type Description
    Double

    SumISq()

    Returns the sum of over square of index^2 times element.

    Declaration
    public virtual double SumISq()
    Returns
    Type Description
    Double

    ToArray()

    Converts this vector to an array of doubles

    Declaration
    public virtual double[] ToArray()
    Returns
    Type Description
    Double[]

    ToString()

    Converts this sparse vector into a human readable string

    Declaration
    public override string ToString()
    Returns
    Type Description
    String
    Overrides
    Object.ToString()

    ToString(String)

    String representation of vector with a specified format for each element

    Declaration
    public virtual string ToString(string format)
    Parameters
    Type Name Description
    String format
    Returns
    Type Description
    String

    ToString(String, String)

    String representation of vector with a specified format and delimiter

    Declaration
    public virtual string ToString(string format, string delimiter)
    Parameters
    Type Name Description
    String format
    String delimiter
    Returns
    Type Description
    String

    ToString(String, String, Func<Int32, String>)

    String representation of vector with a specified format and delimiter and a function for converting integers to display strings.

    Declaration
    public virtual string ToString(string format, string delimiter, Func<int, string> intToString)
    Parameters
    Type Name Description
    String format
    String delimiter
    Func<Int32, String> intToString
    Returns
    Type Description
    String

    Zero(Int32)

    Creates a dense vector of given length with elements all 0.0

    Declaration
    public static Vector Zero(int count)
    Parameters
    Type Name Description
    Int32 count

    Number of elements in vector

    Returns
    Type Description
    Vector

    Zero(Int32, Sparsity)

    Creates a vector of given length with elements all 0.0

    Declaration
    public static Vector Zero(int count, Sparsity sparsity)
    Parameters
    Type Name Description
    Int32 count

    Number of elements in vector

    Sparsity sparsity

    The Sparsity specification.

    Returns
    Type Description
    Vector

    Operators

    Addition(Vector, Vector)

    Returns the sum of two vectors.

    Declaration
    public static Vector operator +(Vector a, Vector b)
    Parameters
    Type Name Description
    Vector a

    First vector.

    Vector b

    Second vector.

    Returns
    Type Description
    Vector

    The sum.

    Addition(Vector, Double)

    Add a scalar to every element of a vector.

    Declaration
    public static Vector operator +(Vector a, double b)
    Parameters
    Type Name Description
    Vector a

    A vector.

    Double b

    A scalar.

    Returns
    Type Description
    Vector

    A vector with the sum.

    Division(Vector, Vector)

    Returns the ratio of two vectors

    Declaration
    public static Vector operator /(Vector a, Vector b)
    Parameters
    Type Name Description
    Vector a

    First vector.

    Vector b

    Second vector.

    Returns
    Type Description
    Vector

    The difference.

    Division(Vector, Double)

    Divides every element of a vector by a scalar.

    Declaration
    public static Vector operator /(Vector a, double b)
    Parameters
    Type Name Description
    Vector a

    A vector.

    Double b

    A scalar.

    Returns
    Type Description
    Vector

    A new vector with the ratio.

    Equality(Vector, Vector)

    Equality operator.

    Declaration
    public static bool operator ==(Vector a, Vector b)
    Parameters
    Type Name Description
    Vector a

    First vector.

    Vector b

    Second vector.

    Returns
    Type Description
    Boolean

    True if the vectors have the same size and element values.

    ExclusiveOr(Vector, Double)

    Returns a vector to some power.

    Declaration
    public static Vector operator ^(Vector a, double b)
    Parameters
    Type Name Description
    Vector a

    A vector.

    Double b

    A scalar.

    Returns
    Type Description
    Vector

    A new vector with this[i] = Math.Pow(a[i],b).

    GreaterThan(Vector, Vector)

    Greater than operator.

    Declaration
    public static bool operator>(Vector a, Vector b)
    Parameters
    Type Name Description
    Vector a

    First vector.

    Vector b

    Second vector.

    Returns
    Type Description
    Boolean

    True if each element in the first vector is greater than the corresponding element in the second vector.

    GreaterThan(Vector, Double)

    Greater than operator.

    Declaration
    public static bool operator>(Vector a, double value)
    Parameters
    Type Name Description
    Vector a

    Vector.

    Double value

    Value to compare against.

    Returns
    Type Description
    Boolean

    True if each element is greater than given value.

    GreaterThanOrEqual(Vector, Vector)

    Greater than or equal to operator.

    Declaration
    public static bool operator >=(Vector a, Vector b)
    Parameters
    Type Name Description
    Vector a

    First vector.

    Vector b

    Second vector.

    Returns
    Type Description
    Boolean

    True if each element in the first vector is not less than the corresponding element in the second vector.

    GreaterThanOrEqual(Vector, Double)

    Greater than or equal to operator.

    Declaration
    public static bool operator >=(Vector a, double value)
    Parameters
    Type Name Description
    Vector a

    Vector.

    Double value

    Value to compare against.

    Returns
    Type Description
    Boolean

    True if each element is not less than given value.

    Inequality(Vector, Vector)

    Inequality operator.

    Declaration
    public static bool operator !=(Vector a, Vector b)
    Parameters
    Type Name Description
    Vector a

    First vector.

    Vector b

    Second vector.

    Returns
    Type Description
    Boolean

    True if vectors are not equal.

    LessThan(Vector, Vector)

    Less than operator.

    Declaration
    public static bool operator <(Vector a, Vector b)
    Parameters
    Type Name Description
    Vector a

    First vector.

    Vector b

    Second vector.

    Returns
    Type Description
    Boolean

    True if each element in the first vector is less than the corresponding element in the second vector.

    LessThan(Vector, Double)

    Less than operator.

    Declaration
    public static bool operator <(Vector a, double value)
    Parameters
    Type Name Description
    Vector a

    Vector.

    Double value

    Value to compare against.

    Returns
    Type Description
    Boolean

    True if each element is less than given value.

    LessThanOrEqual(Vector, Vector)

    Less than or equal to operator.

    Declaration
    public static bool operator <=(Vector a, Vector b)
    Parameters
    Type Name Description
    Vector a

    First vector.

    Vector b

    Second vector.

    Returns
    Type Description
    Boolean

    True if each element in the first vector is not greater than the corresponding element in the second vector.

    LessThanOrEqual(Vector, Double)

    Less than or equal to operator.

    Declaration
    public static bool operator <=(Vector a, double value)
    Parameters
    Type Name Description
    Vector a

    Vector.

    Double value

    Value to compare against.

    Returns
    Type Description
    Boolean

    True if each element is not greater than given value.

    Multiply(Vector, Vector)

    Returns the elementwise product of two vectors.

    Declaration
    public static Vector operator *(Vector a, Vector b)
    Parameters
    Type Name Description
    Vector a
    Vector b
    Returns
    Type Description
    Vector

    A new vector with the product.

    Multiply(Vector, Double)

    Multiplies every element of a vector by a scalar.

    Declaration
    public static Vector operator *(Vector a, double b)
    Parameters
    Type Name Description
    Vector a

    A vector.

    Double b

    A scalar.

    Returns
    Type Description
    Vector

    A new vector with the product.

    Multiply(Double, Vector)

    Multiply every element of this vector by a scalar.

    Declaration
    public static Vector operator *(double b, Vector a)
    Parameters
    Type Name Description
    Double b

    A scalar.

    Vector a

    A vector.

    Returns
    Type Description
    Vector

    A new vector with the product.

    Subtraction(Vector, Vector)

    Returns the difference of two vectors

    Declaration
    public static Vector operator -(Vector a, Vector b)
    Parameters
    Type Name Description
    Vector a

    First vector.

    Vector b

    Second vector.

    Returns
    Type Description
    Vector

    The difference.

    Subtraction(Vector, Double)

    Subtracts a scalar from each element of a vector.

    Declaration
    public static Vector operator -(Vector a, double b)
    Parameters
    Type Name Description
    Vector a

    First vector.

    Double b

    A scalar.

    Returns
    Type Description
    Vector

    The difference.

    Subtraction(Double, Vector)

    Subtracts a scalar from each element of a vector.

    Declaration
    public static Vector operator -(double a, Vector b)
    Parameters
    Type Name Description
    Double a

    First vector.

    Vector b

    A scalar.

    Returns
    Type Description
    Vector

    The difference.

    UnaryNegation(Vector)

    Returns a vector which is the unary negation of a vector.

    Declaration
    public static Vector operator -(Vector a)
    Parameters
    Type Name Description
    Vector a

    The vector to negate.

    Returns
    Type Description
    Vector

    The negation of a.

    Explicit Interface Implementations

    ICollection<Double>.Add(Double)

    Declaration
    void ICollection<double>.Add(double item)
    Parameters
    Type Name Description
    Double item

    ICollection<Double>.Clear()

    Declaration
    void ICollection<double>.Clear()

    ICollection<Double>.Remove(Double)

    Declaration
    bool ICollection<double>.Remove(double item)
    Parameters
    Type Name Description
    Double item
    Returns
    Type Description
    Boolean

    IList<Double>.Insert(Int32, Double)

    Declaration
    void IList<double>.Insert(int index, double item)
    Parameters
    Type Name Description
    Int32 index
    Double item

    IList<Double>.RemoveAt(Int32)

    Declaration
    void IList<double>.RemoveAt(int index)
    Parameters
    Type Name Description
    Int32 index

    IEnumerable.GetEnumerator()

    Declaration
    IEnumerator IEnumerable.GetEnumerator()
    Returns
    Type Description
    IEnumerator

    ICloneable.Clone()

    Declaration
    object ICloneable.Clone()
    Returns
    Type Description
    Object

    Implements

    System.Collections.Generic.IList<T>
    System.Collections.Generic.ICollection<T>
    System.Collections.Generic.IReadOnlyList<T>
    System.Collections.Generic.IReadOnlyCollection<T>
    System.Collections.Generic.IEnumerable<T>
    System.Collections.IEnumerable
    SettableTo<T>
    System.ICloneable
    CanSetAllElementsTo<T>
    SettableToPower<T>
    SettableToProduct<T>
    SettableToProduct<T, U>
    SettableToWeightedSum<T>

    Extension Methods

    CollectionExtensions.AddRange<T>(ICollection<T>, IEnumerable<T>)
    CollectionExtensions.ContainsAll<T>(ICollection<T>, IEnumerable<T>)
    CollectionExtensions.ContainsAny<T>(ICollection<T>, IEnumerable<T>)
    EnumerableExtensions.ForEach<T>(IEnumerable<T>, Action<T>)
    EnumerableExtensions.ForEach<T>(IEnumerable, Action<T>)
    EnumerableExtensions.ForEach<T>(IEnumerable<T>, Action<Int32, T>)
    EnumerableExtensions.ForEach<T>(IEnumerable, Action<Int32, T>)
    EnumerableExtensions.Sum<TSource>(IEnumerable<TSource>, Func<TSource, UInt32>)
    EnumerableExtensions.Sum<TSource>(IEnumerable<TSource>, Func<TSource, UInt64>)
    EnumerableExtensions.ValueEquals<T>(IEnumerable<T>, IEnumerable<T>)
    EnumerableExtensions.IndexOf<T>(IEnumerable<T>, T)
    EnumerableExtensions.IndexOf<T>(IEnumerable, T)
    EnumerableExtensions.FindIndex<T>(IEnumerable<T>, Predicate<T>)
    EnumerableExtensions.FindIndex<T>(IEnumerable, Predicate<T>)
    EnumerableExtensions.FindAllIndex<T>(IEnumerable<T>, Predicate<T>)
    EnumerableExtensions.IndexOfAll<T>(IEnumerable<T>, T)
    EnumerableExtensions.Skip<T>(IEnumerable<T>, Int32, out List<T>)
    EnumerableExtensions.CopyTo<T>(IEnumerable<T>, T[], Int32)
    EnumerableExtensions.ToReadOnlyList<T>(IEnumerable<T>)
    IEnumerableExensions.EnumerableReduce<T, TRes>(IEnumerable<T>, TRes, Func<TRes, T, TRes>, Func<TRes, T, Int32, TRes>)
    IEnumerableExensions.EnumerableSum<T>(IEnumerable<T>, Func<T, Double>)
    IEnumerableExensions.ListZip<TFirst, TSecond, TResult>(IList<TFirst>, IEnumerable<TSecond>, Func<TFirst, TSecond, TResult>)
    IEnumerableExensions.ListZip<TFirst, TSecond, TThird, TResult>(IList<TFirst>, IEnumerable<TSecond>, IEnumerable<TThird>, Func<TFirst, TSecond, TThird, TResult>)
    IEnumerableExensions.ListZip<TFirst, TSecond, TThird, TFourth, TResult>(IList<TFirst>, IList<TSecond>, IList<TThird>, IList<TFourth>, Func<TFirst, TSecond, TThird, TFourth, TResult>)
    IListExtensions.IsSparse<T>(IList<T>)
    IListExtensions.ListSelect<T, T2>(IList<T>, Func<T, T2>)
    IListExtensions.ListReduce<T, TRes>(IList<T>, TRes, Func<TRes, T, TRes>)
    IListExtensions.ListReduce<T, T2, TRes>(IList<T>, IEnumerable<T2>, TRes, Func<TRes, T, T2, TRes>)
    IListExtensions.ToVector(IList<Double>)
    IListExtensions.SetTo<T>(IList<T>, IEnumerable<T>)
    IListExtensions.SetTo(IList<Double>, IEnumerable<Double>)
    IListExtensions.AsReadOnly<T>(IList<T>)
    ReadOnlyArray.ToReadOnlyArray<T>(IEnumerable<T>)
    In This Article
    Back to top Copyright © .NET Foundation. All rights reserved.