classPiiLearningAlgorithm
#include <PiiLearningAlgorithm.h>
An interface for learning algorithms.
Inherited by PiiBoostClassifier< SampleSet >, PiiDecisionStump< SampleSet >, PiiKernelAdatron< SampleSet >, PiiKernelPerceptron< SampleSet >, PiiPerceptron< SampleSet >, PiiSampleSetCollector< SampleSet >, PiiSom< SampleSet >
Description
Learning algorithms work by optimizing a learning criterion based on a batch of training samples. The criterion to be optimized may be represented in a number of very different ways, including maximizing the margin of separation between classes (PiiSvm, PiiKernelAdatron), just separating classes (PiiPerceptron), or clustering data (PiiSom).
Learning algorithms can be categorized in a number of ways. This interface makes a distinction between on-line and batch algorithms. Algorithms that don't require all training samples to be present at once as a batch (so-called on-line algorithms such as sequential SOM) only need to implement the learnOne() function. If the algorithm is not capable of on-line training, the learn() function must be overridden instead.
The learning functions take two optional parameters: label and weight. Not all learning algorithms need these values. Class labels are used in supervised training, and sample weights in weighted learning. Some algorithms such as PiiDecisionStump use both the labels and the weights.
Public types
|
typedef SampleSet
|
Constructors and destructor
|
Create a new learning algorithm instance. |
|
|
virtual
|
Destroys the learning algorithm. |
Public member functions
|
virtual PiiClassification::LearnerCapabilities
|
( )
= 0
Returns the capabilities of the learning algorithm as a combination of LearnerCapability flags. |
|
( )
Returns the currently installed controller. |
|
|
virtual bool
|
( )
= 0
Returns |
|
virtual void
|
Train the learning algorithm with a batch of samples. |
|
virtual double
|
(
Feeds a feature vector to the learning algorithm. |
|
void
|
Set the progress controller. |
Function details
-
PiiLearningAlgorithm
()Create a new learning algorithm instance.
-
virtual ~PiiLearningAlgorithm
()[virtual]Destroys the learning algorithm.
-
virtual PiiClassification::LearnerCapabilities capabilities
()[pure virtual]Returns the capabilities of the learning algorithm as a combination of LearnerCapability flags.
-
PiiProgressController * controller
()Returns the currently installed controller.
Returns
the current controller or zero if no controller is installed
-
virtual bool converged
()[pure virtual]Returns
trueif the algorithm has converged (found an optimal solution) andfalseotherwise. -
virtual void learn
(- const SampleSet & samples
- const QVector< double > & labels = < double >()
- const QVector< double > & weights = < double >()
[virtual]Train the learning algorithm with a batch of samples.
The default implementation sequentially sends each sample in samples to learnOne() until converged() returns
true.Parameters
- samples
-
a set of feature vectors to train the algorithm with.
- labels
-
the labels of the samples. This value is not used by non-supervised classifiers and can be set to an empty list. If the value is given, the length of the list must be equal to the number of samples in samples.
- weights
-
weights for individual samples. This value is used only if the learning algorithm is capable of weighted learning. If this value is given, the length of the list must be equal to the number of samples in samples.
Exceptions
- PiiClassificationException&
-
if something goes wrong. An exception is thrown, for example, if the training is cancelled by the progress controller.
-
virtual double learnOne
(- typename PiiSampleSet::Traits< SampleSet >::ConstFeatureIterator featureVector
- int length
- double label = NAN
- double weight = 1.0
[virtual]Feeds a feature vector to the learning algorithm.
The learning algorithm adapts its internal state according to the feature vector and a known label (supervised learning). In non-supervised learning, the label is ignored.
Parameters
- featureVector
-
a feature vector
- length
-
the length of the feature vector. This must be the same for all samples. Otherwise, the behavior is undefined.
- label
-
an optional class label for supervised learning.
- weight
-
an optional weight for the training sample
Returns
classification for the sample. Some classifiers are able to classify samples during the learning process with no additional computational effort. They return the current classification of the feture vector. Others should return
NaN. The default implementation returnsNaN. -
void setController
Set the progress controller.
Set to zero to disable the controller.
Add a note
Not a single note added yet. Be the first, add yours.