Package moa.classifiers.rules.functions
Class Perceptron
- java.lang.Object
-
- moa.AbstractMOAObject
-
- moa.options.AbstractOptionHandler
-
- moa.classifiers.AbstractClassifier
-
- moa.classifiers.rules.functions.Perceptron
-
- All Implemented Interfaces:
Configurable
,Serializable
,CapabilitiesHandler
,Classifier
,Regressor
,AMRulesLearner
,AMRulesRegressorFunction
,AWTRenderable
,Learner<Example<Instance>>
,MOAObject
,OptionHandler
public class Perceptron extends AbstractClassifier implements AMRulesRegressorFunction
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected double
accumulatedError
FlagOption
constantLearningRatioDecayOption
protected double
fadingFactor
FloatOption
fadingFactorOption
protected boolean
initialisePerceptron
protected double
learningRateDecay
FloatOption
learningRateDecayOption
protected double
learningRatio
FloatOption
learningRatioOption
protected int[]
numericAttributesIndex
DoubleVector
perceptronattributeStatistics
protected double
perceptronInstancesSeen
protected double
perceptronsumY
protected double
perceptronYSeen
IntOption
randomSeedOption
DoubleVector
squaredperceptronattributeStatistics
protected double
squaredperceptronsumY
protected double[]
weightAttribute
-
Fields inherited from class moa.classifiers.AbstractClassifier
classifierRandom, modelContext, randomSeed, trainingWeightSeenByModel
-
Fields inherited from class moa.options.AbstractOptionHandler
config
-
-
Constructor Summary
Constructors Constructor Description Perceptron()
Perceptron(Perceptron p)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description double
computeSD(double squaredVal, double val, double size)
double
getCurrentError()
double
getInstancesSeen()
void
getModelDescription(StringBuilder out, int indent)
Returns a string representation of the model.protected Measurement[]
getModelMeasurementsImpl()
Gets the current measurements of this classifier.
The reason for ...Impl methods: ease programmer burden by not requiring them to remember calls to super in overridden methods.double[]
getVotesForInstance(Instance inst)
Predicts the class memberships for a given instance.double[]
getWeights()
boolean
isRandomizable()
Gets whether this learner needs a random seed.double[]
normalizedInstance(Instance inst)
double
normalizedPrediction(Instance inst)
void
normalizeWeights()
double
prediction(double[] instanceValues)
void
reset()
void
resetError()
void
resetLearningImpl()
A method to reset the modelvoid
setInstancesSeen(int pInstancesSeen)
void
setLearningRatio(double learningRatio)
void
setWeights(double[] w)
void
trainOnInstanceImpl(Instance inst)
Update the model using the provided instancevoid
updateWeights(Instance inst, double learningRatio)
-
Methods inherited from class moa.classifiers.AbstractClassifier
contextIsCompatible, copy, correctlyClassifies, defineImmutableCapabilities, getAttributeNameString, getAWTRenderer, getClassLabelString, getClassNameString, getDescription, getModel, getModelContext, getModelMeasurements, getNominalValueString, getPredictionForInstance, getPredictionForInstance, getPurposeString, getSubClassifiers, getSublearners, getVotesForInstance, modelAttIndexToInstanceAttIndex, modelAttIndexToInstanceAttIndex, prepareForUseImpl, resetLearning, setModelContext, setRandomSeed, trainingHasStarted, trainingWeightSeenByModel, trainOnInstance, trainOnInstance
-
Methods inherited from class moa.options.AbstractOptionHandler
getCLICreationString, getOptions, getPreparedClassOption, prepareClassOptions, prepareForUse, prepareForUse
-
Methods inherited from class moa.AbstractMOAObject
copy, measureByteSize, measureByteSize, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface moa.gui.AWTRenderable
getAWTRenderer
-
Methods inherited from interface moa.capabilities.CapabilitiesHandler
getCapabilities
-
Methods inherited from interface moa.learners.Learner
getModel, getModelContext, getModelMeasurements, getPredictionForInstance, getSublearners, getVotesForInstance, resetLearning, setModelContext, setRandomSeed, trainingHasStarted, trainingWeightSeenByModel, trainOnInstance
-
Methods inherited from interface moa.MOAObject
getDescription, measureByteSize
-
Methods inherited from interface moa.options.OptionHandler
getCLICreationString, getOptions, getPurposeString, prepareForUse, prepareForUse
-
-
-
-
Field Detail
-
constantLearningRatioDecayOption
public FlagOption constantLearningRatioDecayOption
-
learningRatioOption
public FloatOption learningRatioOption
-
learningRateDecayOption
public FloatOption learningRateDecayOption
-
fadingFactorOption
public FloatOption fadingFactorOption
-
randomSeedOption
public IntOption randomSeedOption
-
fadingFactor
protected double fadingFactor
-
learningRatio
protected double learningRatio
-
learningRateDecay
protected double learningRateDecay
-
weightAttribute
protected double[] weightAttribute
-
perceptronattributeStatistics
public DoubleVector perceptronattributeStatistics
-
squaredperceptronattributeStatistics
public DoubleVector squaredperceptronattributeStatistics
-
perceptronInstancesSeen
protected double perceptronInstancesSeen
-
perceptronYSeen
protected double perceptronYSeen
-
accumulatedError
protected double accumulatedError
-
initialisePerceptron
protected boolean initialisePerceptron
-
perceptronsumY
protected double perceptronsumY
-
squaredperceptronsumY
protected double squaredperceptronsumY
-
numericAttributesIndex
protected int[] numericAttributesIndex
-
-
Constructor Detail
-
Perceptron
public Perceptron()
-
Perceptron
public Perceptron(Perceptron p)
-
-
Method Detail
-
setWeights
public void setWeights(double[] w)
-
getWeights
public double[] getWeights()
-
getInstancesSeen
public double getInstancesSeen()
-
setInstancesSeen
public void setInstancesSeen(int pInstancesSeen)
-
resetLearningImpl
public void resetLearningImpl()
A method to reset the model- Specified by:
resetLearningImpl
in classAbstractClassifier
-
reset
public void reset()
-
resetError
public void resetError()
-
trainOnInstanceImpl
public void trainOnInstanceImpl(Instance inst)
Update the model using the provided instance- Specified by:
trainOnInstanceImpl
in classAbstractClassifier
- Parameters:
inst
- the instance to be used for training
-
normalizedPrediction
public double normalizedPrediction(Instance inst)
-
prediction
public double prediction(double[] instanceValues)
-
normalizedInstance
public double[] normalizedInstance(Instance inst)
-
computeSD
public double computeSD(double squaredVal, double val, double size)
-
updateWeights
public void updateWeights(Instance inst, double learningRatio)
-
normalizeWeights
public void normalizeWeights()
-
isRandomizable
public boolean isRandomizable()
Description copied from interface:Learner
Gets whether this learner needs a random seed. Examples of methods that needs a random seed are bagging and boosting.- Specified by:
isRandomizable
in interfaceLearner<Example<Instance>>
- Returns:
- true if the learner needs a random seed.
-
getVotesForInstance
public double[] getVotesForInstance(Instance inst)
Description copied from interface:Classifier
Predicts the class memberships for a given instance. If an instance is unclassified, the returned array elements must be all zero.- Specified by:
getVotesForInstance
in interfaceClassifier
- Specified by:
getVotesForInstance
in classAbstractClassifier
- Parameters:
inst
- the instance to be classified- Returns:
- an array containing the estimated membership probabilities of the test instance in each class
-
getModelMeasurementsImpl
protected Measurement[] getModelMeasurementsImpl()
Description copied from class:AbstractClassifier
Gets the current measurements of this classifier.
The reason for ...Impl methods: ease programmer burden by not requiring them to remember calls to super in overridden methods. Note that this will produce compiler errors if not overridden.- Specified by:
getModelMeasurementsImpl
in classAbstractClassifier
- Returns:
- an array of measurements to be used in evaluation tasks
-
getModelDescription
public void getModelDescription(StringBuilder out, int indent)
Description copied from class:AbstractClassifier
Returns a string representation of the model.- Specified by:
getModelDescription
in classAbstractClassifier
- Parameters:
out
- the stringbuilder to add the descriptionindent
- the number of characters to indent
-
setLearningRatio
public void setLearningRatio(double learningRatio)
-
getCurrentError
public double getCurrentError()
- Specified by:
getCurrentError
in interfaceAMRulesLearner
-
-