public class MatrixUtil extends Object
Constructor and Description |
---|
MatrixUtil() |
Modifier and Type | Method and Description |
---|---|
static org.jblas.DoubleMatrix |
add(org.jblas.DoubleMatrix a,
org.jblas.DoubleMatrix b) |
static void |
assertIntMatrix(org.jblas.DoubleMatrix matrix) |
static org.jblas.DoubleMatrix |
avg(org.jblas.DoubleMatrix... matrices) |
static org.jblas.DoubleMatrix |
binomial(org.jblas.DoubleMatrix p,
int n,
org.apache.commons.math3.random.RandomGenerator rng)
Generate a binomial distribution based on the given rng,
a matrix of p values, and a max number.
|
static void |
columnNormalizeBySum(org.jblas.DoubleMatrix x) |
static org.jblas.DoubleMatrix |
columnStd(org.jblas.DoubleMatrix m)
Calculates the column wise standard deviations
of the matrix
|
static org.jblas.DoubleMatrix |
columnStdDeviation(org.jblas.DoubleMatrix m) |
static org.jblas.DoubleMatrix |
columnWiseMean(org.jblas.DoubleMatrix x,
int axis) |
static void |
complainAboutMissMatchedMatrices(org.jblas.DoubleMatrix d1,
org.jblas.DoubleMatrix d2) |
static org.jblas.DoubleMatrix |
convolution2D(org.jblas.DoubleMatrix input,
int width,
int height,
org.jblas.DoubleMatrix kernel,
int kernelWidth,
int kernelHeight)
Takes a 2D array of grey-levels and a kernel and applies the convolution
over the area of the image specified by width and height.
|
static double |
cosine(org.jblas.DoubleMatrix matrix) |
static double |
cosineSim(org.jblas.DoubleMatrix d1,
org.jblas.DoubleMatrix d2) |
static void |
discretizeColumns(org.jblas.DoubleMatrix toDiscretize,
int numBins) |
static org.jblas.DoubleMatrix |
divColumnsByStDeviation(org.jblas.DoubleMatrix m)
Divides the given matrix's columns
by each column's respective standard deviations
|
static org.jblas.DoubleMatrix |
dot(org.jblas.DoubleMatrix a,
org.jblas.DoubleMatrix b) |
static void |
ensureValidOutcomeMatrix(org.jblas.DoubleMatrix out) |
static boolean |
isInfinite(org.jblas.DoubleMatrix test) |
static boolean |
isNaN(org.jblas.DoubleMatrix test) |
static boolean |
isValidOutcome(org.jblas.DoubleMatrix out) |
static org.jblas.DoubleMatrix |
log(org.jblas.DoubleMatrix vals)
A log impl that prevents numerical underflow
Any number that's infinity or NaN is replaced by
1e-6.
|
static double |
magnitude(org.jblas.DoubleMatrix vec) |
static void |
max(double minNumber,
org.jblas.DoubleMatrix matrix)
Cuts all numbers below a certain cut off
|
static double |
max(org.jblas.DoubleMatrix matrix) |
static int |
maxIndex(org.jblas.DoubleMatrix matrix) |
static org.jblas.DoubleMatrix |
mean(org.jblas.DoubleMatrix input,
int axis) |
static double |
meanSquaredError(org.jblas.DoubleMatrix input,
org.jblas.DoubleMatrix other)
Returns the mean squared error of the 2 matrices.
|
static double |
min(org.jblas.DoubleMatrix matrix) |
static org.jblas.DoubleMatrix |
normal(org.apache.commons.math3.random.RandomGenerator rng,
org.jblas.DoubleMatrix standardDeviations)
Sample from a normal distribution given a mean of zero and a matrix of standard deviations.
|
static org.jblas.DoubleMatrix |
normal(org.apache.commons.math3.random.RandomGenerator rng,
org.jblas.DoubleMatrix mean,
double sigma)
A uniform sample ranging from 0 to sigma.
|
static org.jblas.DoubleMatrix |
normal(org.apache.commons.math3.random.RandomGenerator rng,
org.jblas.DoubleMatrix mean,
org.jblas.DoubleMatrix variance)
A uniform sample ranging from 0 to sigma.
|
static org.jblas.DoubleMatrix |
normalize(org.jblas.DoubleMatrix input) |
static org.jblas.DoubleMatrix |
normalizeByColumnMeans(org.jblas.DoubleMatrix m)
Subtracts by column mean.
|
static org.jblas.DoubleMatrix |
normalizeByColumnSums(org.jblas.DoubleMatrix m) |
static org.jblas.DoubleMatrix |
normalizeByRowSums(org.jblas.DoubleMatrix m) |
static void |
normalizeMatrix(org.jblas.DoubleMatrix toNormalize) |
static org.jblas.DoubleMatrix |
oneDiv(org.jblas.DoubleMatrix ep) |
static org.jblas.DoubleMatrix |
oneMinus(org.jblas.DoubleMatrix ep) |
static org.jblas.DoubleMatrix |
out(org.jblas.DoubleMatrix a,
org.jblas.DoubleMatrix b) |
static org.jblas.DoubleMatrix |
outcomes(org.jblas.DoubleMatrix d) |
static org.jblas.DoubleMatrix |
roundToTheNearest(org.jblas.DoubleMatrix d,
int num) |
static org.jblas.DoubleMatrix |
rowStd(org.jblas.DoubleMatrix m)
Calculates the column wise standard deviations
of the matrix
|
static org.jblas.DoubleMatrix |
scalarMinus(double scalar,
org.jblas.DoubleMatrix ep) |
static void |
scaleByMax(org.jblas.DoubleMatrix toScale) |
static org.jblas.DoubleMatrix |
sigmoid(org.jblas.DoubleMatrix x) |
static double |
singlePixelConvolution(org.jblas.DoubleMatrix input,
int x,
int y,
org.jblas.DoubleMatrix k,
int kernelWidth,
int kernelHeight)
Takes an image (grey-levels) and a kernel and a position,
applies the convolution at that position and returns the
new pixel value.
|
static org.jblas.DoubleMatrix |
softmax(org.jblas.DoubleMatrix input)
Soft max function
row_maxes is a row vector (max for each row)
row_maxes = rowmaxes(input)
diff = exp(input - max) / diff.rowSums()
|
static org.jblas.DoubleMatrix |
sum(org.jblas.DoubleMatrix input,
int axis) |
static double |
sumSquaredError(org.jblas.DoubleMatrix input,
org.jblas.DoubleMatrix other)
Returns the sum squared error of the 2 matrices.
|
static org.jblas.DoubleMatrix |
toMatrix(int[] arr) |
static org.jblas.DoubleMatrix |
toMatrix(int[][] arr) |
static org.jblas.DoubleMatrix |
toOutcomeVector(int index,
int numOutcomes) |
static org.jblas.DoubleMatrix |
uniform(org.apache.commons.math3.random.RandomGenerator rng,
int rows,
int columns)
A uniform sample ranging from 0 to 1.
|
static org.jblas.DoubleMatrix |
unitVec(org.jblas.DoubleMatrix toScale) |
static org.jblas.DoubleMatrix |
unroll(org.jblas.DoubleMatrix d) |
static org.jblas.DoubleMatrix |
variance(org.jblas.DoubleMatrix input) |
static DataSet |
xorData(int n) |
static DataSet |
xorData(int n,
int columns) |
public static void complainAboutMissMatchedMatrices(org.jblas.DoubleMatrix d1, org.jblas.DoubleMatrix d2)
public static void max(double minNumber, org.jblas.DoubleMatrix matrix)
minNumber
- the min number to checkmatrix
- the matrix to max bypublic static void scaleByMax(org.jblas.DoubleMatrix toScale)
public static org.jblas.DoubleMatrix variance(org.jblas.DoubleMatrix input)
public static double singlePixelConvolution(org.jblas.DoubleMatrix input, int x, int y, org.jblas.DoubleMatrix k, int kernelWidth, int kernelHeight)
input
- The 2D double array representing the image.x
- The x coordinate for the position of the convolution.y
- The y coordinate for the position of the convolution.k
- The 2D array representing the kernel.kernelWidth
- The width of the kernel.kernelHeight
- The height of the kernel.public static org.jblas.DoubleMatrix convolution2D(org.jblas.DoubleMatrix input, int width, int height, org.jblas.DoubleMatrix kernel, int kernelWidth, int kernelHeight)
input
- the 2D double array representing the imagewidth
- the width of the imageheight
- the height of the imagekernel
- the 2D array representing the kernelkernelWidth
- the width of the kernelkernelHeight
- the height of the kernelpublic static DataSet xorData(int n)
public static DataSet xorData(int n, int columns)
public static double magnitude(org.jblas.DoubleMatrix vec)
public static org.jblas.DoubleMatrix unroll(org.jblas.DoubleMatrix d)
public static org.jblas.DoubleMatrix outcomes(org.jblas.DoubleMatrix d)
public static double cosineSim(org.jblas.DoubleMatrix d1, org.jblas.DoubleMatrix d2)
public static org.jblas.DoubleMatrix normalize(org.jblas.DoubleMatrix input)
public static double cosine(org.jblas.DoubleMatrix matrix)
public static org.jblas.DoubleMatrix unitVec(org.jblas.DoubleMatrix toScale)
public static org.jblas.DoubleMatrix uniform(org.apache.commons.math3.random.RandomGenerator rng, int rows, int columns)
rng
- the rng to userows
- the number of rows of the matrixcolumns
- the number of columns of the matrixpublic static org.jblas.DoubleMatrix normal(org.apache.commons.math3.random.RandomGenerator rng, org.jblas.DoubleMatrix mean, double sigma)
rng
- the rng to usemean,
- the matrix mean from which to generate values fromsigma
- the standard deviation to use to generate the gaussian noisepublic static org.jblas.DoubleMatrix normal(org.apache.commons.math3.random.RandomGenerator rng, org.jblas.DoubleMatrix mean, org.jblas.DoubleMatrix variance)
rng
- the rng to usemean,
- the matrix mean from which to generate values fromvariance
- the variance matrix where each column is the variance
for the respective columns of the matrixpublic static org.jblas.DoubleMatrix normal(org.apache.commons.math3.random.RandomGenerator rng, org.jblas.DoubleMatrix standardDeviations)
rng
- the rng to usestandard
- deviations, the matrix standard deviations to use
for the respective columns of the matrixpublic static boolean isValidOutcome(org.jblas.DoubleMatrix out)
public static double min(org.jblas.DoubleMatrix matrix)
public static double max(org.jblas.DoubleMatrix matrix)
public static void ensureValidOutcomeMatrix(org.jblas.DoubleMatrix out)
public static void assertIntMatrix(org.jblas.DoubleMatrix matrix)
public static boolean isInfinite(org.jblas.DoubleMatrix test)
public static boolean isNaN(org.jblas.DoubleMatrix test)
public static void discretizeColumns(org.jblas.DoubleMatrix toDiscretize, int numBins)
public static org.jblas.DoubleMatrix roundToTheNearest(org.jblas.DoubleMatrix d, int num)
public static void columnNormalizeBySum(org.jblas.DoubleMatrix x)
public static org.jblas.DoubleMatrix toOutcomeVector(int index, int numOutcomes)
public static org.jblas.DoubleMatrix toMatrix(int[][] arr)
public static org.jblas.DoubleMatrix toMatrix(int[] arr)
public static org.jblas.DoubleMatrix add(org.jblas.DoubleMatrix a, org.jblas.DoubleMatrix b)
public static org.jblas.DoubleMatrix softmax(org.jblas.DoubleMatrix input)
input
- the input for the softmaxpublic static org.jblas.DoubleMatrix mean(org.jblas.DoubleMatrix input, int axis)
public static org.jblas.DoubleMatrix sum(org.jblas.DoubleMatrix input, int axis)
public static org.jblas.DoubleMatrix binomial(org.jblas.DoubleMatrix p, int n, org.apache.commons.math3.random.RandomGenerator rng)
p
- the p matrix to usen
- the n to userng
- the rng to usepublic static org.jblas.DoubleMatrix columnWiseMean(org.jblas.DoubleMatrix x, int axis)
public static org.jblas.DoubleMatrix avg(org.jblas.DoubleMatrix... matrices)
public static int maxIndex(org.jblas.DoubleMatrix matrix)
public static org.jblas.DoubleMatrix sigmoid(org.jblas.DoubleMatrix x)
public static org.jblas.DoubleMatrix dot(org.jblas.DoubleMatrix a, org.jblas.DoubleMatrix b)
public static org.jblas.DoubleMatrix out(org.jblas.DoubleMatrix a, org.jblas.DoubleMatrix b)
public static org.jblas.DoubleMatrix scalarMinus(double scalar, org.jblas.DoubleMatrix ep)
public static org.jblas.DoubleMatrix oneMinus(org.jblas.DoubleMatrix ep)
public static org.jblas.DoubleMatrix oneDiv(org.jblas.DoubleMatrix ep)
public static org.jblas.DoubleMatrix columnStd(org.jblas.DoubleMatrix m)
m
- the matrix to usepublic static org.jblas.DoubleMatrix rowStd(org.jblas.DoubleMatrix m)
m
- the matrix to usepublic static double meanSquaredError(org.jblas.DoubleMatrix input, org.jblas.DoubleMatrix other)
IllegalArgumentException
is throwninput
- the first oneother
- the second onepublic static org.jblas.DoubleMatrix log(org.jblas.DoubleMatrix vals)
vals
- the vals to convert to logpublic static double sumSquaredError(org.jblas.DoubleMatrix input, org.jblas.DoubleMatrix other)
IllegalArgumentException
is throwninput
- the first oneother
- the second onepublic static void normalizeMatrix(org.jblas.DoubleMatrix toNormalize)
public static org.jblas.DoubleMatrix normalizeByColumnSums(org.jblas.DoubleMatrix m)
public static org.jblas.DoubleMatrix columnStdDeviation(org.jblas.DoubleMatrix m)
public static org.jblas.DoubleMatrix divColumnsByStDeviation(org.jblas.DoubleMatrix m)
m
- the matrix to dividepublic static org.jblas.DoubleMatrix normalizeByColumnMeans(org.jblas.DoubleMatrix m)
m
- the matrix to normalizepublic static org.jblas.DoubleMatrix normalizeByRowSums(org.jblas.DoubleMatrix m)
Copyright © 2014. All Rights Reserved.