Report a bug
If you spot a problem with this page, click here to create a GitHub issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
a local clone.
kaleidic.lubeck2
Lubeck 2 - @nogc Linear Algebra
- pure nothrow @nogc @safe Slice!(RCI!T, 2)
eye(T = double)(size_tn, size_tm= 0)
if (isFloatingPoint!T || isComplex!T); - Identity matrix.Parameters:
size_t nnumber of columns size_t moptional number of rows, default n Results Matrix which is 1 on the diagonal and 0 elsewhere
Examples:Real numbersimport mir.ndslice; import mir.math; assert(eye(1)== [ [1]]); assert(eye(2)== [ [1, 0], [0, 1]]); assert(eye(3)== [ [1, 0, 0], [0, 1, 0], [0, 0, 1]]); assert(eye(1,2) == [ [1,0]]); assert(eye(2,1) == [ [1], [0]]);
- pure nothrow @nogc @safe Slice!(RCI!T, 2)
mtimes(T, SliceKind kindA, SliceKind kindB)(Slice!(const(T)*, 2, kindA)a, Slice!(const(T)*, 2, kindB)b)
if (isFloatingPoint!T || isComplex!T);
pure nothrow @nogc @safe Slice!(RCI!(Unqual!A), 2)mtimes(A, B, SliceKind kindA, SliceKind kindB)(auto ref const Slice!(RCI!A, 2, kindA)a, auto ref const Slice!(RCI!B, 2, kindB)b)
if (is(Unqual!A == Unqual!B)); - General matrix-matrix multiplication. Allocates result to using Mir refcounted arrays.Parameters:
Slice!(const(T)*, 2, kindA) am(rows) x k(cols) matrix Slice!(const(T)*, 2, kindB) bk(rows) x n(cols) matrix Result m(rows) x n(cols)
- pure @nogc @safe Slice!(RCI!T, 2)
mldivide(T, SliceKind kindA, SliceKind kindB)(Slice!(const(T)*, 2, kindA)a, Slice!(const(T)*, 2, kindB)b)
if (isFloatingPoint!T || isComplex!T);
pure @nogc @safe Slice!(RCI!(Unqual!A), 2)mldivide(A, B, SliceKind kindA, SliceKind kindB)(auto ref const Slice!(RCI!A, 2, kindA)a, auto ref const Slice!(RCI!B, 2, kindB)b);
pure @nogc @safe Slice!(RCI!(Unqual!A), 1)mldivide(A, B, SliceKind kindA, SliceKind kindB)(auto ref const Slice!(RCI!A, 2, kindA)a, auto ref const Slice!(RCI!B, 1, kindB)b);
pure @nogc @safe Slice!(RCI!T, 1)mldivide(T, SliceKind kindA, SliceKind kindB)(Slice!(const(T)*, 2, kindA)a, Slice!(const(T)*, 1, kindB)b)
if (isFloatingPoint!T || isComplex!T); - Solve systems of linear equations AX = B for X. Computes minimum-norm solution to a linear least squares problem if A is not a square matrix.
- pure @nogc @safe Slice!(RCI!A, 2)
mlinverse(A, SliceKind kindA)(auto ref Slice!(RCI!A, 2, kindA)a); - Solve systems of linear equations AX = I for X, where I is the identity. X is the right inverse of A if it exists, it's also a (Moore-Penrose) Pseudoinverse if A is invertible then X is the inverse. Computes minimum-norm solution to a linear least squares problem if A is not a square matrix.
- struct
SvdResult(T); - Singuar value decomposition result
- Slice!(RCI!T, 2)
u; - Slice!(RCI!T)
sigma; - Singular Values
- Slice!(RCI!T, 2)
vt;
- pure @nogc @safe SvdResult!T
svd(T, string algorithm = "gesvd", SliceKind kind)(Slice!(const(T)*, 2, kind)a, Flag!"slim"slim= No.slim)
if (algorithm == "gesvd" || algorithm == "gesdd"); - Computes the singular value decomposition.Parameters:
Slice!(const(T)*, 2, kind) ainput M x N matrix Flag!" slim"slimIf true the first min(M,N) columns of u and the first min(M,N) rows of vt are returned in the ndslices u and vt. out result = SvdResult. ] Returns:error code from CBlas - struct
PcaResult(T); - Principal component analysis result.
- Slice!(RCI!T, 2)
eigenvectors; - Eigenvectors (Eigenvectors[i] is the ith eigenvector)
- Slice!(RCI!T, 2)
scores; - Principal component scores. (Input matrix rotated to basis of eigenvectors)
- Slice!(RCI!T)
eigenvalues; - Principal component variances. (Eigenvalues)
- Slice!(RCI!T)
mean; - The means of each data column (0 if not centred)
- Slice!(RCI!T)
stdDev; - The standard deviations of each column (1 if not normalized)
- Slice!(RCI!T, 2)
loadings(); - Principal component Loadings vectors (Eigenvectors times sqrt(Eigenvalue))
- pure @nogc @safe PcaResult!T
pca(SliceKind kind, T)(Slice!(const(T)*, 2, kind)data, DeviationEstimatordevEst= DeviationEstimator.sample, MeanEstimatormeanEst= MeanEstimator.average, Flag!"fixEigenvectorDirections"fixEigenvectorDirections= Yes.fixEigenvectorDirections); - Principal component analysis of raw data.
Template correlation = Flag to use correlation matrix instead of covariance
Parameters:Slice!(const(T)*, 2, kind) datainput M x N matrix, where 'M (rows)>= N(cols)' DeviationEstimator devEstMeanEstimator meanEstFlag!" fixEigenvectorDirections"fixEigenvectorDirectionsReturns: - enum
MeanEstimator: int; -
noneaveragemedian
- pure nothrow @nogc @safe T
median(T)(auto ref Slice!(RCI!T)data);
pure nothrow @nogc @safe Tmedian(T)(Slice!(const(T)*)data); - Examples:
import mir.ndslice; import mir.math; auto a = mininitRcslice!double(3); a[] = [3, 1, 7]; auto med = median!double(a.flattened); assert(med == 3.0); assert(a == [3, 1, 7]);//add in stddev out param double aDev; auto aCenter = centerColumns(a, aDev, MeanEstimator.median); assert(aCenter == [0.0, -2.0, 4.0]); assert(aDev == 3.0); auto b = mininitRcslice!double(4); b[] = [4,2,5,1]; auto medB = median!double(b.flattened); assert(medB == 3.0); assert(b == [4,2,5,1]); double bDev; auto bCenter = centerColumns(b, bDev, MeanEstimator.median); assert(bCenter == [1.0, -1.0, 2.0, -2.0]); assert(bDev == 3.0);
- pure nothrow @nogc @safe Slice!(RCI!T, 2)
centerColumns(T, SliceKind kind)(Slice!(const(T)*, 2, kind)matrix, out Slice!(RCI!T)mean, MeanEstimatorest= MeanEstimator.average);
pure nothrow @nogc @safe Slice!(RCI!T)centerColumns(T)(Slice!(const(T)*)col, out Tmean, MeanEstimatorest= MeanEstimator.average);
pure nothrow @nogc @safe Slice!(RCI!T)centerColumns(T)(auto ref const Slice!(RCI!T)col, out Tmean, MeanEstimatorest= MeanEstimator.average);
pure nothrow @nogc @safe Slice!(RCI!T, 2)centerColumns(T, SliceKind kind)(auto ref const Slice!(RCI!T, 2, kind)matrix, out Slice!(RCI!T)mean, MeanEstimatorest= MeanEstimator.average); - Mean Centring of raw data.Parameters:
Slice!(const(T)*, 2, kind) matrixinput M x N matrix Slice!(RCI!T) meancolumn means MeanEstimator estmean estimation method Returns:M x N matrix with each column translated by the column meanExamples:import mir.ndslice; import mir.math; auto data = mininitRcslice!double(2,1); data[] = [[1], [3]]; auto mean = mininitRcslice!double(1); auto res = centerColumns(data, mean, MeanEstimator.average); assert(mean[0] == 2); assert(res == [[-1],[1]]);
- enum
DeviationEstimator: int; -
nonesamplemad- median absolute deviation
- pure nothrow @nogc @safe Slice!(RCI!T, 2)
normalizeColumns(T, SliceKind kind)(auto ref const Slice!(const(T)*, 2, kind)matrix, out Slice!(RCI!T)stdDev, DeviationEstimatordevEst= DeviationEstimator.sample);
pure nothrow @nogc @safe Slice!(RCI!T, 2)normalizeColumns(T, SliceKind kind)(auto ref const Slice!(RCI!T, 2, kind)matrix, out Slice!(RCI!T)stdDev, DeviationEstimatordevEst= DeviationEstimator.sample); - Normalization of raw data.Parameters:
Slice!(const(T)*, 2, kind) matrixinput M x N matrix, each row an observation and each column mean centred Slice!(RCI!T) stdDevcolumn standard deviation DeviationEstimator devEstestimation method Returns:M x N matrix with each column divided by it's standard deviationExamples:import mir.ndslice; import mir.math; auto data = mininitRcslice!double(2,2); data[] = [[ 2, -1], [-2, 1]]; //sd1 = 2 * sqrt(2.0); //sd2 = sqrt(2.0); auto x = 1.0 / sqrt(2.0); auto scaled = mininitRcslice!double(2,2); scaled[] = [[ x, -x], [-x, x]]; auto stdDev = mininitRcslice!double(2); assert(normalizeColumns(data, stdDev) == scaled); assert(stdDev == [2*sqrt(2.0), sqrt(2.0)]);
Copyright © 2016-2021 by Ilya Yaroshenko | Page generated by
Ddoc on Fri Aug 20 14:35:49 2021