Skip to content

add_sample_class_knnAddSampleClassKnnAddSampleClassKnnadd_sample_class_knnT_add_sample_class_knnπŸ”—

Short descriptionπŸ”—

add_sample_class_knnAddSampleClassKnnAddSampleClassKnnadd_sample_class_knnT_add_sample_class_knn β€” Add a sample to a k-nearest neighbors (k-NN) classifier.

SignatureπŸ”—

add_sample_class_knn( class_knn KNNHandle, number Features, integer ClassID )void AddSampleClassKnn( const HTuple& KNNHandle, const HTuple& Features, const HTuple& ClassID )static void HOperatorSet.AddSampleClassKnn( HTuple KNNHandle, HTuple features, HTuple classID )def add_sample_class_knn( knnhandle: HHandle, features: MaybeSequence[float], class_id: MaybeSequence[int] ) -> None

Herror T_add_sample_class_knn( const Htuple KNNHandle, const Htuple Features, const Htuple ClassID )

void HClassKnn::AddSampleClassKnn( const HTuple& Features, const HTuple& ClassID ) const

void HClassKnn::AddSampleClassKnn( double Features, Hlong ClassID ) const

void HClassKnn.AddSampleClassKnn( HTuple features, HTuple classID )

void HClassKnn.AddSampleClassKnn( double features, int classID )

DescriptionπŸ”—

add_sample_class_knnAddSampleClassKnn adds a feature vector to a k-nearest neighbors (k-NN) data structure. The length of a feature vector was specified in create_class_knnCreateClassKnn by NumDimnumDimnum_dim. A handle to a k-NN data structure has to be specified in KNNHandleKNNHandleknnhandle.

The feature vectors are collected in Featuresfeaturesfeatures. The length of the input vector must be a multiple of NumDimnumDimnum_dim. Each feature vector needs a class which can be given by ClassIDclassIDclass_id, if only one was specified, the class is used for all vectors. The class is a natural number greater or equal to 0. If only one class is used, the class has to be 0. In case the operator classify_image_class_knnClassifyImageClassKnn will be used, all numbers starting from 0 to the number of classes-1 should be used, since otherwise an empty region will be generated for each unused number.

It is allowed to add samples to an already trained k-NN classificator. The new data is only integrated after another call to train_class_knnTrainClassKnn.

If the k-NN classifier has been trained with automatic feature normalization enabled, the supplied features Featuresfeaturesfeatures are interpreted as unnormalized and are normalized as it was defined by the last call to train_class_knnTrainClassKnn. Please see train_class_knnTrainClassKnn for more information on normalization.

Execution informationπŸ”—

Execution information
  • Multithreading type: reentrant (runs in parallel with non-exclusive operators).

  • Multithreading scope: global (may be called from any thread).

  • Processed without parallelization.

This operator modifies the state of the following input parameter:

During execution of this operator, access to the value of this parameter must be synchronized if it is used across multiple threads.

ParametersπŸ”—

KNNHandleKNNHandleknnhandle (input_control, state is modified) class_knn β†’ (handle)HTuple (HHandle)HClassKnn, HTuple (IntPtr)HHandleHtuple (handle)

Handle of the k-NN classifier.

Featuresfeaturesfeatures (input_control) number(-array) β†’ (real)HTuple (double)HTuple (double)MaybeSequence[float]Htuple (double)

List of features to add.

ClassIDclassIDclass_id (input_control) integer(-array) β†’ (integer)HTuple (Hlong)HTuple (int / long)MaybeSequence[int]Htuple (Hlong)

Class IDs of the features.

ResultπŸ”—

If the parameters are valid, the operator add_sample_class_knnAddSampleClassKnn returns the value 2 (H_MSG_TRUE). If necessary, an exception is raised.

Combinations with other operatorsπŸ”—

Combinations

Possible predecessors

train_class_knnTrainClassKnn, read_class_knnReadClassKnn

See also

create_class_knnCreateClassKnn, read_class_knnReadClassKnn

ReferencesπŸ”—

Marius Muja, David G. Lowe: ``Fast Approximate Nearest Neighbors with Automatic Algorithm Configurationβ€™β€˜; International Conference on Computer Vision Theory and Applications (VISAPP 09); 2009.

ModuleπŸ”—

Foundation