Show / Hide Table of Contents

Class VectorExtensions

A vector extensions.

Inheritance
System.Object
VectorExtensions
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace:numl.Math.LinearAlgebra
Assembly:numl.dll
Syntax
public static class VectorExtensions

Methods

View Source

Calc(Vector, Func<Double, Double>)

A Vector extension method that calcs.

Declaration
public static Vector Calc(this Vector v, Func<double, double> f)
Parameters
Type Name Description
Vector v

The v to act on.

System.Func<System.Double, System.Double> f

The Func<T,double> to process.

Returns
Type Description
Vector

A Vector.

View Source

Combine(Vector, Vector[])

Binds the supplied Vectors with the current vector.

Declaration
public static Vector Combine(this Vector source, params Vector[] vectors)
Parameters
Type Name Description
Vector source

Source vector.

Vector[] vectors

Array of vectors to bind with.

Returns
Type Description
Vector
View Source

ContainsNaN(Vector)

A Vector extension method that query if 'vector' contains na n.

Declaration
public static bool ContainsNaN(this Vector vector)
Parameters
Type Name Description
Vector vector

The vector to act on.

Returns
Type Description
System.Boolean

true if it succeeds, false if it fails.

View Source

Correlation(Vector, Vector)

A Vector extension method that correlations.

Declaration
public static double Correlation(this Vector x, Vector y)
Parameters
Type Name Description
Vector x

The x to act on.

Vector y

The Vector to process.

Returns
Type Description
System.Double

A double.

View Source

Covariance(Vector, Vector)

A Vector extension method that covariances.

Declaration
public static double Covariance(this Vector x, Vector y)
Parameters
Type Name Description
Vector x

The x to act on.

Vector y

The Vector to process.

Returns
Type Description
System.Double

A double.

Exceptions
Type Condition
System.InvalidOperationException

Thrown when the requested operation is invalid.

View Source

Diag(Vector)

A Vector extension method that diags.

Declaration
public static Matrix Diag(this Vector v)
Parameters
Type Name Description
Vector v

The v to act on.

Returns
Type Description
Matrix

A Matrix.

View Source

Diag(Vector, Int32, Int32)

A Vector extension method that diags.

Declaration
public static Matrix Diag(this Vector v, int n, int d)
Parameters
Type Name Description
Vector v

The v to act on.

System.Int32 n

The int to process.

System.Int32 d

The int to process.

Returns
Type Description
Matrix

A Matrix.

View Source

Dot(Vector, Vector)

A Vector extension method that dots.

Declaration
public static double Dot(this Vector v, Vector x)
Parameters
Type Name Description
Vector v

The v to act on.

Vector x

The x to act on.

Returns
Type Description
System.Double

A double.

View Source

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

A Vector extension method that eaches.

Declaration
public static Vector Each(this Vector v, Func<double, double> transform, bool asCopy = false)
Parameters
Type Name Description
Vector v

The v to act on.

System.Func<System.Double, System.Double> transform

The transform.

System.Boolean asCopy

(Optional) true to as copy.

Returns
Type Description
Vector

A Vector.

View Source

Each(Vector, Func<Double, Int32, Double>, Boolean)

A Vector extension method that eaches.

Declaration
public static Vector Each(this Vector v, Func<double, int, double> transform, bool asCopy = false)
Parameters
Type Name Description
Vector v

The v to act on.

System.Func<System.Double, System.Int32, System.Double> transform

The transform including value and coordinate.

System.Boolean asCopy

(Optional) true to as copy.

Returns
Type Description
Vector

A Vector.

View Source

Expand(Vector, Vector)

A Vector extension method that expands.

Declaration
public static Vector Expand(this Vector source, Vector s)
Parameters
Type Name Description
Vector source

The source to act on.

Vector s

The Vector to process.

Returns
Type Description
Vector

A Vector.

View Source

Expand(Vector, Int32)

A Vector extension method that expands.

Declaration
public static Vector Expand(this Vector source, int n)
Parameters
Type Name Description
Vector source

