Search Results for

    Show / Hide Table of Contents

    Class ApproximateSparseVector

    A one-dimensional vector of double values, optimised for the case where many of the elements share a common value (which need not be zero) within some tolerance.

    Inheritance
    Object
    Vector
    SparseVector
    ApproximateSparseVector
    Implements
    IReadOnlyList<Double>
    IReadOnlyCollection<Double>
    SettableToPower<Vector>
    SettableToProduct<Vector>
    SettableToProduct<Vector, Vector>
    SettableToWeightedSum<Vector>
    ISparseList<Double>
    ISparseEnumerable<Double>
    IList<Double>
    ICollection<Double>
    IEnumerable<Double>
    IEnumerable
    ICloneable
    CanSetAllElementsTo<Double>
    SettableTo<Vector>
    Inherited Members
    SparseVector.SparseValues
    SparseVector.CommonValue
    SparseVector.Count
    SparseVector.SparseCount
    SparseVector.FromSparseValues(Int32, Double, List<ValueAtIndex<Double>>)
    SparseVector.GetSparseIndex(Int32)
    SparseVector.HasCommonElements
    SparseVector.GetFirstCommonIndex()
    SparseVector.GetEnumerator()
    SparseVector.IEnumerable.GetEnumerator()
    SparseVector.GetSparseEnumerator()
    SparseVector.SetAllElementsTo(Double)
    SparseVector.SetTo(SparseVector)
    SparseVector.SetTo(IList<Double>)
    SparseVector.Equals(Object)
    SparseVector.GreaterThan(Vector)
    SparseVector.LessThan(Vector)
    SparseVector.GreaterThanOrEqual(Vector)
    SparseVector.LessThanOrEqual(Vector)
    SparseVector.All(Converter<Double, Boolean>)
    SparseVector.Any(Converter<Double, Boolean>)
    SparseVector.Any(Vector, Func<Double, Double, Boolean>)
    SparseVector.Any(SparseVector, Func<Double, Double, Boolean>)
    SparseVector.FindAll(Converter<Double, Boolean>)
    SparseVector.CountAll(Converter<Double, Boolean>)
    SparseVector.FindFirstIndex(Converter<Double, Boolean>)
    SparseVector.FindLastIndex(Converter<Double, Boolean>)
    SparseVector.Reduce(Double, Func<Double, Double, Double>)
    SparseVector.Reduce(Double, Vector, Func<Double, Double, Double, Double>)
    SparseVector.Reduce(Double, SparseVector, Func<Double, Double, Double, Double>)
    SparseVector.Reduce(Double, SparseVector, SparseVector, Func<Double, Double, Double, Double, Double>)
    SparseVector.Reduce<TRes>(TRes, Func<TRes, Double, TRes>, Func<TRes, Double, Int32, TRes>)
    SparseVector.Reduce<TRes, T1>(TRes, ISparseEnumerable<T1>, Func<TRes, Double, T1, TRes>, Func<TRes, Double, T1, Int32, TRes>)
    SparseVector.Reduce<TRes, T1, T2>(TRes, ISparseEnumerable<T1>, ISparseEnumerable<T2>, Func<TRes, Double, T1, T2, TRes>, Func<TRes, Double, T1, T2, Int32, TRes>)
    SparseVector.Sum()
    SparseVector.Sum(Converter<Double, Double>)
    SparseVector.Sum(Converter<Double, Double>, Vector, Converter<Double, Boolean>)
    SparseVector.Sum(Converter<Double, Double>, SparseVector, Converter<Double, Boolean>)
    SparseVector.SumI()
    SparseVector.SumISq()
    SparseVector.Max()
    SparseVector.Max(Converter<Double, Double>)
    SparseVector.Median()
    SparseVector.Min()
    SparseVector.Min(Converter<Double, Double>)
    SparseVector.LogSumExp()
    SparseVector.IndexOfMinimum()
    SparseVector.IndexOfMaximum()
    SparseVector.IndexAtCumulativeSum(Double)
    SparseVector.Inner(Vector)
    SparseVector.Inner(SparseVector)
    SparseVector.Inner(Vector, Converter<Double, Double>)
    SparseVector.Inner(SparseVector, Converter<Double, Double>)
    SparseVector.Inner(Converter<Double, Double>, Vector, Converter<Double, Double>)
    SparseVector.Inner(Converter<Double, Double>, SparseVector, Converter<Double, Double>)
    SparseVector.Outer(Vector)
    SparseVector.Outer(SparseVector)
    SparseVector.CopyTo(Double[], Int32)
    SparseVector.SetToFunction(Vector, Converter<Double, Double>)
    SparseVector.SetToFunction(Vector, Vector, Func<Double, Double, Double>)
    SparseVector.ToArray()
    SparseVector.ToVector()
    SparseVector.AsSparseVector(IList<Double>)
    SparseVector.SetToSubvector(Vector, Int32)
    SparseVector.Add(Double)
    SparseVector.Clear()
    SparseVector.Remove(Double)
    Vector.Sparsity
    Vector.IsDense
    Vector.IsSparse
    Vector.IsApproximate
    Vector.IsExact
    Vector.Copy(Vector, Sparsity)
    Vector.FromArray(Double[], Sparsity)
    Vector.FromList(IList<Double>)
    Vector.FromArray(Int32, Double[], Int32, Sparsity)
    Vector.IList<Double>.Insert(Int32, Double)
    Vector.IList<Double>.RemoveAt(Int32)
    Vector.IsReadOnly
    Vector.ICollection<Double>.Add(Double)
    Vector.ICollection<Double>.Clear()
    Vector.ICollection<Double>.Remove(Double)
    Vector.CheckCompatible(Vector, String)
    Vector.IndexOfAll(Converter<Double, Boolean>)
    Vector.Reduce(Double, Vector, Vector, Func<Double, Double, Double, Double, Double>)
    Vector.SetToPower(Vector, Double)
    Vector.SetToProduct(Vector, Vector)
    Vector.SetToSum(Double, Vector, Double, Vector)
    Vector.SetToSum(Vector, Vector)
    Vector.SetToSum(Vector, Double)
    Vector.SetToDifference(Vector, Vector)
    Vector.SetToDifference(Vector, Double)
    Vector.SetToDifference(Double, Vector)
    Vector.SetToProduct(Vector, Double)
    Vector.SetToProduct(Vector, Matrix)
    Vector.SetToProduct(Matrix, Vector)
    Vector.SetToRatio(Vector, Vector)
    Vector.InnerProduct(Vector, Vector)
    Vector.EqualsAll(Double)
    Vector.GreaterThan(Double)
    Vector.LessThan(Double)
    Vector.GreaterThanOrEqual(Double)
    Vector.LessThanOrEqual(Double)
    Vector.ToString(String, String, Func<Int32, String>)
    Vector.PredivideBy(UpperTriangularMatrix)
    Vector.PredivideByTranspose(LowerTriangularMatrix)
    Vector.PredivideBy(LowerTriangularMatrix)
    Vector.EnsureDense(Vector)
    Vector.PredivideBy(PositiveDefiniteMatrix)
    Vector.Concat(Vector, Vector)
    Vector.Subvector(Vector, Int32, Int32)
    Vector.ToString(String)
    Vector.ToString()
    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 class ApproximateSparseVector : SparseVector, IReadOnlyList<double>, IReadOnlyCollection<double>, SettableToPower<Vector>, SettableToProduct<Vector>, SettableToProduct<Vector, Vector>, SettableToWeightedSum<Vector>, ISparseList<double>, ISparseEnumerable<double>, IList<double>, ICollection<double>, IEnumerable<double>, IEnumerable, ICloneable, CanSetAllElementsTo<double>, SettableTo<Vector>

    Properties

    CountTolerance

    The maximum allowed count of vector elements not set to the common value.

    Declaration
    public int CountTolerance { get; }
    Property Value
    Type Description
    Int32
    Remarks

    This is ignored if <= 0 which is the default value.

    Item[Int32]

    Gets or sets an element at a given index.

    Declaration
    public override double this[int index] { get; set; }
    Parameters
    Type Name Description
    Int32 index

    The index of an element.

    Property Value
    Type Description
    Double

    The element at a given index.

    Overrides
    SparseVector.Item[Int32]

    Tolerance

    The tolerance at which vector element values are considered equal to the common value.

    Declaration
    public double Tolerance { get; }
    Property Value
    Type Description
    Double
    Remarks

    By default this tolerance is set to 0.000001.

    Methods

    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
    SparseVector.Append(Vector)
    Remarks

    If the second vector is dense, or if the common values for the two vectors are different, then the result becomes dense

    Append(Double)

    Appends an item to a vector - returns a new sparse vector

    Declaration
    public override Vector Append(double item)
    Parameters
    Type Name Description
    Double item
    Returns
    Type Description
    Vector
    Overrides
    SparseVector.Append(Double)

    Clone()

    Clones this vector - return as a vector

    Declaration
    public override Vector Clone()
    Returns
    Type Description
    Vector
    Overrides
    SparseVector.Clone()

    Constant(Int32, Double)

    Creates an approximate sparse vector of given length with elements all equal to a specified value

    Declaration
    public static ApproximateSparseVector 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
    ApproximateSparseVector

    Constant(Int32, Double, Sparsity)

    Creates an approximate sparse vector of given length with elements all equal to a specified value

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

    Number of elements in vector

    Double value

    value for each element

    Sparsity s

    Sparsity

    Returns
    Type Description
    ApproximateSparseVector

    Contains(Double)

    Returns true if the Vector contains the specified value up to tolerance

    Declaration
    public override bool Contains(double value)
    Parameters
    Type Name Description
    Double value

    The value to test for

    Returns
    Type Description
    Boolean
    Overrides
    SparseVector.Contains(Double)

    Copy(Vector)

    Creates an approximate sparse vector as a copy of another vector (which may not be sparse)

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

    The source vector - can be dense or sparse

    Returns
    Type Description
    ApproximateSparseVector

    FromArray(Double[])

    Constructs a sparse vector from a dense array.

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

    1D array of elements.

    Returns
    Type Description
    ApproximateSparseVector
    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 ApproximateSparseVector 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
    ApproximateSparseVector
    Remarks

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

    FromSparseValues(Int32, Double, Sparsity, List<ValueAtIndex<Double>>)

    Constructs a sparse vector from a sorted list of sparse elements.

    Declaration
    [Construction(new string[]{"Count", "CommonValue", "Sparsity", "SparseValues"})]
    public static ApproximateSparseVector FromSparseValues(int count, double commonValue, Sparsity s, List<ValueAtIndex<double>> sortedSparseValues)
    Parameters
    Type Name Description
    Int32 count

    Count for result

    Double commonValue

    Common value

    Sparsity s

    Sparsity

    List<ValueAtIndex<Double>> sortedSparseValues

    Sorted list of sparse elements

    Returns
    Type Description
    ApproximateSparseVector

    GetHashCode()

    Gets a hash code for the instance.

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    Int32

    The code.

    Overrides
    SparseVector.GetHashCode()

    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 override int IndexOf(double item)
    Parameters
    Type Name Description
    Double item

    The item to check for

    Returns
    Type Description
    Int32

    Its index in the array

    Overrides
    SparseVector.IndexOf(Double)

    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

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

    Overrides
    SparseVector.MaxDiff(Vector)
    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

    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.

    Overrides
    SparseVector.MaxDiff(Vector, Double)
    Remarks

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

    Scale(Double)

    Multiplies this vector by a scalar.

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

    The scalar.

    Overrides
    SparseVector.Scale(Double)
    Remarks

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

    SetSubvector(Int32, Vector)

    Set a subvector of this sparse vector to another vector. The common value is not changed

    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 this.Count - startIndex.

    Overrides
    SparseVector.SetSubvector(Int32, Vector)

    SetTo(ApproximateSparseVector)

    Copies values from a sparse vector to this sparse vector.

    Declaration
    public void SetTo(ApproximateSparseVector that)
    Parameters
    Type Name Description
    ApproximateSparseVector 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
    SparseVector.SetTo(Vector)
    Remarks

    The source vector can be dense, in which case the minimum value is used as the common value.

    SetTo(IEnumerable<Double>)

    Set this vector to a collection

    Declaration
    public override void SetTo(IEnumerable<double> that)
    Parameters
    Type Name Description
    IEnumerable<Double> that
    Overrides
    SparseVector.SetTo(IEnumerable<Double>)

    SetTo(IList<Double>, Double)

    Copies values from a list of doubles which must have the same size as this vector, using the specified common value.

    Declaration
    public override void SetTo(IList<double> dlist, double commonValue)
    Parameters
    Type Name Description
    IList<Double> dlist

    List of doubles

    Double commonValue

    Common value

    Overrides
    SparseVector.SetTo(IList<Double>, Double)

    SetTo(Double[])

    Copies values from an array. The minimum value is used as the common value

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

    An array whose length matches this.Count.

    Overrides
    SparseVector.SetTo(Double[])

    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
    SparseVector.SetToDiagonal(Matrix)

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

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

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

    The first vector

    SparseVector b

    The second vector

    Func<Double, Double, Double> fun

    The function which maps two doubles to a double

    Returns
    Type Description
    SparseVector
    Overrides
    SparseVector.SetToFunction(SparseVector, SparseVector, Func<Double, Double, Double>)
    Remarks

    Assumes the vectors are compatible

    SetToFunction(SparseVector, Converter<Double, Double>)

    Sets the elements of this sparse vector to a function of the elements of another sparse vector

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

    The other vector

    Converter<Double, Double> fun

    The function which maps doubles to doubles

    Returns
    Type Description
    SparseVector
    Overrides
    SparseVector.SetToFunction(SparseVector, Converter<Double, Double>)
    Remarks

    Assumes the vectors are compatible

    SetToFunctionInPlace(SparseVector, Func<Double, Double, Double>)

    Sets the elements of this sparse vector to a function of the elements of this sparse vector and another sparse vectors x = fun(x,b)

    Declaration
    public override SparseVector SetToFunctionInPlace(SparseVector b, Func<double, double, double> fun)
    Parameters
    Type Name Description
    SparseVector b

    The second vector

    Func<Double, Double, Double> fun

    The function which maps two doubles to a double

    Returns
    Type Description
    SparseVector
    Overrides
    SparseVector.SetToFunctionInPlace(SparseVector, Func<Double, Double, Double>)
    Remarks

    Assumes the vectors are compatible

    SetToSubarray(Double[], Int32)

    Copies values from an array. The minimum is used as the common value

    Declaration
    public override 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.

    Overrides
    SparseVector.SetToSubarray(Double[], Int32)

    SetToSubvector(SparseVector, Int32)

    Copies values from a sparse vector. The common value is set to the common value from the source vector.

    Declaration
    public override void SetToSubvector(SparseVector that, int startIndex)
    Parameters
    Type Name Description
    SparseVector that

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

    Int32 startIndex

    The index of the first value in that to copy.

    Overrides
    SparseVector.SetToSubvector(SparseVector, Int32)

    Subvector(Int32, Int32)

    Create a subvector of this sparse vector.

    Declaration
    public override Vector Subvector(int startIndex, int count)
    Parameters
    Type Name Description
    Int32 startIndex
    Int32 count
    Returns
    Type Description
    Vector
    Overrides
    SparseVector.Subvector(Int32, Int32)

    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
    SparseVector.ToString(String, String)

    Zero(Int32)

    Creates an approximate sparse vector of given length with elements all 0.0

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

    Number of elements in vector

    Returns
    Type Description
    ApproximateSparseVector

    Zero(Int32, Sparsity)

    Creates an approximate sparse vector of given length with elements all 0.0

    Declaration
    public static ApproximateSparseVector Zero(int count, Sparsity s)
    Parameters
    Type Name Description
    Int32 count

    Number of elements in vector

    Sparsity s

    Sparsity

    Returns
    Type Description
    ApproximateSparseVector

    Explicit Interface Implementations

    ICloneable.Clone()

    Clones this vector - return as an object

    Declaration
    object ICloneable.Clone()
    Returns
    Type Description
    Object

    Implements

    System.Collections.Generic.IReadOnlyList<T>
    System.Collections.Generic.IReadOnlyCollection<T>
    SettableToPower<T>
    SettableToProduct<T>
    SettableToProduct<T, U>
    SettableToWeightedSum<T>
    ISparseList<T>
    ISparseEnumerable<T>
    System.Collections.Generic.IList<T>
    System.Collections.Generic.ICollection<T>
    System.Collections.Generic.IEnumerable<T>
    System.Collections.IEnumerable
    System.ICloneable
    CanSetAllElementsTo<T>
    SettableTo<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.