tensor/tensor_math_cpu
library
Functions
-
add(Tensor<Scalar> a, Tensor<Scalar> b)
→ Tensor<Scalar>
-
Simple addition of tensor
a and b.
-
add3D(Tensor<Tensor3D> a, Tensor<Tensor3D> b)
→ Tensor<Tensor3D>
-
Adds the elements of
a to the elements of b. a and b are required to have the same size.
-
addMatrix(Tensor<Matrix> a, Tensor<Matrix> b)
→ Tensor<Matrix>
-
Adds a matrix
a to a matrix b.
-
addMatrixAndVector(Tensor<Matrix> m, Tensor<Vector> v)
→ Tensor<Matrix>
-
Adds a vector
v to every row of matrix m.
-
addScalar(Tensor<Vector> v, double s)
→ Tensor<Vector>
-
Adds a constant value to each element of a vector.
-
addScalarToMatrix(Tensor<Matrix> m, Tensor<Scalar> s)
→ Tensor<Matrix>
-
Adds a scalar
s to every element of a matrix m.
-
addVector(Tensor<Vector> a, Tensor<Vector> b)
→ Tensor<Vector>
-
Adds two vectors together element.
-
avgPool1d(Tensor<Vector> input, int poolSize, int stride)
→ Tensor<Vector>
-
Slides a window of size
poolSize over the vector with the step-size stride.
Returns a vector containing the averages of the observed windows.
-
avgPool2d(Tensor<Matrix> input, int poolSize, int stride)
→ Tensor<Matrix>
-
Slides a 2 dimensional kernel over a Matrix averaging the window together.
The sliding window size is defined by
poolSizexpoolSize with stride as the step size in both dimensions.
-
batchNorm1dMath(Tensor<Vector> x, Tensor<Vector> gamma, Tensor<Vector> beta, Vector runningMean, Vector runningVariance, int numFeatures, bool isTraining, double momentum, double epsilon)
→ Tensor<Vector>
-
Applies Batch Normalization over a 1D vector.
-
batchNorm2dMath(Tensor<Tensor3D> x, Tensor<Vector> gamma, Tensor<Vector> beta, Vector runningMean, Vector runningVariance, int numChannels, bool isTraining, double momentum, double epsilon)
→ Tensor<Tensor3D>
-
Applies Batch Normalization over a 3D tensor (channels, height, width).
-
binaryCrossEntropy(Tensor<Scalar> prediction, Tensor<Scalar> target)
→ Tensor<Scalar>
-
Calculates the binary cross entropy by comparing the prediction of the network to the target required.
-
concatenate(Tensor<Vector> a, Tensor<Vector> b)
→ Tensor<Vector>
-
Appends two vectors after each oder with
a and b becoming ab.
-
concatenate3D(Tensor<Tensor3D> a, Tensor<Tensor3D> b)
→ Tensor<Tensor3D>
-
Appends two Tensor3D objects together on their 0th axis.
-
concatenateMatricesByColumn(List<Tensor<Matrix>> matrices)
→ Tensor<Matrix>
-
Concatenates two matrices via their columns
-
conv2d(Tensor<Matrix> input, Tensor<Matrix> kernel, {String padding = 'valid'})
→ Tensor<Matrix>
-
Slides a kernel
kernel over the matrix and calculates the elementwise multiplication at each position.
Allows for optional zero padding with padding = 'same' where input size equals output size.
-
dot(Tensor<Vector> a, Tensor<Vector> b)
→ Tensor<Scalar>
-
Calculates the eucledian dot product of
a and b.
-
dropoutMatrixMath(Tensor<Matrix> input, double rate, bool isTraining)
→ Tensor<Matrix>
-
If
isTraining is set to true this function sets values with the probability rate to zero.
The remaining values get scaled up tp conserve the total sum of the values.
-
dropoutVectorMath(Tensor<Vector> input, double rate, bool isTraining)
→ Tensor<Vector>
-
If
isTraining is set to true this function sets values with the probability rate to zero.
The remaining values get scaled up tp conserve the total sum of the values.
-
elementWiseMultiply(Tensor<Vector> a, Tensor<Vector> b)
→ Tensor<Vector>
-
Multiplies each element of
a with each element of b.
-
elementWiseMultiply3D(Tensor<Tensor3D> a, Tensor<Tensor3D> b)
→ Tensor<Tensor3D>
-
Multiplies the elements of
a with the elements of b. a and b are required to have the same size.
-
elementWiseMultiplyMatrix(Tensor<Matrix> a, Tensor<Matrix> b)
→ Tensor<Matrix>
-
Multiplies the elements of matrix
a with the elements of matrix b. This is NOT matrix multiplication.
-
eluMatrix(Tensor<Matrix> m, double alpha)
→ Tensor<Matrix>
-
Applies the elu activation function to each element inside of
m with multiplying negative values of m with a small negative number alpha to prevent negatives.
-
eluVector(Tensor<Vector> v, double alpha)
→ Tensor<Vector>
-
Applies the elu activation function to each element inside of
v with multiplying negative values of v with a small negative number alpha to prevent negatives.
-
globalAveragePooling(Tensor<Matrix> input)
→ Tensor<Vector>
-
Pools the average over each column in
input.
-
leakyReluMatrix(Tensor<Matrix> m, double alpha)
→ Tensor<Matrix>
-
Applies leaky ReLu over a matrix
m with multiplying negative values with a small negative number alpha to prevent the dying gradient problem.
-
leakyReluVector(Tensor<Vector> v, double alpha)
→ Tensor<Vector>
-
Applies leaky ReLu over a matrix
v with multiplying negative values with a small negative number alpha to prevent the dying gradient problem.
-
matMul(Tensor<Matrix> a, Tensor<Matrix> b)
→ Tensor<Matrix>
-
Calculates the matrix multiplication of two matrices
a and b.
-
matVecMul(Tensor<Matrix> M, Tensor<Vector> v)
→ Tensor<Vector>
-
Multiplies a vector
v with a matrix M, resulting in a new vector.
-
maxPool1d(Tensor<Vector> input, int poolSize, int stride)
→ Tensor<Vector>
-
Slides a window of size
poolSize over the vector with the step-size stride.
Returns a vector containing the maximum in the observed windows.
-
maxPool2d(Tensor<Matrix> input, int poolSize, int stride)
→ Tensor<Matrix>
-
Slides a window of size
poolSize over the matrix with the step-size stride.
Returns a matrix containing the maximum in the observed windows.
-
mishMatrix(Tensor<Matrix> m)
→ Tensor<Matrix>
-
Applies the mish activation function (similar to swish) to each element inside of
m.
Mish mirrors Relu with a continuous curve.
-
mishVector(Tensor<Vector> v)
→ Tensor<Vector>
-
Applies the mish activation function (similar to swish) to each element inside of
v.
Mish mirrors Relu with a continuous curve.
-
mse(Tensor<Vector> predictions, Tensor<Vector> targets)
→ Tensor<Scalar>
-
Calculates the mean square error/difference between the elements of
a and b.
Both Tensors need to have the same size.
-
mseMatrix(Tensor<Matrix> predictions, Tensor<Matrix> targets)
→ Tensor<Scalar>
-
Calculates the mean squared error between two matrices
a and b. Error here means the difference between each element of the matrices.
The provided matrices are required to have the same shape.
-
multiply(Tensor<Scalar> a, Tensor<Scalar> b)
→ Tensor<Scalar>
-
Simple multiplication of tensor
a and b.
-
padMatrix(Matrix input, int padding)
→ Matrix
-
Pads the matrix on all sides with the given
padding.
-
relu(Tensor<Vector> v)
→ Tensor<Vector>
-
Applies the ReLU function to each value of
v. When the values is bigger then 0 it is the output, otherwise 0.
-
reluMatrix(Tensor<Matrix> m)
→ Tensor<Matrix>
-
Applies the ReLU function to every element of a matrix. Every negative value is set to 0.
-
reshapeVectorToMatrix(Tensor<Vector> v, int numRows, int numCols)
→ Tensor<Matrix>
-
Reformats a vector to a matrix with given dimensions
numRowsxnumCols.
-
scaleMatrix(Tensor<Matrix> m, double s)
→ Tensor<Matrix>
-
Multiplies each element of a matrix with a constant
s.
-
selectRow(Tensor<Matrix> m, int rowIndex)
→ Tensor<Vector>
-
Returns the vector of the selected row of
rowIndex inside of m.
-
sigmoid(Tensor<Vector> v)
→ Tensor<Vector>
-
Applies the Sigmoid activation function to each value of a vector.
-
sigmoidMatrix(Tensor<Matrix> m)
→ Tensor<Matrix>
-
Applies the sigmoid function to every value of matrix
m.
-
sigmoidScalar(Tensor<Scalar> s)
→ Tensor<Scalar>
-
Applies the sigmoid activation function to a scalar tensor.
-
softmaxMatrix(Tensor<Matrix> m)
→ Tensor<Matrix>
-
Applies the softmax function to every element. Creates probability distribution over all values summing up to 1.
-
softmaxVector(Tensor<Vector> v)
→ Tensor<Vector>
-
Applies the softmax function over a vector, converting them into a probability value.
-
softplus(Tensor<Vector> v)
→ Tensor<Vector>
-
Differentiable approximation of the Relu function.
-
stackMatricesTo3D(List<Tensor<Matrix>> matrices)
→ Tensor<Tensor3D>
-
Uses a stack of matrices to construct a Tensor3D by concatenating them. Gradient propagation is conserved.
-
sum(Tensor<Vector> v)
→ Tensor<Scalar>
-
Sums up all elements of the input vector tensor.
-
sumMatrix(Tensor<Matrix> m)
→ Tensor<Scalar>
-
Sums all elements of matrix
m together.
-
swishMatrix(Tensor<Matrix> m)
→ Tensor<Matrix>
-
Applies the swish activation function to each element inside of
m.
Swish mirrors Relu with a continuous curve.
-
swishVector(Tensor<Vector> v)
→ Tensor<Vector>
-
Applies the swish activation function to each element inside of
v.
Swish mirrors Relu with a continuous curve.
-
tanhMatrix(Tensor<Matrix> m)
→ Tensor<Matrix>
-
Applies the tanh fucntion to every values of matrix
m.
-
transpose(Tensor<Matrix> a)
→ Tensor<Matrix>
-
Switches rows and columns.
-
vectorExp(Tensor<Vector> v)
→ Tensor<Vector>
-
Calculates the e^x exponent for each element
x in v.
-
vectorLog(Tensor<Vector> v)
→ Tensor<Vector>
-
Calculates the log(x) exponent for each element
x in v.
-
vectorTanh(Tensor<Vector> v)
→ Tensor<Vector>
-
Applies the tanh activation function to every element of a vector.