The source to act on.

System.Int32 n

The int to process.

Returns
Type Description
Vector

A Vector.

View Source

First(Vector, Func<Int32, Double, Boolean>)

A Vector extension method that firsts.

Declaration
public static int First(this Vector v, Func<int, double, bool> predicate)
Parameters
Type Name Description
Vector v

The v to act on.

System.Func<System.Int32, System.Double, System.Boolean> predicate

The predicate.

Returns
Type Description
System.Int32

An int.

View Source

Generate(IEnumerable<Double>, Func<Double, Double>)

Enumerates generate in this collection.

Declaration
public static IEnumerable<double> Generate(this IEnumerable<double> seq, Func<double, double> gen)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<System.Double> seq

The seq to act on.

System.Func<System.Double, System.Double> gen

The generate.

Returns
Type Description
System.Collections.Generic.IEnumerable<System.Double>

An enumerator that allows foreach to be used to process generate in this collection.

View Source

GetRandom(Vector)

Gets a random element from the vector.

Declaration
public static double GetRandom(this Vector v)
Parameters
Type Name Description
Vector v

The v.

Returns
Type Description
System.Double

System.Double.

View Source

Indices(IEnumerable<Double>, Func<Double, Boolean>)

Enumerates indices in this collection.

Declaration
public static IEnumerable<int> Indices(this IEnumerable<double> source, Func<double, bool> f)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<System.Double> source

The source to act on.

System.Func<System.Double, System.Boolean> f

The Func<T,double> to process.

Returns
Type Description
System.Collections.Generic.IEnumerable<System.Int32>

An enumerator that allows foreach to be used to process indices in this collection.

View Source

Insert(Vector, Int32, Double, Boolean)

Inserts the supplied value into a new Vector at the specified position

Declaration
public static Vector Insert(this Vector source, int index, double value, bool insertAfter = true)
Parameters
Type Name Description
Vector source
System.Int32 index

Row or Column index

System.Double value

Value to insert

System.Boolean insertAfter

True to add to the end, if the index matches last column

Returns
Type Description
Vector
View Source

IsBinary(Vector)

Returns True if the Vector contains only positive and negative values (either 0 or -1).

Declaration
public static bool IsBinary(this Vector vector)
Parameters
Type Name Description
Vector vector

The input vector.

Returns
Type Description
System.Boolean

Boolean.

View Source

IsNaN(Vector)

A Vector extension method that query if 'vector' is na n.

Declaration
public static bool IsNaN(this Vector vector)
Parameters
Type Name Description
Vector vector

The vector to act on.

Returns
Type Description
System.Boolean

true if na n, false if not.

View Source

Last(Vector, Func<Int32, Double, Boolean>)

A Vector extension method that lasts.

Declaration
public static int Last(this Vector v, Func<int, double, bool> predicate)
Parameters
Type Name Description
Vector v

The v to act on.

System.Func<System.Int32, System.Double, System.Boolean> predicate

The predicate.

Returns
Type Description
System.Int32

An int.

View Source

Log(Vector)

Returns the Log of the current Vector

Declaration
public static Vector Log(this Vector v)
Parameters
Type Name Description
Vector v
Returns
Type Description
Vector
View Source

MaxIndex(IEnumerable<Double>)

An IEnumerable<double> extension method that maximum index.

Declaration
public static int MaxIndex(this IEnumerable<double> source)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<System.Double> source

The source to act on.

Returns
Type Description
System.Int32

An int.

View Source

Mean(Vector)

A Vector extension method that determines the mean of the given parameters.

Declaration
public static double Mean(this Vector source)
Parameters
Type Name Description
Vector source

The source to act on.

Returns
Type Description
System.Double

The mean value.

Exceptions
Type Condition
System.InvalidOperationException

Thrown when the requested operation is invalid.

View Source

Mean(IEnumerable<Vector>)

A Vector extension method that determines the mean of the given parameters.

Declaration
public static Vector Mean(this IEnumerable<Vector> source)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<Vector> source

