public abstract class Layer
extends java.lang.Object
implements java.io.Serializable
| Modifier and Type | Field and Description |
|---|---|
protected double[] |
bias
The bias.
|
protected java.lang.ThreadLocal<double[]> |
biasGradient
The bias gradient.
|
protected java.lang.ThreadLocal<double[]> |
biasUpdate
The bias update.
|
protected int |
n
The number of neurons in this layer
|
protected java.lang.ThreadLocal<double[]> |
output
The output vector.
|
protected java.lang.ThreadLocal<double[]> |
outputGradient
The output gradient.
|
protected int |
p
The number of input variables.
|
protected java.lang.ThreadLocal<double[]> |
rmsBiasGradient
The accumulate bias gradient.
|
protected java.lang.ThreadLocal<smile.math.matrix.Matrix> |
rmsWeightGradient
The accumulate weight gradient.
|
protected smile.math.matrix.Matrix |
weight
The affine transformation matrix.
|
protected java.lang.ThreadLocal<smile.math.matrix.Matrix> |
weightGradient
The weight gradient.
|
protected java.lang.ThreadLocal<smile.math.matrix.Matrix> |
weightUpdate
The weight update.
|
| Constructor and Description |
|---|
Layer(int n,
int p)
Constructor.
|
Layer(smile.math.matrix.Matrix weight,
double[] bias)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
abstract void |
backpropagate(double[] lowerLayerGradient)
Propagates the errors back to a lower layer.
|
void |
computeGradient(double[] x)
Computes the parameter gradient for a sample of (mini-)batch.
|
void |
computeGradientUpdate(double[] x,
double learningRate,
double momentum,
double decay)
Computes the parameter gradient and update the weights.
|
abstract void |
f(double[] x)
The activation or output function.
|
int |
getInputSize()
Returns the dimension of input vector (not including bias value).
|
int |
getOutputSize()
Returns the dimension of output vector.
|
double[] |
gradient()
Returns the output gradient vector.
|
static HiddenLayerBuilder |
linear(int n)
Returns a hidden layer with linear activation function.
|
static OutputLayerBuilder |
mle(int n,
OutputFunction f)
Returns an output layer with (log-)likelihood cost function.
|
static OutputLayerBuilder |
mse(int n,
OutputFunction f)
Returns an output layer with mean squared error cost function.
|
double[] |
output()
Returns the output vector.
|
void |
propagate(double[] x)
Propagates signals from a lower layer to this layer.
|
static HiddenLayerBuilder |
rectifier(int n)
Returns a hidden layer with rectified linear activation function.
|
static HiddenLayerBuilder |
sigmoid(int n)
Returns a hidden layer with sigmoid activation function.
|
static HiddenLayerBuilder |
tanh(int n)
Returns a hidden layer with hyperbolic tangent activation function.
|
void |
update(int m,
double learningRate,
double momentum,
double decay,
double rho,
double epsilon)
Adjust network weights by back-propagation algorithm.
|
protected int n
protected int p
protected smile.math.matrix.Matrix weight
protected double[] bias
protected transient java.lang.ThreadLocal<double[]> output
protected transient java.lang.ThreadLocal<double[]> outputGradient
protected transient java.lang.ThreadLocal<smile.math.matrix.Matrix> weightGradient
protected transient java.lang.ThreadLocal<double[]> biasGradient
protected transient java.lang.ThreadLocal<smile.math.matrix.Matrix> rmsWeightGradient
protected transient java.lang.ThreadLocal<double[]> rmsBiasGradient
protected transient java.lang.ThreadLocal<smile.math.matrix.Matrix> weightUpdate
protected transient java.lang.ThreadLocal<double[]> biasUpdate
public Layer(int n,
int p)
n - the number of neurons.p - the number of input variables (not including bias value).public Layer(smile.math.matrix.Matrix weight,
double[] bias)
weight - the weight matrix.bias - the bias vector.public int getOutputSize()
public int getInputSize()
public double[] output()
public double[] gradient()
public void propagate(double[] x)
x - the lower layer signals.public abstract void f(double[] x)
x - the input and output values.public abstract void backpropagate(double[] lowerLayerGradient)
lowerLayerGradient - the gradient vector of lower layer.public void computeGradientUpdate(double[] x,
double learningRate,
double momentum,
double decay)
x - the input vector.learningRate - the learning rate.momentum - the momentum factordecay - weight decay factorpublic void computeGradient(double[] x)
x - the input vector.public void update(int m,
double learningRate,
double momentum,
double decay,
double rho,
double epsilon)
m - the size of mini-batch.learningRate - the learning rate.momentum - the momentum factordecay - weight decay factorpublic static HiddenLayerBuilder linear(int n)
n - the number of neurons.public static HiddenLayerBuilder rectifier(int n)
n - the number of neurons.public static HiddenLayerBuilder sigmoid(int n)
n - the number of neurons.public static HiddenLayerBuilder tanh(int n)
n - the number of neurons.public static OutputLayerBuilder mse(int n, OutputFunction f)
n - the number of neurons.f - the output function.public static OutputLayerBuilder mle(int n, OutputFunction f)
n - the number of neurons.f - the output function.