Into

Modules

Documentation

classPiiPerceptron

#include <PiiPerceptron.h>

Implementation of the Perceptron algorithm.

Inherits PiiLearningAlgorithm< SampleSet >, PiiClassifier< SampleSet >

Description

The Perceptron is a linear (hyperplane) classifier that maps an N-dimensional input space into a binary value:

The vector w in the equation is known as the weight vector, which defines the direction of the hyperplane separating the two classes. (The weight vector is perpendicular to the plane, pointing to the positive side.) The b term is known as the bias, and it can be seen as an offset to the decision function. Geometrically, a non-zero bias term translates the separating hyperplane along the plane's normal (weight vector) so that the plane doesn't intersect the origin of the feature space. The Perceptron algorithm iteratively adjusts the weights and the bias to find the separating hyperplane.

The input for the training algorithm is a sample set with binary classifications: . On each iteration, the weigh vector and the bias are updated as follows:

Here, is a learning constant and t denotes time. Note that if the sample is classified correctly (c equals the output of the decision function f(x)), the updates become zero. Another thing to note is that scaling the decision function with a constant value has no effect on the outcome. Therefore, the choice of becomes irrelevat with increasing number of iterations. Usually, the learning rate is just set to one. In fact, this implementation doesn't even allow you to specify the learning rate for the sake of avoiding unnecessary parameterization.

The linear Perceptron algorithm converges if the two classes are linearly separable in the input space. If they are not, one can use a kernel function to separate the classes with a non-linear mapping to a high-dimensional feature space. This is called the Kernel Perceptron" algorithm.

Public types

typedef PiiSampleSet::Traits< SampleSet >::ConstFeatureIterator

Constructors and destructor

Public member functions

double
( )

Returns the bias term.

virtual PiiClassification::LearnerCapabilities

Returns 0.

virtual double
(
  • ConstFeatureIterator featureVector
)

Returns the classification of featureVector (either 0 or 1), or NaN if the Perceptron has not been trained yet.

virtual bool
( )

Returns true if learn() was called, and the learning algorithm converged to a solution, false otherwise.

int

Returns the number of features in each feature vector.

virtual void
(
  • const SampleSet & samples
  • const QVector< double > & labels
  • const QVector< double > & weights = < double >()
)

Runs the Perceptron algorithm with the given samples and class labels.

int

Returns the maximum number of learning iterations.

void
(
  • double bias
)

Sets the bias term.

void
(
  • int maxIterations
)

Sets the maximum number of iterations the algorithm will take.

void
(
  • const QVector< double > & weights
)

Sets the weight vector.

QVector< double >
( )

Returns the weight vector.

Function details

  • PiiPerceptron

    ()
  • ~PiiPerceptron

    ()
  • double bias

    ()

    Returns the bias term.

    This value is initially zero and assigned by the learning algorithm

  • virtual PiiClassification::LearnerCapabilities capabilities

    ()
    [virtual]

    Returns 0.

    The Perceptron is a supervised classifier with no on-line learning capabilities.

    Reimplemented from PiiLearningAlgorithm.

  • virtual double classify

    (
    • ConstFeatureIterator featureVector
    )
    [virtual]

    Returns the classification of featureVector (either 0 or 1), or NaN if the Perceptron has not been trained yet.

    Reimplemented from PiiClassifier.

  • virtual bool converged

    ()
    [virtual]

    Returns true if learn() was called, and the learning algorithm converged to a solution, false otherwise.

    The learning algorithm won't converge if the classes are not linearly separable or if maxIterations() is reached before finding a solution.

    Reimplemented from PiiLearningAlgorithm.

  • int featureCount

    ()

    Returns the number of features in each feature vector.

    If the Perceptron has not been trained, zero will be returned.

  • virtual void learn

    (
    • const SampleSet & samples
    • const QVector< double > & labels
    • const QVector< double > & weights = < double >()
    )
    [virtual]

    Runs the Perceptron algorithm with the given samples and class labels.

    Since the Perceptron is a binary classifier, the class labels must be either ones or zeros. The weights will be ignored.

    Reimplemented from PiiLearningAlgorithm.

  • int maxIterations

    ()

    Returns the maximum number of learning iterations.

    The default value is 100.

  • void setBias

    (
    • double bias
    )

    Sets the bias term.

    The bias is usually not assigned manually, but using the learn() function.

  • void setMaxIterations

    (
    • int maxIterations
    )

    Sets the maximum number of iterations the algorithm will take.

    This value limits the number of times the whole sample set is iterated over.

  • void setWeights

    (
    • const QVector< double > & weights
    )

    Sets the weight vector.

    The weighs are usually not assigned manually, but using the learn() function. The number of weights must match the number of feature space dimensions.

  • QVector< double > weights

    ()

    Returns the weight vector.

    The length of the weight vector is equal to the number of feature space dimensions. If learn() has not been called, an empty vector will be returned.

Notes (0)

Add a note

Not a single note added yet. Be the first, add yours.