The source to act on.

Returns
Type Description
Vector

The mean value.

Exceptions
Type Condition
System.InvalidOperationException

Thrown when the requested operation is invalid.

View Source

Median(Vector)

Returns the median value of the Vector.

Declaration
public static double Median(this Vector source)
Parameters
Type Name Description
Vector source

Vector.

Returns
Type Description
System.Double

Double.

View Source

MinIndex(IEnumerable<Double>)

An IEnumerable<double> extension method that minimum index.

Declaration
public static int MinIndex(this IEnumerable<double> source)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<System.Double> source

The source to act on.

Returns
Type Description
System.Int32

An int.

View Source

Mode(Vector)

A Vector extension method that modes the given source.

Declaration
public static double Mode(this Vector source)
Parameters
Type Name Description
Vector source

The source to act on.

Returns
Type Description
System.Double

A double.

View Source

Norm(Vector)

A Vector extension method that normals.

Declaration
public static double Norm(this Vector v)
Parameters
Type Name Description
Vector v

The v to act on.

Returns
Type Description
System.Double

A double.

View Source

Norm(Vector, Double)

A Vector extension method that normals.

Declaration
public static double Norm(this Vector v, double p)
Parameters
Type Name Description
Vector v

The v to act on.

System.Double p

The double to process.

Returns
Type Description
System.Double

A double.

View Source

Outer(Vector, Vector)

A Vector extension method that outers.

Declaration
public static Matrix Outer(this Vector x, Vector y)
Parameters
Type Name Description
Vector x

The x to act on.

Vector y

The Vector to process.

Returns
Type Description
Matrix

A Matrix.

View Source

Prod(Vector)

A Vector extension method that products the given v.

Declaration
public static double Prod(this Vector v)
Parameters
Type Name Description
Vector v

The v to act on.

Returns
Type Description
System.Double

A double.

View Source

Reshape(Vector, Int32, VectorType, VectorType)

Reshapes the given Vector into a Matrix form given the specified dimension.

Reads from the source vector and repopulates from left to right when vectorType equals 'Col' otherwise uses top down approach.

Declaration
public static Matrix Reshape(this Vector source, int dimension, VectorType vectorType = VectorType.Col, VectorType fillType = VectorType.Row)
Parameters
Type Name Description
Vector source
System.Int32 dimension

If the vectorType equals 'Col' the dimension becomes the column width otherwise it is row height.

VectorType vectorType

Unit type of the dimension to use when rebuilding the Matrix.

VectorType fillType

Direction to process, i.e. Row = Fill Down then Right, or Col = Fill Right then Down

Returns
Type Description
Matrix

Matrix.

View Source

Reverse(Vector)

Enumerates reverse in this collection.

Declaration
public static IEnumerable<double> Reverse(this Vector v)
Parameters
Type Name Description
Vector v

The v to act on.

Returns
Type Description
System.Collections.Generic.IEnumerable<System.Double>

An enumerator that allows foreach to be used to process reverse in this collection.

View Source

Round(Vector, Int32)

A Vector extension method that rounds.

Declaration
public static Vector Round(this Vector v, int decimals = 0)
Parameters
Type Name Description
Vector v

The v to act on.

System.Int32 decimals

(Optional) the decimals.

Returns
Type Description
Vector

A Vector.

View Source

Segment(Vector, Int32)

A Vector extension method that segments.

Declaration
public static Range[] Segment(this Vector x, int segments)
Parameters
Type Name Description
Vector x

The x to act on.

System.Int32 segments

The segments.

Returns
Type Description
Range[]

A Range[].

Exceptions
Type Condition
System.InvalidOperationException

Thrown when the requested operation is invalid.

View Source

Slice(Vector, IEnumerable<Int32>)

Enumerates slice in this collection.

Declaration
public static Vector Slice(this Vector v, IEnumerable<int> indices)
Parameters
Type Name Description
Vector v

The v to act on.

System.Collections.Generic.IEnumerable<System.Int32> indices

