Package de.jungblut.classification.nn
Class MultilayerPerceptron
- java.lang.Object
-
- de.jungblut.classification.AbstractPredictor
-
- de.jungblut.classification.AbstractClassifier
-
- de.jungblut.classification.nn.MultilayerPerceptron
-
- All Implemented Interfaces:
Classifier,Predictor
public final class MultilayerPerceptron extends AbstractClassifier
Multilayer perceptron implementation that works on GPU via JCuda and CPU. It features l0/1 regularization (lambda) and dropout. A wide variety of activation functions and error functions can be configured. You can set this network up by using the builder given byMultilayerPerceptron.MultilayerPerceptron.MultilayerPerceptronBuilder.- Author:
- thomas.jungblut
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMultilayerPerceptron.MultilayerPerceptronBuilderConfiguration for training a neural net through theClassifier
-
Field Summary
Fields Modifier and Type Field Description static longSEED
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static MultilayerPerceptrondeserialize(java.io.DataInput in)Deserializes a new neural network from the given input stream.ActivationFunction[]getActivations()de.jungblut.math.DoubleVectorgetFoldedThetaVector()int[]getLayers()WeightMatrix[]getWeights()de.jungblut.math.DoubleVectorpredict(de.jungblut.math.DoubleVector xi)Predicts the outcome of the given input by doing a forward pass.de.jungblut.math.DoubleVectorpredict(de.jungblut.math.DoubleVector xi, double threshold)Predicts the outcome of the given input by doing a forward pass.static voidserialize(MultilayerPerceptron model, java.io.DataOutput out)Serializes this network at its current state to a binary file.voidtrain(de.jungblut.math.DoubleVector[] features, de.jungblut.math.DoubleVector[] outcome)Trains this classifier with the given features and the outcome.doubletrain(de.jungblut.math.DoubleVector[] features, de.jungblut.math.DoubleVector[] outcome, Minimizer minimizer, int maxIterations, double lambda, boolean verbose)Full backpropagation training method.-
Methods inherited from class de.jungblut.classification.AbstractClassifier
train
-
Methods inherited from class de.jungblut.classification.AbstractPredictor
extractPredictedClass, extractPredictedClass, predictedClass, predictedClass, predictProbability
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface de.jungblut.classification.Predictor
asClassifier, extractPredictedClass, extractPredictedClass, predictedClass, predictedClass, predictProbability
-
-
-
-
Method Detail
-
predict
public de.jungblut.math.DoubleVector predict(de.jungblut.math.DoubleVector xi)
Predicts the outcome of the given input by doing a forward pass.- Returns:
- the vector that contains an indicator at the index of the class. Usually zero or 1, in some cases it is a probability or activation value.
-
predict
public de.jungblut.math.DoubleVector predict(de.jungblut.math.DoubleVector xi, double threshold)Predicts the outcome of the given input by doing a forward pass. Used for binary classification by a threshold. Everything above threshold will be considered as 1, the other case as 0.
-
train
public void train(de.jungblut.math.DoubleVector[] features, de.jungblut.math.DoubleVector[] outcome)Description copied from interface:ClassifierTrains this classifier with the given features and the outcome.- Specified by:
trainin interfaceClassifier- Overrides:
trainin classAbstractClassifieroutcome- the outcome must have classes labeled as doubles. E.G. in the binary case you have a single element and decide between 0d and 1d. In higher dimensional cases you have each of these single elements mapped to a dimension.
-
train
public final double train(de.jungblut.math.DoubleVector[] features, de.jungblut.math.DoubleVector[] outcome, Minimizer minimizer, int maxIterations, double lambda, boolean verbose)Full backpropagation training method. It performs weight finding by using a minimizer. Note that it only guarantees to find a global minimum solution in case of linear or convex problems (zero / one hidden layer), of course this is also dependend on the concrete minimizer implementation. If you have more than a single hidden layer, then it will usually trap into a local minimum. It supplies a vector so training can be resumed from a good starting point.- Parameters:
features- the training examples.outcome- the outcomes for the training examples.minimizer- the minimizer to use to train the neural network.maxIterations- the number of maximum iterations to train.lambda- the given regularization parameter.verbose- output to console with the last given errors.theta- initial spot to start the minimizations.- Returns:
- the cost of the training.
-
getFoldedThetaVector
public de.jungblut.math.DoubleVector getFoldedThetaVector()
- Returns:
- the folded theta vector, seeded by the current weight matrices.
-
getWeights
public WeightMatrix[] getWeights()
-
getLayers
public int[] getLayers()
-
getActivations
public ActivationFunction[] getActivations()
-
deserialize
public static MultilayerPerceptron deserialize(java.io.DataInput in) throws java.io.IOException
Deserializes a new neural network from the given input stream. Note that "in" will not be closed by this method.- Throws:
java.io.IOException
-
serialize
public static void serialize(MultilayerPerceptron model, java.io.DataOutput out) throws java.io.IOException
Serializes this network at its current state to a binary file. Note that "out" will not be closed in this method.- Throws:
java.io.IOException
-
-