Package de.jungblut.classification.nn
Class RBM
- java.lang.Object
-
- de.jungblut.classification.nn.RBM
-
public final class RBM extends java.lang.ObjectClass for training and stacking Restricted Boltzmann Machines (RBMs). Stacked RBMs are called DBN (deep belief net). Usually every layer of a deep belief net is training greedily with the contrastive divergence algorithm implemented inRBMCostFunction. Create new instances with theRBM.RBMBuilderor with the static factory methods.- Author:
- thomas.jungblut
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classRBM.RBMBuilder
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static RBMdeserialize(java.io.DataInputStream in)Deserializes the RBM back from the binary stream input.WeightMatrix[]getNeuralNetworkWeights(int outputLayerSize)Creates a weight matrix that can be used for unsupervised weight initialization in theMultilayerPerceptron.de.jungblut.math.DoubleMatrix[]getWeights()de.jungblut.math.DoubleVectorpredict(de.jungblut.math.DoubleVector input)Returns the hidden activations of the last RBM.de.jungblut.math.DoubleVectorreconstructInput(de.jungblut.math.DoubleVector hiddenActivations)Creates a reconstruction of the input using the given hidden activations.static voidserialize(RBM model, java.io.DataOutput out)Serializes this RBM model into the given output stream.voidsetSeed(long seed)Sets the internally used rng seed.static RBMsingle(int numHiddenNodes)static RBMsingle(int numHiddenNodes, ActivationFunction func)static RBMsingleGPU(int numHiddenNodes, ActivationFunction func)static RBMstacked(int... numHiddenNodes)Creates a new stacked RBM with sigmoid activation and with the given number of hidden nodes in each stacked layer.static RBMstacked(ActivationFunction func, int... numHiddenNodes)Creates a new stacked RBM with sigmoid activation and with the given number of hidden nodes in each stacked layer.static RBMstackedGPU(ActivationFunction func, int... numHiddenNodes)Creates a new stacked RBM with sigmoid activation and with the given number of hidden nodes in each stacked layer.voidtrain(de.jungblut.math.DoubleVector[] trainingSet, double alpha, int numIterations)Trains the RBM on the given training set.voidtrain(de.jungblut.math.DoubleVector[] trainingSet, Minimizer minimizer, int numIterations)Trains the RBM on the given training set.
-
-
-
Method Detail
-
train
public void train(de.jungblut.math.DoubleVector[] trainingSet, double alpha, int numIterations)Trains the RBM on the given training set.- Parameters:
trainingSet- the training set to train on.alpha- the learning rate for gradient descent.numIterations- how many iterations of training have to be done. (if converged before, it will stop training)
-
train
public void train(de.jungblut.math.DoubleVector[] trainingSet, Minimizer minimizer, int numIterations)Trains the RBM on the given training set.- Parameters:
trainingSet- the training set to train on.minimizer- the minimizer to use. Note that the costfunction's gradient isn't the real gradient and thus can't be optimized by line searching minimizers likeFmincg.numIterations- how many iterations of training have to be done. (if converged before, it will stop training)
-
predict
public de.jungblut.math.DoubleVector predict(de.jungblut.math.DoubleVector input)
Returns the hidden activations of the last RBM.- Parameters:
input- the input of the first RBM.- Returns:
- a vector that contains the values of the hidden activations on the last layer.
-
reconstructInput
public de.jungblut.math.DoubleVector reconstructInput(de.jungblut.math.DoubleVector hiddenActivations)
Creates a reconstruction of the input using the given hidden activations. (That, what is returned bypredict(DoubleVector)).- Parameters:
hiddenActivations- the activations of the predict method.- Returns:
- the reconstructed input vector.
-
getWeights
public de.jungblut.math.DoubleMatrix[] getWeights()
- Returns:
- the weight matrices.
-
getNeuralNetworkWeights
public WeightMatrix[] getNeuralNetworkWeights(int outputLayerSize)
Creates a weight matrix that can be used for unsupervised weight initialization in theMultilayerPerceptron.- Parameters:
outputLayerSize- the size of the classification layer on top of this RBM.- Returns:
- the
WeightMatrixthat maps layers to the weights.
-
setSeed
public void setSeed(long seed)
Sets the internally used rng seed.
-
serialize
public static void serialize(RBM model, java.io.DataOutput out) throws java.io.IOException
Serializes this RBM model into the given output stream.- Throws:
java.io.IOException
-
deserialize
public static RBM deserialize(java.io.DataInputStream in) throws java.io.IOException
Deserializes the RBM back from the binary stream input.- Throws:
java.io.IOException
-
single
public static RBM single(int numHiddenNodes, ActivationFunction func)
- Returns:
- a single RBM which isn't stacked and emits to the given number of hidden nodes.
-
stacked
public static RBM stacked(ActivationFunction func, int... numHiddenNodes)
Creates a new stacked RBM with sigmoid activation and with the given number of hidden nodes in each stacked layer. For example: 4,3,2 will create the first RBM with 4 hidden nodes, the second layer will operate on the 4 hidden node outputs of the RBM before and emit to 3 hidden nodes. Similarly the last layer will receive three inputs and emit 2 output's, which state you receive in the predict method.
-
single
public static RBM single(int numHiddenNodes)
- Returns:
- a single RBM with sigmoid activation which isn't stacked and emits to the given number of hidden nodes.
-
stacked
public static RBM stacked(int... numHiddenNodes)
Creates a new stacked RBM with sigmoid activation and with the given number of hidden nodes in each stacked layer. For example: 4,3,2 will create the first RBM with 4 hidden nodes, the second layer will operate on the 4 hidden node outputs of the RBM before and emit to 3 hidden nodes. Similarly the last layer will receive three inputs and emit 2 output's, which state you receive in the predict method.
-
singleGPU
public static RBM singleGPU(int numHiddenNodes, ActivationFunction func)
- Returns:
- a single RBM which isn't stacked and emits to the given number of hidden nodes.
-
stackedGPU
public static RBM stackedGPU(ActivationFunction func, int... numHiddenNodes)
Creates a new stacked RBM with sigmoid activation and with the given number of hidden nodes in each stacked layer. For example: 4,3,2 will create the first RBM with 4 hidden nodes, the second layer will operate on the 4 hidden node outputs of the RBM before and emit to 3 hidden nodes. Similarly the last layer will receive three inputs and emit 2 output's, which state you receive in the predict method.
-
-