The indices.

Returns
Type Description
Vector

An enumerator that allows foreach to be used to process slice in this collection.

View Source

Slice(Vector, IEnumerable<Int32>, Boolean)

Slices the given Vector while preserving the index ordering in the specified index array.

Declaration
public static Vector Slice(this Vector v, IEnumerable<int> indices, bool preserveOrder)
Parameters
Type Name Description
Vector v

Vector to slice.

System.Collections.Generic.IEnumerable<System.Int32> indices

Index array to extract.

System.Boolean preserveOrder

If True, the ordering in indices is preserved.

Returns
Type Description
Vector
View Source

Slice(Vector, Int32, Int32)

Slices using starting and stopping positions.

Declaration
public static Vector Slice(this Vector v, int fromIndex, int toIndex)
Parameters
Type Name Description
Vector v

Vector.

System.Int32 fromIndex

Minimum index to from.

System.Int32 toIndex

Maximum index to.

Returns
Type Description
Vector
View Source

Slice(IEnumerable<Double>, Func<Double, Boolean>)

Enumerates slice in this collection.

Declaration
public static IEnumerable<double> Slice(this IEnumerable<double> x, Func<double, bool> where)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<System.Double> x

The x to act on.

System.Func<System.Double, System.Boolean> where

The where.

Returns
Type Description
System.Collections.Generic.IEnumerable<System.Double>

An enumerator that allows foreach to be used to process slice in this collection.

View Source

Sort(Vector, Boolean, out Int32[])

Sorts the given Vector by the specified direction, and returns the original unsorted indices.

Declaration
public static Vector Sort(this Vector source, bool ascending, out int[] indices)
Parameters
Type Name Description
Vector source

Vector.

System.Boolean ascending

True to sort in ascending order, otherwise False.

System.Int32[] indices

The original index array before sorting.

Returns
Type Description
Vector
View Source

Sqrt(Vector)

Computes the element-wise square-root value for each row / col value.

Declaration
public static Vector Sqrt(this Vector source)
Parameters
Type Name Description
Vector source

The source Vector.

Returns
Type Description
Vector

Vector.

View Source

Stats(Vector)

A Vector extension method that statistics the given x coordinate.

Declaration
public static Matrix Stats(this Vector x)
Parameters
Type Name Description
Vector x

The x to act on.

Returns
Type Description
Matrix

A Matrix.

View Source

StdDev(Vector, Boolean)

A Vector extension method that computes the standard deviation

Declaration
public static double StdDev(this Vector source, bool isSamplePop = false)
Parameters
Type Name Description
Vector source

The source to act on.

System.Boolean isSamplePop

is sample population?

Returns
Type Description
System.Double

A double.

View Source

Sum(Vector)

An IEnumerable<Vector> extension method that sums the given source.

Declaration
public static double Sum(this Vector v)
Parameters
Type Name Description
Vector v

The v to act on.

Returns
Type Description
System.Double

A Vector.

View Source

Sum(IEnumerable<Vector>)

An IEnumerable<Vector> extension method that sums the given source.

Declaration
public static Vector Sum(this IEnumerable<Vector> source)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<Vector> source

The source to act on.

Returns
Type Description
Vector

A Vector.

View Source

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

Converts the Vector to a binary Vector based on a predicate function.

Declaration
public static Vector ToBinary(this Vector v, Func<double, bool> fnPredicate, double trueValue = 1, double falseValue = 0)
Parameters
Type Name Description
Vector v

Vector to process.

System.Func<System.Double, System.Boolean> fnPredicate

Predicate function to test values for.

System.Double trueValue

True substitution value.

System.Double falseValue

False substitution value.

Returns
Type Description
Vector
View Source

ToBinaryMatrix(Vector, Boolean)

Returns a 1-of-k binary indexed Matrix (m x k) from the supplied Vector, where k is the number of distinct values.

Declaration
public static Matrix ToBinaryMatrix(this Vector v, bool expand = false)
Parameters
Type Name Description
Vector v

