public class NeuralUtils
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static SimpleMatrix |
concatenate(SimpleMatrix... vectors)
Concatenates several column vectors into one large column vector
|
static SimpleMatrix |
concatenateWithBias(SimpleMatrix... vectors)
Concatenates several column vectors into one large column
vector, adds a 1.0 at the end as a bias term
|
static SimpleMatrix |
convertTextMatrix(java.lang.String text) |
static double |
cosine(SimpleMatrix vector1,
SimpleMatrix vector2)
Compute cosine distance between two column vectors.
|
static double |
dot(SimpleMatrix vector1,
SimpleMatrix vector2)
Compute dot product between two vectors.
|
static SimpleMatrix |
elementwiseApplyLog(SimpleMatrix input)
Applies log to each of the entries in the matrix.
|
static SimpleMatrix |
elementwiseApplyReLU(SimpleMatrix input)
Applies ReLU to each of the entries in the matrix.
|
static SimpleMatrix |
elementwiseApplyTanh(SimpleMatrix input)
Applies tanh to each of the entries in the matrix.
|
static SimpleMatrix |
elementwiseApplyTanhDerivative(SimpleMatrix input)
Applies the derivative of tanh to each of the elements in the vector.
|
static boolean |
isZero(SimpleMatrix matrix)
Returns true iff every element of matrix is 0
|
static java.util.List<SimpleMatrix> |
loadTextMatrices(java.lang.String path)
Convert a file into a list of matrices.
|
static SimpleMatrix |
loadTextMatrix(java.io.File file)
Convert a file into a text matrix.
|
static SimpleMatrix |
loadTextMatrix(java.lang.String path)
Convert a file into a text matrix.
|
static SimpleMatrix |
oneHot(int index,
int size) |
static double[] |
paramsToVector(double scale,
int totalSize,
java.util.Iterator<SimpleMatrix>... matrices)
Given a sequence of iterators over the matrices, builds a vector
out of those matrices in the order given.
|
static double[] |
paramsToVector(int totalSize,
java.util.Iterator<SimpleMatrix>... matrices)
Given a sequence of iterators over the matrices, builds a vector
out of those matrices in the order given.
|
static SimpleMatrix |
randomGaussian(int numRows,
int numCols,
java.util.Random rand)
Returns a vector with random Gaussian values, mean 0, std 1
|
static double |
sigmoid(double x)
Returns a sigmoid applied to the input
x . |
static SimpleMatrix |
softmax(SimpleMatrix input)
Applies softmax to all of the elements of the matrix.
|
static java.lang.String |
toString(SimpleMatrix matrix,
java.lang.String format) |
static void |
vectorToParams(double[] theta,
java.util.Iterator<SimpleMatrix>... matrices)
Given a sequence of Iterators over SimpleMatrix, fill in all of
the matrices with the entries in the theta vector.
|
public static SimpleMatrix loadTextMatrix(java.lang.String path)
public static SimpleMatrix loadTextMatrix(java.io.File file)
public static java.util.List<SimpleMatrix> loadTextMatrices(java.lang.String path)
public static SimpleMatrix convertTextMatrix(java.lang.String text)
public static java.lang.String toString(SimpleMatrix matrix, java.lang.String format)
matrix
- The matrix to return as a Stringformat
- The format to use for each value in the matrix, eg "%f"public static double cosine(SimpleMatrix vector1, SimpleMatrix vector2)
public static double dot(SimpleMatrix vector1, SimpleMatrix vector2)
@SafeVarargs public static void vectorToParams(double[] theta, java.util.Iterator<SimpleMatrix>... matrices)
@SafeVarargs public static double[] paramsToVector(int totalSize, java.util.Iterator<SimpleMatrix>... matrices)
@SafeVarargs public static double[] paramsToVector(double scale, int totalSize, java.util.Iterator<SimpleMatrix>... matrices)
scale
parameter. Asks for an
expected total size as a time savings. AssertionError thrown if
the vector sizes do not exactly match.public static double sigmoid(double x)
x
.public static SimpleMatrix softmax(SimpleMatrix input)
public static SimpleMatrix elementwiseApplyReLU(SimpleMatrix input)
public static SimpleMatrix elementwiseApplyLog(SimpleMatrix input)
public static SimpleMatrix elementwiseApplyTanh(SimpleMatrix input)
public static SimpleMatrix elementwiseApplyTanhDerivative(SimpleMatrix input)
public static SimpleMatrix concatenateWithBias(SimpleMatrix... vectors)
public static SimpleMatrix concatenate(SimpleMatrix... vectors)
public static SimpleMatrix randomGaussian(int numRows, int numCols, java.util.Random rand)
public static SimpleMatrix oneHot(int index, int size)
public static boolean isZero(SimpleMatrix matrix)