shark::AbstractClustering< InputT > Class Template Referenceabstract

Base class for clustering. More...

#include <shark/Models/Clustering/AbstractClustering.h>

+ Inheritance diagram for shark::AbstractClustering< InputT >:

Public Types

enum  Feature { HAS_SOFT_MEMBERSHIP = 1 }
 
typedef InputT InputType
 
typedef unsigned int OutputType
 
typedef Batch< InputType >::type BatchInputType
 
typedef Batch< OutputType >::type BatchOutputType
 
typedef TypedFlags< FeatureFeatures
 
typedef TypedFeatureNotAvailableException< FeatureFeatureNotAvailableException
 
- Public Types inherited from shark::IParameterizable<>
typedef RealVector ParameterVectorType
 

Public Member Functions

const Featuresfeatures () const
 
virtual void updateFeatures ()
 
bool hasSoftMembershipFunction () const
 
virtual std::size_t numberOfClusters () const =0
 return the number of clusters More...
 
virtual Shape inputShape () const =0
 
virtual unsigned int hardMembership (InputType const &pattern) const
 Compute best matching cluster. More...
 
virtual BatchOutputType hardMembership (BatchInputType const &patterns) const
 Compute best matching cluster for a batch of inputs. More...
 
virtual RealVector softMembership (InputType const &pattern) const
 Compute cluster membership function. More...
 
virtual RealMatrix softMembership (BatchInputType const &patterns) const
 Compute cluster membership function. More...
 
void read (InArchive &archive)
 empty default implementation of ISerializable::read More...
 
void write (OutArchive &archive) const
 empty default implementation of ISerializable::write More...
 
- Public Member Functions inherited from shark::INameable
virtual ~INameable ()
 
virtual std::string name () const
 returns the name of the object More...
 
- Public Member Functions inherited from shark::IParameterizable<>
virtual ~IParameterizable ()
 
virtual ParameterVectorType parameterVector () const
 Return the parameter vector. More...
 
virtual void setParameterVector (ParameterVectorType const &newParameters)
 Set the parameter vector. More...
 
virtual std::size_t numberOfParameters () const
 Return the number of parameters. More...
 
- Public Member Functions inherited from shark::ISerializable
virtual ~ISerializable ()
 Virtual d'tor. More...
 
void load (InArchive &archive, unsigned int version)
 Versioned loading of components, calls read(...). More...
 
void save (OutArchive &archive, unsigned int version) const
 Versioned storing of components, calls write(...). More...
 
 BOOST_SERIALIZATION_SPLIT_MEMBER ()
 

Protected Attributes

Features m_features
 

Detailed Description

template<class InputT>
class shark::AbstractClustering< InputT >

Base class for clustering.

Clustering algorithms vary widely in the data structures on which they operate. For example, simple centroid-based approaches such as k-means are mutually incompatible with tree-based hierarchical clustering. This interface class is the attempt to cast different cluster descriptions into a minimal common interface that is useful for prediction.
There are at least two common types of predictions made with clusterings. The first one is the assignment of the best matching cluster to a patters, such as in vector quantization or unsupervised clustering. This is often referred to as "hard clustering". The second one is the computation of a membership function ("soft clustering"). The membership of a pattern to a cluster is non-negative, and the total membership should add to one.
This interface makes minimal assumptions to allow for these types of predictions. It assumes that clusters can be enumbered (identified by an index), and that at least a membership test can be made (hard clustering). It is optional to provide a membership function. Only one of the two interfaces for best matching cluster or membership function need to be implemented, since the best matching cluster can be deduced from the membership function. However, often the best matching cluster can be computed more efficiently than the membership function. In these cases both interface functions should be implemented.
The purpose of this interface is to act as a common super class to different data structures describing the outcome of a clustering operation. The interface allows all of these data structures to be used in the two clustering model classes: HardClusteringModel and SoftClusteringModel.

Definition at line 92 of file AbstractClustering.h.

Member Typedef Documentation

◆ BatchInputType

template<class InputT>
typedef Batch<InputType>::type shark::AbstractClustering< InputT >::BatchInputType

Definition at line 97 of file AbstractClustering.h.

◆ BatchOutputType

template<class InputT>
typedef Batch<OutputType>::type shark::AbstractClustering< InputT >::BatchOutputType

Definition at line 98 of file AbstractClustering.h.

◆ FeatureNotAvailableException

Definition at line 103 of file AbstractClustering.h.

◆ Features