Vector of discrete values.

System.Boolean expand

If True, a binary Vector is expanded to a m x 2 Matrix, otherwise a binary Matrix of m x 1 is returned.

Returns
Type Description
Matrix

Matrix.

View Source

ToDouble(Vector)

Return the result of a 1 x m * m x 1

Declaration
public static double ToDouble(this Vector vector)
Parameters
Type Name Description
Vector vector
Returns
Type Description
System.Double
View Source

ToMatrix(IEnumerable<Vector>, VectorType)

An IEnumerable<double[]> extension method that converts the source into a matrix.

Declaration
public static Matrix ToMatrix(this IEnumerable<Vector> source, VectorType vectorType = VectorType.Row)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<Vector> source

The source to act on.

VectorType vectorType

The VectorType of the input array.

Returns
Type Description
Matrix

e as a Matrix.

Exceptions
Type Condition
System.InvalidOperationException

Thrown when the requested operation is invalid.

View Source

ToMatrix(IEnumerable<Double[]>)

An IEnumerable<double[]> extension method that converts an e to a matrix.

Declaration
public static Matrix ToMatrix(this IEnumerable<double[]> e)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<System.Double[]> e

The e to act on.

Returns
Type Description
Matrix

e as a Matrix.

View Source

Top(Vector, Int32)

Enumerates top in this collection.

Declaration
public static IEnumerable<int> Top(this Vector source, int n)
Parameters
Type Name Description
Vector source

The source to act on.

System.Int32 n

The int to process.

Returns
Type Description
System.Collections.Generic.IEnumerable<System.Int32>

An enumerator that allows foreach to be used to process top in this collection.

Exceptions
Type Condition
System.InvalidOperationException

Thrown when the requested operation is invalid.

View Source

TopReverse(Vector, Int32)

Enumerates top reverse in this collection.

Declaration
public static IEnumerable<int> TopReverse(this Vector source, int n)
Parameters
Type Name Description
Vector source

The source to act on.

System.Int32 n

The int to process.

Returns
Type Description
System.Collections.Generic.IEnumerable<System.Int32>

An enumerator that allows foreach to be used to process top reverse in this collection.

Exceptions
Type Condition
System.InvalidOperationException

Thrown when the requested operation is invalid.

View Source

ToVector(IEnumerable<Double>)

An IEnumerable<int> extension method that converts a seq to a vector.

Declaration
public static Vector ToVector(this IEnumerable<double> seq)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<System.Double> seq

The seq to act on.

Returns
Type Description
Vector

seq as a Vector.

View Source

ToVector(IEnumerable<Int32>)

An IEnumerable<int> extension method that converts a seq to a vector.

Declaration
public static Vector ToVector(this IEnumerable<int> seq)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<System.Int32> seq

The seq to act on.

Returns
Type Description
Vector

seq as a Vector.

View Source

ToVector(Double[])

An IEnumerable<int> extension method that converts a seq to a vector.

Declaration
public static Vector ToVector(this double[] array)
Parameters
Type Name Description
System.Double[] array

The array to act on.

Returns
Type Description
Vector

seq as a Vector.

View Source

ToVector<T>(IEnumerable<T>, Func<T, Double>)

An IEnumerable<T> extension method that converts this object to a vector.

Declaration
public static Vector ToVector<T>(this IEnumerable<T> seq, Func<T, double> f)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<T> seq

The seq to act on.

System.Func<T, System.Double> f

The Func<T,double> to process.

Returns
Type Description
Vector

The given data converted to a Vector.

Type Parameters
Name Description
T
View Source

Variance(Vector, Boolean)

A Vector extension method that computes variances the given x coordinate

Declaration
public static double Variance(this Vector x, bool isSamplePop = false)
Parameters
Type Name Description
Vector x

The source to act on.

System.Boolean isSamplePop

is sample population?

Returns
Type Description
System.Double

A double.

  • View Source
©2017 — Seth Juarez
numl v0.9.20-beta
MIT License
docs by docfx