classPiiVectorQuantizerOperation
#include <PiiVectorQuantizerOperation.h>
A superclass for classifier operations that use classifiers derived from PiiVectorQuantizer.
Inherits PiiClassifierOperation
Inherited by PiiKnnClassifierOperation, PiiSomOperation
Description
This class adds support for run-time changeable distance measures to the classifier operation.
Inputs
Outputs
classification if classLabels are not set.
Properties
|
QVariantList
|
Class labels for code vectors. |
|
The mode of combining the distances calculated by different distance measures. |
|
|
Set the distance measure. |
|
|
Set many distance measures. |
|
|
QVariantList
|
Weights assigned to distance measures, if many are used. |
|
The model samples as a PiiVariant. |
|
|
double
|
Set a distance threshold for rejecting samples. |
Constructors and destructor
|
(
|
|
Public member functions
|
QVariantList
|
( )
|
|
( )
|
|
|
( )
|
|
|
QVariantList
|
( )
|
|
( )
|
|
|
double
|
( )
|
|
void
|
(
|
|
void
|
|
|
void
|
|
|
void
|
|
|
void
|
(
|
|
void
|
|
|
void
|
(
|
Protected member functions
|
( )
Returns a pointer to the |
|
|
template<class SampleSet>
void
|
Configure classifier for running. |
|
template<class SampleSet>
double
|
Reads features from the |
|
template<class Measure>
Measure *
|
Create an instance of name as |
|
( )
Returns a pointer to the |
|
|
double
|
(
Returns the class label corresponding to the sample at index. |
|
(
|
|
|
template<class SampleSet>
void
|
Creates an instance of a distance measure as specified by the distanceMeasure property. |
|
template<class SampleSet>
void
|
Configures classifier so that its distance measure is aware of multi-feature boundaries. |
|
template<class SampleSet>
void
|
Checks that the models variant is of correct type, and reconfigures classifier with them. |
|
Returns a pointer to the |
Property details
-
QVariantList classLabels
[read, write]Class labels for code vectors.
If this list is non-empty, the
classificationoutput will emit the label corresponding to the closest code vector instead of the index of the code vector. Otherwise theclassificationandvectorindexoutputs will both emit the index of the closest code vector. -
PiiClassification::DistanceCombinationMode distanceCombinationMode
[read, write]The mode of combining the distances calculated by different distance measures.
-
QString distanceMeasure
[read, write]Set the distance measure.
Use the resource name in the resource database as a key. Note that distance measures are registered to the resource database as template instances, but template arguments should not be explicitly given here. If no resource matching the given name is found in the resource database, setting this property does nothing. The default distance measure is PiiSquaredGeometricDistance.
PiiOperation* pClassifier = engine.createOperation("PiiKnnClassifier<float>"); // This will create an instance of PiiHistogramIntersection<float> classifier->setProperty("distanceMeasure", "PiiHistogramIntersection"); // Explicitly creating a one-element list has the same same effect classifier->setProperty("distanceMeasures", QStringList() << "PiiHistogramIntersection");
-
QStringList distanceMeasures
[read, write]Set many distance measures.
Multiple different distance measures may be needed if input samples are composed of many feature vectors. Assume your feature vectors actually consist of two concatenated vectors (see PiiFeatureCombiner). You intend to use histogram intersection for the first and log-likelihood for the other. Here's how:
classifier->setProperty("distanceMeasures", QStringList() << "PiiHistogramIntersection" << "PiiLogLikelihood");
If multiple distance measures are given, distanceMeasure will be set to "PiiMultiFeatureDistance".
-
QVariantList distanceWeights
[read, write]Weights assigned to distance measures, if many are used.
-
PiiVariant models
[read, write]The model samples as a PiiVariant.
The variant will usually hold a PiiMatrix whose data type equals the type of the operation. For example, PiiSomOperation<double> will have a PiiMatrix<double> as its code book. Subclasses are however free to use any suitable data structure to represent the code book.
-
double rejectThreshold
[read, write]Set a distance threshold for rejecting samples.
If the distance of an unknown sample to the closest code vector is above this threshold, the sample will be rejected and classified as minus one. The default value is INFINITY.
Function details
-
PiiVectorQuantizerOperation
(- PiiClassification::LearnerCapabilities capabilities
[protected] -
~PiiVectorQuantizerOperation
() -
QVariantList classLabels
() -
PiiClassification::DistanceCombinationMode distanceCombinationMode
() -
QString distanceMeasure
() -
QStringList distanceMeasures
() -
QVariantList distanceWeights
() -
PiiVariant models
() -
double rejectThreshold
() -
void setClassLabels
(- const QVariantList & labels
-
void setDistanceCombinationMode
-
void setDistanceMeasure
-
void setDistanceMeasures
-
void setDistanceWeights
(- const QVariantList & distanceWeights
-
void setModels
-
void setRejectThreshold
(- double rejectThreshold
-
Returns a pointer to the
boundaryinput. -
template<class SampleSet>
void check
[protected]Configure classifier for running.
This function must be called by a subclass' implementation of the check() function. This function configures classifier with the samples given as the models property, and creates an instance of the requested distance measure.
Exceptions
- PiiExecutionException&
-
if setting the model samples or the distance measure fails.
-
template<class SampleSet>
double classify
[protected]Reads features from the
featuresinput, configures multi-feature boundaries if needed, finds the closest match for the features just read, and returns the index of the closest vector in the model sample set.If classLabels is non-empty, returns the class label corresponding to the index of the closest sample. This function also sends the distance to the closest sample and its index.
Exceptions
- PiiExecutionException&
-
if the features are of incorrect type or size.
-
Create an instance of name as
Measure.Exceptions
- PiiExecutionException&
-
if the resource database doesn't contain the named resource, or it is not instantiable as
Measure.
-
Returns a pointer to the
distanceoutput. -
double labelForIndex
(- int index
[protected]Returns the class label corresponding to the sample at index.
If the label list is empty, returns index (or
NaNif index is -1). If there is no label for index, returns NAN. -
template<class SampleSet>
void setDistanceMeasure
[protected]Creates an instance of a distance measure as specified by the distanceMeasure property.
If there are many distance measures, creates a PiiMultiFeatureDistance and appends all requrested distance measures to it.
Exceptions
- PiiExecutionException&
-
if the distance measures cannot be created.
-
template<class SampleSet>
void setFeatureBoundaries
[protected]Configures classifier so that its distance measure is aware of multi-feature boundaries.
Does nothing if the distance measure is not a PiiMultiFeatureDistance or the
boundariesinput is not connected.Exceptions
- PiiExecutionException&
-
if the boundary input doesn't contain a PiiMatrix<int>.
-
template<class SampleSet>
void setModels
[protected]Checks that the models variant is of correct type, and reconfigures classifier with them.
Exceptions
- PiiExecutionException&
-
if the type of the variant is incorrect
-
Returns a pointer to the
vectorindexoutput.
Add a note
Not a single note added yet. Be the first, add yours.