template<class InputT>
typedef TypedFlags<Feature> shark::AbstractClustering< InputT >::Features

Definition at line 103 of file AbstractClustering.h.

◆ InputType

template<class InputT>
typedef InputT shark::AbstractClustering< InputT >::InputType

Definition at line 95 of file AbstractClustering.h.

◆ OutputType

template<class InputT>
typedef unsigned int shark::AbstractClustering< InputT >::OutputType

Definition at line 96 of file AbstractClustering.h.

Member Enumeration Documentation

◆ Feature

template<class InputT>
enum shark::AbstractClustering::Feature
Enumerator
HAS_SOFT_MEMBERSHIP 

Definition at line 100 of file AbstractClustering.h.

Member Function Documentation

◆ features()

template<class InputT>
const Features& shark::AbstractClustering< InputT >::features ( ) const
inline

Definition at line 103 of file AbstractClustering.h.

◆ hardMembership() [1/2]

template<class InputT>
virtual unsigned int shark::AbstractClustering< InputT >::hardMembership ( InputType const &  pattern) const
inlinevirtual

Compute best matching cluster.

This function should be overriden by sub-classes to compute the cluster best matching the input pattern. The (typically slow) default implementation is to create a batch of size 1 and return the result of the batch call to hardMembership

Definition at line 124 of file AbstractClustering.h.

Referenced by shark::HardClusteringModel< InputT >::eval(), and shark::AbstractClustering< RealVector >::hardMembership().

◆ hardMembership() [2/2]

template<class InputT>
virtual BatchOutputType shark::AbstractClustering< InputT >::hardMembership ( BatchInputType const &  patterns) const
inlinevirtual

Compute best matching cluster for a batch of inputs.

This function should be overriden by sub-classes to compute the cluster best matching the input pattern. The (typically slow) default implementation is to return the arg max of the soft membership function for every pattern.

Reimplemented in shark::HierarchicalClustering< InputT >.

Definition at line 137 of file AbstractClustering.h.

◆ hasSoftMembershipFunction()

template<class InputT>
bool shark::AbstractClustering< InputT >::hasSoftMembershipFunction ( ) const
inline

Tests whether the clustering can compute a (soft) member ship function, describing the membership of a sample to the different clusters.

Definition at line 108 of file AbstractClustering.h.

Referenced by shark::SoftClusteringModel< InputT >::SoftClusteringModel().

◆ inputShape()

◆ numberOfClusters()

template<class InputT>
virtual std::size_t shark::AbstractClustering< InputT >::numberOfClusters ( ) const
pure virtual

◆ read()

template<class InputT>
void shark::AbstractClustering< InputT >::read ( InArchive archive)
inlinevirtual

empty default implementation of ISerializable::read

Reimplemented from shark::ISerializable.

Definition at line 172 of file AbstractClustering.h.

◆ softMembership() [1/2]

template<class InputT>
virtual RealVector shark::AbstractClustering< InputT >::softMembership ( InputType const &  pattern) const
inlinevirtual

Compute cluster membership function.

This function should be overriden by sub-classes to compute the membership of a pattern to the clusters. The default implementation creates a batch of size 1 and calls the batched version. If this is not overriden, an xception is thrown.

Reimplemented in shark::Centroids.

Definition at line 157 of file AbstractClustering.h.

Referenced by shark::SoftClusteringModel< InputT >::eval(), and shark::AbstractClustering< RealVector >::hardMembership().

◆ softMembership() [2/2]

template<class InputT>
virtual RealMatrix shark::AbstractClustering< InputT >::softMembership ( BatchInputType const &  patterns) const
inlinevirtual

Compute cluster membership function.

This function should be overriden by sub-classes to compute the membership of a pattern to the clusters. This default implementation throws an exception.

Reimplemented in shark::Centroids.

Definition at line 167 of file AbstractClustering.h.

◆ updateFeatures()

template<class InputT>
virtual void shark::AbstractClustering< InputT >::updateFeatures ( )
inlinevirtual

Definition at line 103 of file AbstractClustering.h.

◆ write()

template<class InputT>
void shark::AbstractClustering< InputT >::write ( OutArchive archive) const
inlinevirtual

empty default implementation of ISerializable::write

Reimplemented from shark::ISerializable.

Definition at line 175 of file AbstractClustering.h.

Member Data Documentation

◆ m_features

template<class InputT>
Features shark::AbstractClustering< InputT >::m_features
protected

The documentation for this class was generated from the following file: