Clusters defined by centroids. More...
#include <shark/Models/Clustering/Centroids.h>
Public Member Functions | |
SHARK_EXPORT_SYMBOL | Centroids () |
Default constructor. More... | |
SHARK_EXPORT_SYMBOL | Centroids (std::size_t centroids, std::size_t dimension) |
SHARK_EXPORT_SYMBOL | Centroids (Data< RealVector > const ¢roids) |
std::string | name () const |
From INameable: return the class name. More... | |
SHARK_EXPORT_SYMBOL RealVector | parameterVector () const |
from IParameterizable More... | |
SHARK_EXPORT_SYMBOL void | setParameterVector (RealVector const &newParameters) |
from IParameterizable More... | |
SHARK_EXPORT_SYMBOL std::size_t | numberOfParameters () const |
from IParameterizable More... | |
Shape | inputShape () const |
return the dimension of the inputs More... | |
SHARK_EXPORT_SYMBOL std::size_t | numberOfClusters () const |
return the number of centroids in the model More... | |
Data< RealVector > const & | centroids () const |
read access to the centroid vectors More... | |
void | setCentroids (Data< RealVector > const &newCentroids) |
overwrite the centroid vectors More... | |
SHARK_EXPORT_SYMBOL void | read (InArchive &archive) |
from ISerializable More... | |
SHARK_EXPORT_SYMBOL void | write (OutArchive &archive) const |
from ISerializable More... | |
SHARK_EXPORT_SYMBOL RealVector | softMembership (RealVector const &pattern) const |
from AbstractClustering: Compute cluster memberships. More... | |
SHARK_EXPORT_SYMBOL RealMatrix | softMembership (BatchInputType const &patterns) const |
From AbstractClustering: Compute cluster memberships for a batch of patterns. More... | |
SHARK_EXPORT_SYMBOL RealMatrix | distances (BatchInputType const &patterns) const |
Computes the distances of each pattern to all cluster centers. More... | |
SHARK_EXPORT_SYMBOL void | initFromData (ClassificationDataset const &data, std::size_t noClusters=0, std::size_t noClasses=0) |
SHARK_EXPORT_SYMBOL void | initFromData (Data< RealVector > const &dataset, std::size_t noClusters) |
Public Member Functions inherited from shark::AbstractClustering< RealVector > | |
const Features & | features () const |
virtual void | updateFeatures () |
bool | hasSoftMembershipFunction () const |
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... | |
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 () |
Public Member Functions inherited from shark::IParameterizable<> | |
virtual | ~IParameterizable () |
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 Member Functions | |
virtual SHARK_EXPORT_SYMBOL double | membershipKernel (double dist) const |
Protected Attributes | |
Data< RealVector > | m_centroids |
centroid vectors More... | |
Protected Attributes inherited from shark::AbstractClustering< RealVector > | |
Features | m_features |
Additional Inherited Members | |
Public Types inherited from shark::AbstractClustering< RealVector > | |
enum | Feature |
typedef RealVector | InputType |
typedef unsigned int | OutputType |
typedef Batch< InputType >::type | BatchInputType |
typedef Batch< OutputType >::type | BatchOutputType |
typedef TypedFlags< Feature > | Features |
typedef TypedFeatureNotAvailableException< Feature > | FeatureNotAvailableException |
Public Types inherited from shark::IParameterizable<> | |
typedef RealVector | ParameterVectorType |
Clusters defined by centroids.
Definition at line 58 of file Centroids.h.
SHARK_EXPORT_SYMBOL shark::Centroids::Centroids | ( | ) |
Default constructor.
SHARK_EXPORT_SYMBOL shark::Centroids::Centroids | ( | std::size_t | centroids, |
std::size_t | dimension | ||
) |
Constructor
centroids | number of centroids in the model (initially zero) |
dimension | dimension of the input space, and thus of the centroids |
SHARK_EXPORT_SYMBOL shark::Centroids::Centroids | ( | Data< RealVector > const & | centroids | ) |
Constructor
centroids | centroid vectors |
|
inline |
read access to the centroid vectors
Definition at line 99 of file Centroids.h.
References m_centroids.
Referenced by main().
SHARK_EXPORT_SYMBOL RealMatrix shark::Centroids::distances | ( | BatchInputType const & | patterns | ) | const |
Computes the distances of each pattern to all cluster centers.
Referenced by setCentroids().
SHARK_EXPORT_SYMBOL void shark::Centroids::initFromData | ( | ClassificationDataset const & | data, |
std::size_t | noClusters = 0 , |
||
std::size_t | noClasses = 0 |
||
) |
initialize centroids from labeled data: take the first data points with different labels; if there are more centroids than classes, the remaining centroids are filled with the first elements in the data set
data | dataset from which to take the centroids |
noClusters | number of centroids in the model, default 0 is mapped to the number of classes in the data set |
noClasses | number of clases in the dataset, default 0 means that the number is computed |
Referenced by setCentroids().
SHARK_EXPORT_SYMBOL void shark::Centroids::initFromData | ( | Data< RealVector > const & | dataset, |
std::size_t | noClusters | ||
) |
initialize centroids from unlabeled data: take a random subset of data points
dataset | dataset from which to take the centroids |
noClusters | number of centroids in the model |
|
inlinevirtual |
return the dimension of the inputs
Implements shark::AbstractClustering< RealVector >.
Definition at line 91 of file Centroids.h.
References shark::dataDimension(), m_centroids, numberOfClusters(), and SHARK_EXPORT_SYMBOL.
|
protectedvirtual |
Compute unnormalized membership from distance. The default implementation is to return exp(-distance)
Referenced by setCentroids().
|
inlinevirtual |
From INameable: return the class name.
Reimplemented from shark::INameable.
Definition at line 78 of file Centroids.h.
References numberOfParameters(), parameterVector(), setParameterVector(), and SHARK_EXPORT_SYMBOL.
|
virtual |
return the number of centroids in the model
Implements shark::AbstractClustering< RealVector >.
Referenced by inputShape().
|
virtual |
|
virtual |
|
virtual |
|
inline |
overwrite the centroid vectors
Definition at line 104 of file Centroids.h.
References distances(), initFromData(), m_centroids, membershipKernel(), read(), SHARK_EXPORT_SYMBOL, softMembership(), and write().
|
virtual |
|
virtual |
from AbstractClustering: Compute cluster memberships.
Reimplemented from shark::AbstractClustering< RealVector >.
Referenced by setCentroids().
|
virtual |
From AbstractClustering: Compute cluster memberships for a batch of patterns.
Reimplemented from shark::AbstractClustering< RealVector >.
|
virtual |
|
protected |
centroid vectors
Definition at line 146 of file Centroids.h.
Referenced by centroids(), inputShape(), and setCentroids().