jsat.classifiers.neuralnetwork
Class RBFNet
- java.lang.Object
-
- jsat.classifiers.neuralnetwork.RBFNet
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, Classifier, DataTransform, Parameterized, Regressor
public class RBFNet extends java.lang.Object implements Classifier, Regressor, DataTransform, Parameterized
This provides a highly configurable implementation of a Radial Basis Function Neural Network. A RBF network is a type of neural network that contains one hidden layer, and is related to theLVQalgorithm. In a classical RBF Network, the distance between two data points is generally theEuclideanDistanceorMahalanobisDistance. This implementation allows the specification of any arbitrary distance metric.
Another restriction on classical RBF Nets is that a weighted sum of the output of the hidden units be used to make the final decision. Instead this implementation allows the specification of an arbitrary Classifier or Regressor to estimate the outputs based on the hidden unit activations. Whether or not the predictor supports Classification, Regression, and what classification features it supports - will determine what the RBF Network supports. This allows for models technically more complicated and powerful than the standard RBF network.
The initial phases of a RBF Network is to learn the neuron locations and activations. This part can also be seen as learning a data transformation. As such, the RBF Network can be used as a DataTransform itself.
The last phase of the network is to learn the model based on the data point activations.
It is highly recommended to use a base learning method that can efficiently use sparse vectors.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static classRBFNet.Phase1LearnerThe first phase of learning a RBF Neural Network is to determine the neuron locations.static classRBFNet.Phase2LearnerThe second phase of learning a RBF Neural Network is to determine how the neurons are activated to produce the output of the hidden layer.
-
Constructor Summary
Constructors Constructor and Description RBFNet()Creates a new RBF Network suitable for binary classification or regression and uses 100 hidden nodes.RBFNet(int numCentroids)Creates a new RBF Network suitable for binary classification or regression.RBFNet(int numCentroids, RBFNet.Phase1Learner cl, RBFNet.Phase2Learner bl, double alpha, int p, DistanceMetric dm, Classifier baseClassifier)Creates a new RBF Network for classification tasks.RBFNet(int numCentroids, RBFNet.Phase1Learner cl, RBFNet.Phase2Learner bl, double alpha, int p, DistanceMetric dm, Regressor baseRegressor)Creates a new RBF Network for regression tasks.RBFNet(RBFNet toCopy)Copy constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description CategoricalResultsclassify(DataPoint data)Performs classification on the given data point.RBFNetclone()voidfit(DataSet data)Fits this transform to the given dataset.doublegetAlpha()Returns the alpha bandwidth learning parameterDistanceMetricgetDistanceMetric()Returns the distance metric in useintgetNumCentroids()Returns the number of centroids to use when trainingintgetP()Returns the nearest neighbors parameter.RBFNet.Phase1LearnergetPhase1Learner()Returns the method to use for learning the centroids of the network.RBFNet.Phase2LearnergetPhase2Learner()Returns the learning method to use for determining the bandwidths of each center in the network.static DistributionguessAlpha(DataSet data)Guesses the distribution for thesetAlpha(double)parameterstatic DistributionguessNumCentroids(DataSet data)Guesses the distribution for thesetNumCentroids(int)parameterstatic DistributionguessP(DataSet data)Guesses the distribution for thesetP(int)parameterbooleanisNormalize()Returns whether or not the network is currently normalizing its neuron outputs.doubleregress(DataPoint data)voidsetAlpha(double alpha)Sets the alpha parameter.voidsetDistanceMetric(DistanceMetric dm)Sets the distance metric used to determine neuron activations.voidsetNormalize(boolean normalize)Sets whether or not to normalize the outputs of the neurons in the network so that the activations sum to one.voidsetNumCentroids(int numCentroids)Sets the number of centroids to learn for this model.voidsetP(int p)Sets the nearest neighbor parameter.voidsetPhase1Learner(RBFNet.Phase1Learner p1l)Sets the method used for learning the centroids (or hidden units) of the network.voidsetPhase2Learner(RBFNet.Phase2Learner p2l)Sets the method used for learning the bandwidths for each centroid in the network.booleansupportsWeightedData()Indicates whether the model knows how to train using weighted data points.voidtrain(ClassificationDataSet dataSet, boolean parallel)Trains the classifier and constructs a model for classification using the given data set.voidtrain(RegressionDataSet dataSet, boolean parallel)DataPointtransform(DataPoint dp)Returns a new data point that is a transformation of the original data point.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jsat.classifiers.Classifier
train
-
Methods inherited from interface jsat.parameters.Parameterized
getParameter, getParameters
-
-
-
-
Constructor Detail
-
RBFNet
public RBFNet()
Creates a new RBF Network suitable for binary classification or regression and uses 100 hidden nodes. One of the other constructors should be used if you need classification for multi-class or if you need probability outputs.
This will useRBFNet.Phase1Learner.K_MEANSfor neuron selection andRBFNet.Phase2Learner.NEAREST_OTHER_CENTROID_AVERAGEfor activation tuning. TheEuclideanDistancewill be use as the metric.
-
RBFNet
public RBFNet(int numCentroids)
Creates a new RBF Network suitable for binary classification or regression. One of the other constructors should be used if you need classification for multi-class or if you need probability outputs.
This will useRBFNet.Phase1Learner.K_MEANSfor neuron selection andRBFNet.Phase2Learner.NEAREST_OTHER_CENTROID_AVERAGEfor activation tuning. TheEuclideanDistancewill be use as the metric.- Parameters:
numCentroids- the number of centroids or neurons to use in the network's hidden layer
-
RBFNet
public RBFNet(int numCentroids, RBFNet.Phase1Learner cl, RBFNet.Phase2Learner bl, double alpha, int p, DistanceMetric dm, Classifier baseClassifier)Creates a new RBF Network for classification tasks. If the classifier can also perform regression, then the network will be able to perform both.- Parameters:
numCentroids- the number of centroids or neurons to use in the network's hidden layercl- the method to learn the neuron locationsbl- the method to learn the neuron activationsalpha- a parameter that may have an effect on the neuron activation learning method.p- a parameter that may have an effect on the neuron activation learning methoddm- the distance metric to usebaseClassifier- the base classifier to learn on top of the hidden layer activations.
-
RBFNet
public RBFNet(int numCentroids, RBFNet.Phase1Learner cl, RBFNet.Phase2Learner bl, double alpha, int p, DistanceMetric dm, Regressor baseRegressor)Creates a new RBF Network for regression tasks. If the regressor can also perform classification, then the network will be able to perform both.- Parameters:
numCentroids- the number of centroids or neurons to use in the network's hidden layercl- the method to learn the neuron locationsbl- the method to learn the neuron activationsalpha- a parameter that may have an effect on the neuron activation learning method.p- a parameter that may have an effect on the neuron activation learning methoddm- the distance metric to usebaseRegressor- the base regressor to learn on op of the hidden layer activations.
-
RBFNet
public RBFNet(RBFNet toCopy)
Copy constructor- Parameters:
toCopy- the network to copy
-
-
Method Detail
-
transform
public DataPoint transform(DataPoint dp)
Description copied from interface:DataTransformReturns a new data point that is a transformation of the original data point. This new data point is a different object, but may contain the same references as the original data point. It is not guaranteed that you can mutate the transformed point without having a side effect on the original point.- Specified by:
transformin interfaceDataTransform- Parameters:
dp- the data point to apply a transformation to- Returns:
- a transformed data point
-
setAlpha
public void setAlpha(double alpha)
Sets the alpha parameter. This value is used for certainRBFNet.Phase2Learnerlearners as a parameter. A good default value for most methods is often 1 or 3. However the parameter must always be a non-negative value.- Parameters:
alpha- a non negative value that controls the width of the learned bandwidths.
-
getAlpha
public double getAlpha()
Returns the alpha bandwidth learning parameter- Returns:
- the alpha bandwidth learning parameter
- See Also:
setAlpha(double)
-
guessAlpha
public static Distribution guessAlpha(DataSet data)
Guesses the distribution for thesetAlpha(double)parameter- Parameters:
data- the data to create a guess for- Returns:
- a guess for the distribution of the Alpha parameter
-
setP
public void setP(int p)
Sets the nearest neighbor parameter. This value is used for certainRBFNet.Phase2Learnerlearners as a parameter. It is used to control the number of neighbors taken into account in learning the parameter value. It must always be a positive value. 3 is usually a good value for this parameter.- Parameters:
p- the positive integer used that controls the width of the learned bandwidths
-
getP
public int getP()
Returns the nearest neighbors parameter.- Returns:
- the nearest neighbors parameter.
- See Also:
setP(int)
-
guessP
public static Distribution guessP(DataSet data)
Guesses the distribution for thesetP(int)parameter- Parameters:
data- the data to create a guess for- Returns:
- a guess for the distribution of the P parameter
-
setNumCentroids
public void setNumCentroids(int numCentroids)
Sets the number of centroids to learn for this model. Increasing the number of centroids increases the complexity of the model as well as training and evaluation time. The centroids serve as the hidden units in the network.
The centroids learned are controlled via thesetPhase1Learner(jsat.classifiers.neuralnetwork.RBFNet.Phase1Learner)method- Parameters:
numCentroids- the number of centroids to use in the model
-
getNumCentroids
public int getNumCentroids()
Returns the number of centroids to use when training- Returns:
- * Returns the number of centroids to use when training
-
guessNumCentroids
public static Distribution guessNumCentroids(DataSet data)
Guesses the distribution for thesetNumCentroids(int)parameter- Parameters:
data- the data to create a guess for- Returns:
- a guess for the distribution of the number of centroids to use
-
setDistanceMetric
public void setDistanceMetric(DistanceMetric dm)
Sets the distance metric used to determine neuron activations.- Parameters:
dm- the distance metric to use
-
getDistanceMetric
public DistanceMetric getDistanceMetric()
Returns the distance metric in use- Returns:
- the distance metric in use
-
setPhase1Learner
public void setPhase1Learner(RBFNet.Phase1Learner p1l)
Sets the method used for learning the centroids (or hidden units) of the network.- Parameters:
p1l- the learning method to use
-
getPhase1Learner
public RBFNet.Phase1Learner getPhase1Learner()
Returns the method to use for learning the centroids of the network.- Returns:
- the method to use for learning the centroids of the network.
-
setPhase2Learner
public void setPhase2Learner(RBFNet.Phase2Learner p2l)
Sets the method used for learning the bandwidths for each centroid in the network. Depending on the method used,setAlpha(double)orsetP(int)may impact the learned bandwidths.- Parameters:
p2l- the learning method to use
-
getPhase2Learner
public RBFNet.Phase2Learner getPhase2Learner()
Returns the learning method to use for determining the bandwidths of each center in the network.- Returns:
- the learning method to use for the bandwidths
-
setNormalize
public void setNormalize(boolean normalize)
Sets whether or not to normalize the outputs of the neurons in the network so that the activations sum to one. Normalizing the outputs can increase the generalization ability of the network. By default this is set totrue- Parameters:
normalize-trueto normalize the neuron outputs,falseto use the raw activation values.
-
isNormalize
public boolean isNormalize()
Returns whether or not the network is currently normalizing its neuron outputs.- Returns:
- whether or not the neuron outputs are normalized
-
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.
-
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
-
fit
public void fit(DataSet data)
Description copied from interface:DataTransformFits this transform to the given dataset. Some transforms can only be learned from classification or regression datasets. If an incompatible dataset type is given, aFailedToFitExceptionexception may be thrown.- Specified by:
fitin interfaceDataTransform- Parameters:
data- the dataset to fir this transform to
-
train
public void train(RegressionDataSet dataSet, boolean parallel)
-
clone
public RBFNet clone()
- Specified by:
clonein interfaceClassifier- Specified by:
clonein interfaceDataTransform- Specified by:
clonein interfaceRegressor- Overrides:
clonein classjava.lang.Object
-
-
DataMelt 3.0 © DataMelt by jWork.ORG