Class DenseVector
1-dimensional dense container of double precision data that supports vector operations.
Implements
Inherited Members
Namespace: Microsoft.ML.Probabilistic.Math
Assembly: Microsoft.ML.Probabilistic.dll
Syntax
[Serializable]
[DataContract]
public class DenseVector : Vector, IList<double>, ICollection<double>, IReadOnlyList<double>, IReadOnlyCollection<double>, IEnumerable<double>, IEnumerable, CanSetAllElementsTo<double>, SettableToPower<Vector>, SettableToProduct<Vector>, SettableToProduct<Vector, Vector>, SettableToWeightedSum<Vector>, ICursor, ICloneable, SettableTo<Vector>
Fields
count
Declaration
[DataMember]
protected readonly int count
Field Value
| Type | Description |
|---|---|
| Int32 |
data
Declaration
[DataMember]
protected double[] data
Field Value
| Type | Description |
|---|---|
| Double[] |
start
Declaration
[DataMember]
protected int start
Field Value
| Type | Description |
|---|---|
| Int32 |
Properties
Count
Number of elements in vector
Declaration
public override int Count { get; protected set; }
Property Value
| Type | Description |
|---|---|
| Int32 |
Overrides
IsReadOnly
Is read only
Declaration
public override bool IsReadOnly { get; }
Property Value
| Type | Description |
|---|---|
| Boolean |
Overrides
Item[Int32]
Gets and sets an element.
Declaration
public override double this[int index] { get; set; }
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | index |
Property Value
| Type | Description |
|---|---|
| Double |
Overrides
SourceArray
Gets/sets source array for the vector
Declaration
[IgnoreDataMember]
public double[] SourceArray { get; set; }
Property Value
| Type | Description |
|---|---|
| Double[] |
Start
Gets/sets the start index in the source array
Declaration
[IgnoreDataMember]
public int Start { get; set; }
Property Value
| Type | Description |
|---|---|
| Int32 |
Methods
All(Converter<Double, Boolean>)
Tests if all elements in the vector satisfy the specified condition.
Declaration
public override bool All(Converter<double, bool> fun)
Parameters
| Type | Name | Description |
|---|---|---|
| Converter<Double, Boolean> | fun |
Returns
| Type | Description |
|---|---|
| Boolean |
Overrides
Any(DenseVector, Func<Double, Double, Boolean>)
Declaration
public bool Any(DenseVector that, Func<double, double, bool> fun)
Parameters
| Type | Name | Description |
|---|---|---|
| DenseVector | that | |
| Func<Double, Double, Boolean> | fun |
Returns
| Type | Description |
|---|---|
| Boolean |
Any(Vector, Func<Double, Double, Boolean>)
Declaration
public override bool Any(Vector that, Func<double, double, bool> fun)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector | that | |
| Func<Double, Double, Boolean> | fun |
Returns
| Type | Description |
|---|---|
| Boolean |
Overrides
Any(Converter<Double, Boolean>)
Tests if any elements in the vector satisfy the specified condition.
Declaration
public override bool Any(Converter<double, bool> fun)
Parameters
| Type | Name | Description |
|---|---|---|
| Converter<Double, Boolean> | fun |
Returns
| Type | Description |
|---|---|
| Boolean |
Overrides
Append(DenseVector)
Returns a new vector which appends a second dense vector to this dense vector
Declaration
public DenseVector Append(DenseVector second)
Parameters
| Type | Name | Description |
|---|---|---|
| DenseVector | second | Second vector |
Returns
| Type | Description |
|---|---|
| DenseVector |
Append(Vector)
Returns a new vector which appends a second vector to this vector
Declaration
public override Vector Append(Vector second)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector | second | Second vector |
Returns
| Type | Description |
|---|---|
| Vector |
Overrides
Append(Double)
Appends an item to a vector - returns a new vector
Declaration
public override Vector Append(double item)
Parameters
| Type | Name | Description |
|---|---|---|
| Double | item |
Returns
| Type | Description |
|---|---|
| Vector |
Overrides
Clone()
Clones this vector - return as a vector
Declaration
public override Vector Clone()
Returns
| Type | Description |
|---|---|
| Vector |
Overrides
Constant(Int32, Double)
Create a dense vector of given length with elements all equal to a specified value
Declaration
public static DenseVector 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 |
|---|---|
| DenseVector |
Contains(Double)
Returns true if the Vector contains the specified item value
Declaration
public override bool Contains(double item)
Parameters
| Type | Name | Description |
|---|---|---|
| Double | item |
Returns
| Type | Description |
|---|---|
| Boolean |
Overrides
Copy(Vector)
Creates a dense vector as a copy of another vector
Declaration
public static DenseVector Copy(Vector that)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector | that | The source vector - can be dense or sparse |
Returns
| Type | Description |
|---|---|
| DenseVector |
CopyTo(Double[], Int32)
Copies this vector to the given array starting at the specified index in the target array
Declaration
public override void CopyTo(double[] array, int index)
Parameters
| Type | Name | Description |
|---|---|---|
| Double[] | array | The target array |
| Int32 | index | The start index in the target array |
Overrides
CountAll(Converter<Double, Boolean>)
Returns the number of elements in the vector which satisfy a given condition.
Declaration
public override 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. |
Overrides
CreateSourceArray(Int32)
Creates a source array with a given number of records
Declaration
public void CreateSourceArray(int nRecords)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | nRecords |
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
EqualsAll(Double)
Tests if all elements are equal to a given value.
Declaration
public override 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 |
Overrides
FindAll(Converter<Double, Boolean>)
Returns an enumeration over the indices and values of all the elements which satisfy the specified condition. Indices are returned in sorted order.
Declaration
public override 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 the elements which satisfy the specified condition. |
Overrides
FindFirstIndex(Converter<Double, Boolean>)
Returns the index of the first element that satisfies a given condition.
Declaration
public override 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. |
Overrides
FindLastIndex(Converter<Double, Boolean>)
Returns the index of the last element that satisfies a given condition.
Declaration
public override 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. |
Overrides
FromArray(Double[])
Constructs a dense vector from an array.
Declaration
[Construction(new string[]{"ToArray"})]
public static DenseVector FromArray(params double[] data)
Parameters
| Type | Name | Description |
|---|---|---|
| Double[] | data | 1D array of elements. |
Returns
| Type | Description |
|---|---|
| DenseVector |
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 DenseVector 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 |
|---|---|
| DenseVector |
Remarks
Throws an exception if Data is null, start < 0, or count < 0.
FromArrayReference(Int32, Double[], Int32)
Constructs a vector by referencing an array.
Declaration
public static DenseVector FromArrayReference(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 |
|---|---|
| DenseVector |
Remarks
The vector will not copy the array but only reference it, so any numerical changes to the array will also apply to the vector. If the array grows larger, the extra elements are ignored. The array must not shrink or else the vector will become inconsistent.
Throws an exception if Data is null, start < 0, or count < 0.
GetEnumerator()
Gets a typed enumerator which yields the vector elements
Declaration
public override IEnumerator<double> GetEnumerator()
Returns
| Type | Description |
|---|---|
| IEnumerator<Double> |
Overrides
GetHashCode()
Gets a hash code for the instance.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| Int32 | The code. |
Overrides
GreaterThan(DenseVector)
Tests if this dense vector is strictly greater than a second dense vector.
Declaration
public bool GreaterThan(DenseVector that)
Parameters
| Type | Name | Description |
|---|---|---|
| DenseVector | that | The value to test against. |
Returns
| Type | Description |
|---|---|
| Boolean | True if each element is strictly greater than the corresponding element of |
GreaterThan(Vector)
Tests if this vector is strictly greater than a second vector.
Declaration
public override 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 |
Overrides
GreaterThan(Double)
Tests if all elements are strictly greater than a given value.
Declaration
public override 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 |
Overrides
GreaterThanOrEqual(DenseVector)
Tests if this dense vector is greater than or equal to a second dense vector.
Declaration
public bool GreaterThanOrEqual(DenseVector that)
Parameters
| Type | Name | Description |
|---|---|---|
| DenseVector | that | The value to test against. |
Returns
| Type | Description |
|---|---|
| Boolean | True if each element is greater than or equal to the corresponding element of |
GreaterThanOrEqual(Vector)
Tests if this vector is greater than or equal to a second vector.
Declaration
public override 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 |
Overrides
GreaterThanOrEqual(Double)
Tests if all elements are greater than or equal to a given value.
Declaration
public override 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 |
Overrides
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 override int IndexAtCumulativeSum(double targetSum)
Parameters
| Type | Name | Description |
|---|---|---|
| Double | targetSum | The sum of interest |
Returns
| Type | Description |
|---|---|
| Int32 | The index of the element where |
Overrides
IndexOf(Double)
Returns the index of the first occurence of the given value in the vector. Returns -1 if the value is not in the array
Declaration
public override int IndexOf(double item)
Parameters
| Type | Name | Description |
|---|---|---|
| Double | item | The item to check for |
Returns
| Type | Description |
|---|---|
| Int32 | Its index in the vector |
Overrides
IndexOfMaximum()
Returns the index of the maximum element.
Declaration
public override int IndexOfMaximum()
Returns
| Type | Description |
|---|---|
| Int32 | The index of the maximum element. |
Overrides
IndexOfMinimum()
Returns the index of the minimum element.
Declaration
public override int IndexOfMinimum()
Returns
| Type | Description |
|---|---|
| Int32 | The index of the minimum element. |
Overrides
Inner(DenseVector)
Returns the inner product of this dense vector with another dense vector.
Declaration
public double Inner(DenseVector that)
Parameters
| Type | Name | Description |
|---|---|---|
| DenseVector | that | Second vector, which must have the same size as |
Returns
| Type | Description |
|---|---|
| Double | Their inner product. |
Inner(DenseVector, Converter<Double, Double>)
Returns the inner product of this dense vector with a function of a second dense vector.
Declaration
public double Inner(DenseVector that, Converter<double, double> fun)
Parameters
| Type | Name | Description |
|---|---|---|
| DenseVector | that | Second vector, which must have the same size as |
| Converter<Double, Double> | fun | Function to convert the elements of the second vector |
Returns
| Type | Description |
|---|---|
| Double | Their inner product. |
Inner(Vector)
Returns the inner product of this vector with another vector.
Declaration
public override double Inner(Vector that)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector | that | Second vector, which must have the same size as |
Returns
| Type | Description |
|---|---|
| Double | Their inner product. |
Overrides
Inner(Vector, Converter<Double, Double>)
Returns the inner product of this vector with a function of a second vector.
Declaration
public override double Inner(Vector that, Converter<double, double> fun)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector | that | Second vector, which must have the same size as |
| Converter<Double, Double> | fun | Function to convert the elements of the second vector |
Returns
| Type | Description |
|---|---|
| Double | Their inner product. |
Overrides
Inner(Converter<Double, Double>, DenseVector, Converter<Double, Double>)
Returns the inner product of a function of this dense vector with a function of a second dense vector.
Declaration
public double Inner(Converter<double, double> thisFun, DenseVector that, Converter<double, double> thatFun)
Parameters
| Type | Name | Description |
|---|---|---|
| Converter<Double, Double> | thisFun | Function to convert the elements of this vector |
| DenseVector | that | Second vector, which must have the same size as |
| Converter<Double, Double> | thatFun | Function to convert the elements of that 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 override 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 |
| Converter<Double, Double> | thatFun | Function to convert the elements of that vector |
Returns
| Type | Description |
|---|---|
| Double | Their inner product. |
Overrides
LessThan(DenseVector)
Tests if this dense vector is strictly less than a second dense vector.
Declaration
public bool LessThan(DenseVector that)
Parameters
| Type | Name | Description |
|---|---|---|
| DenseVector | that | The value to test against. |
Returns
| Type | Description |
|---|---|
| Boolean | True if each element is strictly less than the corresponding element of |
LessThan(Vector)
Tests if this vector is strictly less than a second vector.
Declaration
public override 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 |
Overrides
LessThan(Double)
Tests if all elements are strictly less than a given value.
Declaration
public override 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 |
Overrides
LessThanOrEqual(DenseVector)
Tests if this dense vector is less than or equal to a second dense vector.
Declaration
public bool LessThanOrEqual(DenseVector that)
Parameters
| Type | Name | Description |
|---|---|---|
| DenseVector | 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 |
LessThanOrEqual(Vector)
Tests if this vector is less than or equal to a second vector.
Declaration
public override 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 |
Overrides
LessThanOrEqual(Double)
Tests if all elements are less than or equal to a given value.
Declaration
public override 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 |
Overrides
LogSumExp()
Returns the log of the sum of exponentials of the elements of the vector computed to high accuracy
Declaration
public override double LogSumExp()
Returns
| Type | Description |
|---|---|
| Double |
Overrides
Max()
Returns the maximum of the elements in the vector
Declaration
public override double Max()
Returns
| Type | Description |
|---|---|
| Double |
Overrides
Max(Converter<Double, Double>)
Returns the maximum of a function of the elements in the vector
Declaration
public override double Max(Converter<double, double> fun)
Parameters
| Type | Name | Description |
|---|---|---|
| Converter<Double, Double> | fun | Conversion function |
Returns
| Type | Description |
|---|---|
| Double |
Overrides
MaxDiff(DenseVector)
Returns the maximum absolute difference between this dense vector and another dense vector.
Declaration
public double MaxDiff(DenseVector that)
Parameters
| Type | Name | Description |
|---|---|---|
| DenseVector | that | The second vector. |
Returns
| Type | Description |
|---|---|
| Double |
|
Remarks
This routine is typically used instead of Equals, since Equals is susceptible to roundoff errors.
MaxDiff(DenseVector, Double)
Returns the maximum relative difference between this dense vector and another.
Declaration
public double MaxDiff(DenseVector that, double rel)
Parameters
| Type | Name | Description |
|---|---|---|
| DenseVector | that | The second vector. |
| Double | rel | An offset to avoid division by zero. |
Returns
| Type | Description |
|---|---|
| Double |
|
Remarks
This routine is typically used instead of Equals, since Equals is susceptible to roundoff errors.
MaxDiff(Vector)
Returns the maximum absolute difference between this vector and another vector.
Declaration
public override double MaxDiff(Vector that)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector | that | The second vector. |
Returns
| Type | Description |
|---|---|
| Double |
|
Overrides
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 override 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 |
|
Overrides
Remarks
This routine is typically used instead of Equals, since Equals is susceptible to roundoff errors.
Median()
Returns the median of all elements.
Declaration
public override double Median()
Returns
| Type | Description |
|---|---|
| Double |
Overrides
Min()
Returns the minimum of the elements in the vector
Declaration
public override double Min()
Returns
| Type | Description |
|---|---|
| Double |
Overrides
Min(Converter<Double, Double>)
Returns the minimum of the elements in the vector
Declaration
public override double Min(Converter<double, double> fun)
Parameters
| Type | Name | Description |
|---|---|---|
| Converter<Double, Double> | fun | Conversion function |
Returns
| Type | Description |
|---|---|
| Double |
Overrides
Outer(DenseVector)
Returns the outer product of this dense vector with another dense vector.
Declaration
public PositiveDefiniteMatrix Outer(DenseVector that)
Parameters
| Type | Name | Description |
|---|---|---|
| DenseVector | that | Second vector. |
Returns
| Type | Description |
|---|---|
| PositiveDefiniteMatrix | Their outer product. |
Outer(Vector)
Returns the outer product of this vector with another vector.
Declaration
public override Matrix Outer(Vector that)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector | that | Second vector. |
Returns
| Type | Description |
|---|---|
| Matrix | Their outer product. |
Overrides
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 override Vector PredivideBy(LowerTriangularMatrix A)
Parameters
| Type | Name | Description |
|---|---|---|
| LowerTriangularMatrix | A | A lower triangular matrix. |
Returns
| Type | Description |
|---|---|
| Vector |
|
Overrides
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 the given positive definite matrix
Declaration
public override Vector PredivideBy(PositiveDefiniteMatrix A)
Parameters
| Type | Name | Description |
|---|---|---|
| PositiveDefiniteMatrix | A |
Returns
| Type | Description |
|---|---|
| Vector |
Overrides
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 override Vector PredivideBy(UpperTriangularMatrix A)
Parameters
| Type | Name | Description |
|---|---|---|
| UpperTriangularMatrix | A | An upper triangular matrix. |
Returns
| Type | Description |
|---|---|
| Vector |
|
Overrides
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 override Vector PredivideByTranspose(LowerTriangularMatrix A)
Parameters
| Type | Name | Description |
|---|---|---|
| LowerTriangularMatrix | A | A lower triangular matrix. |
Returns
| Type | Description |
|---|---|
| Vector |
|
Overrides
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, DenseVector, Func<Double, Double, Double, Double>)
Reduce method. Operates on this vector and that vector
Declaration
public double Reduce(double initial, DenseVector that, Func<double, double, double, double> fun)
Parameters
| Type | Name | Description |
|---|---|---|
| Double | initial | Initial value |
| DenseVector | that | A second vector |
| Func<Double, Double, Double, Double> | fun | Reduction function taking partial result, current element, and current element of |
Returns
| Type | Description |
|---|---|
| Double |
Reduce(Double, Vector, Vector, Func<Double, Double, Double, Double, Double>)
Reduce method. Operates on this vector and two other vectors
Declaration
public override 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 | Reduction function |
Returns
| Type | Description |
|---|---|
| Double |
Overrides
Reduce(Double, Vector, Func<Double, Double, Double, Double>)
Reduce method. Operates on this dense vector and that dense vector
Declaration
public override 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 |
Returns
| Type | Description |
|---|---|
| Double |
Overrides
Reduce(Double, Func<Double, Double, Double>)
Reduce method. Operates on this vector
Declaration
public override 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 |
Overrides
ReferenceClone()
Creates a clone of this instance which references the source array
Declaration
public ICursor ReferenceClone()
Returns
| Type | Description |
|---|---|
| ICursor |
Scale(Double)
Multiplies this vector by a scalar.
Declaration
public override void Scale(double scale)
Parameters
| Type | Name | Description |
|---|---|---|
| Double | scale | The scalar. |
Overrides
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 override void SetAllElementsTo(double value)
Parameters
| Type | Name | Description |
|---|---|---|
| Double | value | The new value. |
Overrides
SetSubvector(Int32, DenseVector)
Set a subvector of this to another vector.
Declaration
public void SetSubvector(int startIndex, DenseVector that)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | startIndex | The index of the first element of to copy to. |
| DenseVector | that | A dense vector whose length is at most |
SetSubvector(Int32, Vector)
Set a subvector of this to another vector.
Declaration
public override 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 |
Overrides
SetTo(DenseVector)
Copies values from a dense vector to this dense vector
Declaration
public void SetTo(DenseVector that)
Parameters
| Type | Name | Description |
|---|---|---|
| DenseVector | that |
SetTo(Vector)
Copies values from a vector to this vector
Declaration
public override void SetTo(Vector that)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector | that |
Overrides
SetTo(IEnumerable<Double>)
Copies values from an Enumerable to this vector
Declaration
public override void SetTo(IEnumerable<double> that)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<Double> | that |
Overrides
SetTo(Double[])
Copies values from an array.
Declaration
public override void SetTo(double[] values)
Parameters
| Type | Name | Description |
|---|---|---|
| Double[] | values | An array whose length matches |
Overrides
SetToDiagonal(Matrix)
Sets this vector to the diagonal of a matrix.
Declaration
public override void SetToDiagonal(Matrix m)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix | m | A matrix with Rows==Cols==this.Count. |
Overrides
SetToDifference(DenseVector, DenseVector)
Sets this dense vector to the difference of two othe dense vectors
Declaration
public DenseVector SetToDifference(DenseVector a, DenseVector b)
Parameters
| Type | Name | Description |
|---|---|---|
| DenseVector | a | First vector, which must have the same size as |
| DenseVector | b | Second vector, which must have the same size as |
Returns
| Type | Description |
|---|---|
| DenseVector |
|
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(DenseVector, Double)
Set this dense vector to another dense vector minus a constant
Declaration
public DenseVector SetToDifference(DenseVector a, double b)
Parameters
| Type | Name | Description |
|---|---|---|
| DenseVector | a | The other vector |
| Double | b | The constant |
Returns
| Type | Description |
|---|---|
| DenseVector |
Remarks
Assumes the vectors are compatible
SetToDifference(Vector, Vector)
Sets this vector to the difference of two vectors
Declaration
public override Vector SetToDifference(Vector a, Vector b)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector | a | First vector, which must have the same size as |
| Vector | b | Second vector, which must have the same size as |
Returns
| Type | Description |
|---|---|
| Vector |
|
Overrides
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 override Vector SetToDifference(Vector a, double b)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector | a | The other vector |
| Double | b | The constant |
Returns
| Type | Description |
|---|---|
| Vector |
Overrides
Remarks
Assumes the vectors are compatible
SetToDifference(Double, DenseVector)
Set this dense vector to a constant minus another dense vector
Declaration
public DenseVector SetToDifference(double a, DenseVector b)
Parameters
| Type | Name | Description |
|---|---|---|
| Double | a | The constant |
| DenseVector | b | The other vector |
Returns
| Type | Description |
|---|---|
| DenseVector |
Remarks
Assumes the vectors are compatible
SetToDifference(Double, Vector)
Set this vector to a constant minus another vector
Declaration
public override Vector SetToDifference(double a, Vector b)
Parameters
| Type | Name | Description |
|---|---|---|
| Double | a | The constant |
| Vector | b | The other vector |
Returns
| Type | Description |
|---|---|
| Vector |
Overrides
Remarks
Assumes the vectors are compatible
SetToFunction(DenseVector, DenseVector, Func<Double, Double, Double>)
Sets the elements of this vector to a function of the elements of two vectors
Declaration
public DenseVector SetToFunction(DenseVector a, DenseVector b, Func<double, double, double> fun)
Parameters
| Type | Name | Description |
|---|---|---|
| DenseVector | a | The first vector |
| DenseVector | b | The second vector |
| Func<Double, Double, Double> | fun | The function which maps two doubles to a double |
Returns
| Type | Description |
|---|---|
| DenseVector |
Remarks
Assumes the vectors are compatible
SetToFunction(DenseVector, Converter<Double, Double>)
Sets the elements of this vector to a function of the elements of a given vector
Declaration
public DenseVector SetToFunction(DenseVector that, Converter<double, double> fun)
Parameters
| Type | Name | Description |
|---|---|---|
| DenseVector | that | The given vector |
| Converter<Double, Double> | fun | The function which maps doubles to doubles |
Returns
| Type | Description |
|---|---|
| DenseVector |
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 override 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 |
Overrides
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 override 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 |
Overrides
Remarks
Assumes the vectors are compatible
SetToLeastSquares(DenseVector, Matrix)
Solve Y = X*A
Declaration
public double SetToLeastSquares(DenseVector Y, Matrix X)
Parameters
| Type | Name | Description |
|---|---|---|
| DenseVector | Y | Vector of target values |
| Matrix | X | Portrait matrix |
Returns
| Type | Description |
|---|---|
| Double | The smallest squared singular value of X. This is useful for detecting an ill-conditioned problem. |
SetToPower(DenseVector, Double)
Sets this vector to the elementwise power of another vector.
Declaration
public void SetToPower(DenseVector that, double exponent)
Parameters
| Type | Name | Description |
|---|---|---|
| DenseVector | that | A vector, which must have the same size as |
| 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.
SetToPower(Vector, Double)
Sets this vector to the elementwise power of another vector.
Declaration
public override void SetToPower(Vector that, double exponent)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector | that | A vector, which must have the same size as |
| Double | exponent | A scalar. |
Overrides
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(DenseVector, DenseVector)
Sets this dense vector to the elementwise product of two other dense vectors.
Declaration
public void SetToProduct(DenseVector a, DenseVector b)
Parameters
| Type | Name | Description |
|---|---|---|
| DenseVector | a | Must have the same size as |
| DenseVector | b | Must have the same size as |
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(DenseVector, Matrix)
Sets this dense vector to the product of a dense vector by a matrix (i.e. x*A).
Declaration
public DenseVector SetToProduct(DenseVector x, Matrix A)
Parameters
| Type | Name | Description |
|---|---|---|
| DenseVector | x | A vector. Cannot be |
| Matrix | A | A matrix. |
Returns
| Type | Description |
|---|---|
| DenseVector |
|
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(DenseVector, Double)
Sets this dense vector to a dense vector times a scalar.
Declaration
public DenseVector SetToProduct(DenseVector a, double b)
Parameters
| Type | Name | Description |
|---|---|---|
| DenseVector | a | A vector, which must have the same size as |
| Double | b | A scalar. |
Returns
| Type | Description |
|---|---|
| DenseVector |
|
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(Matrix, DenseVector)
Set this dense vector to the product of a matrix by a dense vector (i.e. A*x).
Declaration
public DenseVector SetToProduct(Matrix A, DenseVector x)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix | A | A matrix. |
| DenseVector | x | A vector. Cannot be |
Returns
| Type | Description |
|---|---|
| DenseVector |
|
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(Matrix, Vector)
Set this vector to the product of a matrix by a vector (i.e. A*x).
Declaration
public override Vector SetToProduct(Matrix A, Vector x)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix | A | A matrix. |
| Vector | x | A vector. Cannot be |
Returns
| Type | Description |
|---|---|
| Vector |
|
Overrides
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 override Vector SetToProduct(Vector x, Matrix A)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector | x | A vector. Cannot be |
| Matrix | A | A matrix. |
Returns
| Type | Description |
|---|---|
| Vector |
|
Overrides
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 dense vector to the elementwise product of two other vectors.
Declaration
public override void SetToProduct(Vector a, Vector b)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector | a | Must have the same size as |
| Vector | b | Must have the same size as |
Overrides
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 override Vector SetToProduct(Vector a, double b)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector | a | A vector, which must have the same size as |
| Double | b | A scalar. |
Returns
| Type | Description |
|---|---|
| Vector |
|
Overrides
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(DenseVector, DenseVector)
Sets this dense vector to the elementwise ratio of two other dense vectors.
Declaration
public DenseVector SetToRatio(DenseVector a, DenseVector b)
Parameters
| Type | Name | Description |
|---|---|---|
| DenseVector | a | Must have the same size as |
| DenseVector | b | Must have the same size as |
Returns
| Type | Description |
|---|---|
| DenseVector |
|
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 override Vector SetToRatio(Vector a, Vector b)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector | a | Must have the same size as |
| Vector | b | Must have the same size as |
Returns
| Type | Description |
|---|---|
| Vector |
|
Overrides
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 override void SetToSubarray(double[] values, int startIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| Double[] | values | An array whose length is at least |
| Int32 | startIndex | The index of the first value in |
Overrides
SetToSubvector(DenseVector, Int32)
Copies value from a vector.
Declaration
public void SetToSubvector(DenseVector that, int startIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| DenseVector | that | A dense vector whose length is at least |
| Int32 | startIndex | The index of the first value in |
SetToSubvector(Vector, Int32)
Copies value from a vector.
Declaration
public override void SetToSubvector(Vector that, int startIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector | that | A vector whose length is at least |
| Int32 | startIndex | The index of the first value in |
Overrides
SetToSum(DenseVector, DenseVector)
Sets this dense vector to the elementwise sum of two other dense vectors.
Declaration
public DenseVector SetToSum(DenseVector a, DenseVector b)
Parameters
| Type | Name | Description |
|---|---|---|
| DenseVector | a | First vector, which must have the same size as |
| DenseVector | b | Second vector, which must have the same size as |
Returns
| Type | Description |
|---|---|
| DenseVector |
|
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(DenseVector, Double)
Sets this dense vector to another dense vector plus a scalar.
Declaration
public DenseVector SetToSum(DenseVector a, double b)
Parameters
| Type | Name | Description |
|---|---|---|
| DenseVector | a | A vector, which must have the same size as |
| Double | b | A scalar. |
Returns
| Type | Description |
|---|---|
| DenseVector |
|
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(Vector, Vector)
Sets this vector to the elementwise sum of two other vectors.
Declaration
public override Vector SetToSum(Vector a, Vector b)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector | a | First vector, which must have the same size as |
| Vector | b | Second vector, which must have the same size as |
Returns
| Type | Description |
|---|---|
| Vector |
|
Overrides
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 override Vector SetToSum(Vector a, double b)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector | a | A vector, which must have the same size as |
| Double | b | A scalar. |
Returns
| Type | Description |
|---|---|
| Vector |
|
Overrides
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, DenseVector, Double, DenseVector)
Set this vector to a linear combination of two other vectors
Declaration
public void SetToSum(double aScale, DenseVector a, double bScale, DenseVector b)
Parameters
| Type | Name | Description |
|---|---|---|
| Double | aScale | The multiplier for vector a |
| DenseVector | a | Vector a |
| Double | bScale | The multiplier for vector b |
| DenseVector | b | Vector b |
SetToSum(Double, Vector, Double, Vector)
Set this vector to a linear combination of two other vectors
Declaration
public override void SetToSum(double aScale, Vector a, double bScale, Vector b)
Parameters
| Type | Name | Description |
|---|---|---|
| Double | aScale | The multiplier for vector a |
| Vector | a | Vector a |
| Double | bScale | The multiplier for vector b |
| Vector | b | Vector b |
Overrides
Subvector(Int32, Int32)
Create a subvector of this vector
Declaration
public override Vector Subvector(int startIndex, int count)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | startIndex | |
| Int32 | count |
Returns
| Type | Description |
|---|---|
| Vector |
Overrides
Sum()
Returns the sum of all elements.
Declaration
public override double Sum()
Returns
| Type | Description |
|---|---|
| Double |
Overrides
Sum(Converter<Double, Double>)
Returns the sum of a function of all elements.
Declaration
public override double Sum(Converter<double, double> fun)
Parameters
| Type | Name | Description |
|---|---|---|
| Converter<Double, Double> | fun | Conversion function |
Returns
| Type | Description |
|---|---|
| Double |
Overrides
Sum(Converter<Double, Double>, DenseVector, Converter<Double, Boolean>)
Returns the sum of a function of this dense vector filtered by a function of a second dense vector.
Declaration
public double Sum(Converter<double, double> fun, DenseVector that, Converter<double, bool> cond)
Parameters
| Type | Name | Description |
|---|---|---|
| Converter<Double, Double> | fun | Function to convert the elements of this vector |
| DenseVector | that | Second vector, which must have the same size as |
| 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 |
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 override 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 |
| 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 |
Overrides
SumI()
Returns the sum of over zero-based index times element.
Declaration
public override double SumI()
Returns
| Type | Description |
|---|---|
| Double |
Overrides
SumISq()
Returns the sum of over square of index^2 times element.
Declaration
public override double SumISq()
Returns
| Type | Description |
|---|---|
| Double |
Overrides
ToArray()
Converts this vector to an array of doubles
Declaration
public override double[] ToArray()
Returns
| Type | Description |
|---|---|
| Double[] |
Overrides
ToString(String, String)
String representation of vector with a specified format and delimiter
Declaration
public override string ToString(string format, string delimiter)
Parameters
| Type | Name | Description |
|---|---|---|
| String | format | |
| String | delimiter |
Returns
| Type | Description |
|---|---|
| String |
Overrides
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 override 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 |
Overrides
Zero(Int32)
Create a dense vector of given length with elements all 0.0
Declaration
public static DenseVector Zero(int count)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | count | Number of elements in vector |
Returns
| Type | Description |
|---|---|
| DenseVector |
Explicit Interface Implementations
ICloneable.Clone()
Clones this vector - return as an object
Declaration
object ICloneable.Clone()
Returns
| Type | Description |
|---|---|
| Object |