123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- #ifndef KMEANSINCLUDE
- #define KMEANSINCLUDE
- #include <core/basics/Exception.h>
- #include <core/basics/Config.h>
- #include <core/vector/Distance.h>
- #include "core/vector/VectorT.h"
- #include "core/vector/MatrixT.h"
- #include <core/vector/Distance.h>
- #include "ClusterAlgorithm.h"
- namespace OBJREC {
-
- class KMeans : public ClusterAlgorithm
- {
- protected:
-
-
-
-
-
- int noClusters;
-
-
- std::string distanceType;
-
-
- NICE::VectorDistance<double> *distancefunction;
-
-
- double d_minDelta;
-
-
- int i_maxIterations;
-
-
-
-
-
- double vectorDistance(const NICE::Vector &vector1, const NICE::Vector &vector2, uint distancetype);
-
-
- double compute_assignments ( const NICE::VVector & features,
- const NICE::VVector & prototypes,
- std::vector<int> & assignment );
-
- double compute_weights ( const NICE::VVector & features,
- std::vector<double> & weights,
- std::vector<int> & assignment );
-
- double compute_delta ( const NICE::VVector & oldprototypes,
- const NICE::VVector & prototypes );
-
- int compute_prototypes ( const NICE::VVector & features,
- NICE::VVector & prototypes,
- std::vector<double> & weights,
- const std::vector<int> & assignment );
-
-
- void initial_guess ( const NICE::VVector & features,
- NICE::VVector & prototypes );
-
- void print_iteration ( int iterations,
- NICE::VVector & prototypes,
- double delta );
- public:
-
-
-
-
-
- KMeans ( );
-
- KMeans( const int & _noClusters , const std::string & _distanceMode="euclidean");
-
-
- KMeans( const NICE::Config * _conf, const std::string & _confSection = "KMeans");
-
- virtual ~KMeans();
-
-
-
- void initFromConfig ( const NICE::Config * _conf, const std::string & _confSection = "KMeans");
-
-
-
-
-
-
-
- void cluster ( const NICE::VVector & features,
- NICE::VVector & prototypes,
- std::vector<double> & weights,
- std::vector<int> & assignment );
-
-
-
-
-
-
- void restore ( std::istream & is, int format = 0 );
-
- void store ( std::ostream & os, int format = 0 ) const;
-
- void clear ();
- };
- }
- #endif
|