jsat.classifiers.neuralnetwork
Class BackPropagationNet
- java.lang.Object
-
- jsat.classifiers.neuralnetwork.BackPropagationNet
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, Classifier, Parameterized, Regressor
public class BackPropagationNet extends java.lang.Object implements Classifier, Regressor, Parameterized
An implementation of a Feed Forward Neural Network (NN) trained by Back Propagation. NNs are powerful classifiers and regressors, but can suffer from slow training time and overfitting.
NOTE: This class should generally not be used any more. TheDReDNetSimpleprovides an easier to use class for most cases that will likely converge faster.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static classBackPropagationNet.ActivationFunctionThe neural network needs an activation function for the neurons that is used to predict from inputs and train the network by propagating the errors back through the network.static classBackPropagationNet.WeightInitializationDifferent methods of initializing the weight values before training
-
Field Summary
Fields Modifier and Type Field and Description static BackPropagationNet.ActivationFunctionlogitActivThe logit activation function.static BackPropagationNet.ActivationFunctionsoftsignActivThe softsign activation function.static BackPropagationNet.ActivationFunctiontanhActivThe tanh activation function.
-
Constructor Summary
Constructors Constructor and Description BackPropagationNet()Creates a new back propagation network with one hidden layer of 1024 neurons.BackPropagationNet(int... npl)Creates a new back propagation network.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description CategoricalResultsclassify(DataPoint data)Performs classification on the given data point.BackPropagationNetclone()BackPropagationNet.ActivationFunctiongetActivationFunction()Returns the activation function used for training the networkintgetBatchSize()Returns the training batch sizeintgetEpochs()Returns the number of epochs of training epochs for learningdoublegetInitialLearningRate()Returns the learning rate usedDecayRategetLearningRateDecay()Returns the decay rate used to adjust the learning rate after each epochdoublegetMomentum()Returns the momentum in useParametergetParameter(java.lang.String paramName)Returns the parameter with the given name.java.util.List<Parameter>getParameters()Returns the list of parameters that can be altered for this learner.doublegetWeightDecay()Returns the weight decay used for each updateBackPropagationNet.WeightInitializationgetWeightInitialization()Returns the method of weight initialization useddoubleregress(DataPoint data)voidsetActivationFunction(BackPropagationNet.ActivationFunction f)Sets the activation function used for the networkvoidsetBatchSize(int batchSize)Sets the batch size use to estimate the gradient of the error for trainingvoidsetEpochs(int epochs)Sets the number of epochs of training used.voidsetInitialLearningRate(double initialLearningRate)Sets the initial learning rate used for the first epochvoidsetLearningRateDecay(DecayRate learningRateDecay)Sets the decay rate used to adjust the learning rate after each epochvoidsetMomentum(double momentum)Sets the non negative momentum used in training.voidsetWeightDecay(double weightDecay)Sets the weight decay used for each update.voidsetWeightInitialization(BackPropagationNet.WeightInitialization weightInitialization)Sets how the weights are initialized before training startsbooleansupportsWeightedData()Indicates whether the model knows how to train using weighted data points.voidtrain(ClassificationDataSet dataSet)Trains the classifier and constructs a model for classification using the given data set.voidtrain(ClassificationDataSet dataSet, boolean parallel)Trains the classifier and constructs a model for classification using the given data set.voidtrain(RegressionDataSet dataSet)voidtrain(RegressionDataSet dataSet, boolean parallel)
-
-
-
Field Detail
-
logitActiv
public static final BackPropagationNet.ActivationFunction logitActiv
The logit activation function. This function goes from [0, 1]. It has more difficultly learning than symmetric activation functions, often requiring considerably more layers and neurons than other activation functions.
-
tanhActiv
public static final BackPropagationNet.ActivationFunction tanhActiv
The tanh activation function. This function is symmetric in the range of [-1, 1]. It works well for many problems in general.
-
softsignActiv
public static final BackPropagationNet.ActivationFunction softsignActiv
The softsign activation function. This function is symmetric in the range of [-1, 1]. It works well for classification problems, and is very fast to compute. It sometimes requires more neurons to learn more complicated functions / boundaries. It sometimes has reduced performance in regression
-
-
Constructor Detail
-
BackPropagationNet
public BackPropagationNet()
Creates a new back propagation network with one hidden layer of 1024 neurons.- Parameters:
npl- the array of hidden layer information. The length indicates how many hidden layers, and the value of each index indicates how many neurons to place in each hidden layer
-
BackPropagationNet
public BackPropagationNet(int... npl)
Creates a new back propagation network.- Parameters:
npl- the array of hidden layer information. The length indicates how many hidden layers, and the value of each index indicates how many neurons to place in each hidden layer
-
-
Method Detail
-
setMomentum
public void setMomentum(double momentum)
Sets the non negative momentum used in training.- Parameters:
momentum- the momentum to apply to training
-
getMomentum
public double getMomentum()
Returns the momentum in use- Returns:
- the momentum
-
setInitialLearningRate
public void setInitialLearningRate(double initialLearningRate)
Sets the initial learning rate used for the first epoch- Parameters:
initialLearningRate- the positive learning rate to use
-
getInitialLearningRate
public double getInitialLearningRate()
Returns the learning rate used- Returns:
- the learning rate used
-
setLearningRateDecay
public void setLearningRateDecay(DecayRate learningRateDecay)
Sets the decay rate used to adjust the learning rate after each epoch- Parameters:
learningRateDecay- the decay for the learning rate
-
getLearningRateDecay
public DecayRate getLearningRateDecay()
Returns the decay rate used to adjust the learning rate after each epoch- Returns:
- the decay rate used for learning
-
setEpochs
public void setEpochs(int epochs)
Sets the number of epochs of training used. Each epoch goes through the whole data set once.- Parameters:
epochs- the number of training epochs
-
getEpochs
public int getEpochs()
Returns the number of epochs of training epochs for learning- Returns:
- the number of training epochs
-
setWeightDecay
public void setWeightDecay(double weightDecay)
Sets the weight decay used for each update. The weight decay must be in the range [0, 1). Weight decay values must often be very small, often 1e-8 or less.- Parameters:
weightDecay- the weight decay to apply when training
-
getWeightDecay
public double getWeightDecay()
Returns the weight decay used for each update- Returns:
- the weight decay used.
-
setWeightInitialization
public void setWeightInitialization(BackPropagationNet.WeightInitialization weightInitialization)
Sets how the weights are initialized before training starts- Parameters:
weightInitialization- the method of weight initialization
-
getWeightInitialization
public BackPropagationNet.WeightInitialization getWeightInitialization()
Returns the method of weight initialization used- Returns:
- the method of weight initialization used
-
setBatchSize
public void setBatchSize(int batchSize)
Sets the batch size use to estimate the gradient of the error for training- Parameters:
batchSize- the number of training instances to use on each update
-
getBatchSize
public int getBatchSize()
Returns the training batch size- Returns:
- the batch size used for training
-
setActivationFunction
public void setActivationFunction(BackPropagationNet.ActivationFunction f)
Sets the activation function used for the network- Parameters:
f- the activation function to use
-
getActivationFunction
public BackPropagationNet.ActivationFunction getActivationFunction()
Returns the activation function used for training the network- Returns:
- the activation function in use
-
classify
public CategoricalResults classify(DataPoint data)
Description copied from interface:ClassifierPerforms classification on the given data point.- Specified by:
classifyin interfaceClassifier- Parameters:
data- the data point to classify- Returns:
- the results of the classification.
-
train
public void train(ClassificationDataSet dataSet, boolean parallel)
Description copied from interface:ClassifierTrains the classifier and constructs a model for classification using the given data set. If the training method knows how, it will used the threadPool to conduct training in parallel. This method will block until the training has completed.- Specified by:
trainin interfaceClassifier- Parameters:
dataSet- the data set to train onparallel-trueif multiple threads should be used to train the model.falseif it should be done in a single threaded manner.
-
train
public void train(ClassificationDataSet dataSet)
Description copied from interface:ClassifierTrains the classifier and constructs a model for classification using the given data set.- Specified by:
trainin interfaceClassifier- Parameters:
dataSet- the data set to train on
-
train
public void train(RegressionDataSet dataSet, boolean parallel)
-
train
public void train(RegressionDataSet dataSet)
-
supportsWeightedData
public boolean supportsWeightedData()
Description copied from interface:ClassifierIndicates whether the model knows how to train using weighted data points. If it does, the model will train assuming the weights. The values returned by this method may change depending on the parameters set for the model.- Specified by:
supportsWeightedDatain interfaceClassifier- Specified by:
supportsWeightedDatain interfaceRegressor- Returns:
- true if the model supports weighted data, false otherwise
-
clone
public BackPropagationNet clone()
- Specified by:
clonein interfaceClassifier- Specified by:
clonein interfaceRegressor- Overrides:
clonein classjava.lang.Object
-
getParameters
public java.util.List<Parameter> getParameters()
Description copied from interface:ParameterizedReturns the list of parameters that can be altered for this learner.- Specified by:
getParametersin interfaceParameterized- Returns:
- the list of parameters that can be altered for this learner.
-
getParameter
public Parameter getParameter(java.lang.String paramName)
Description copied from interface:ParameterizedReturns the parameter with the given name. Two different strings may map to a single Parameter object. An ASCII only string, and a Unicode style string.- Specified by:
getParameterin interfaceParameterized- Parameters:
paramName- the name of the parameter to obtain- Returns:
- the Parameter in question, or null if no such named Parameter exists.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG