123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- #ifndef CodebookRandomForestINCLUDE
- #define CodebookRandomForestINCLUDE
- #include "core/vector/VVector.h"
- #include "vislearning/features/simplefeatures/Codebook.h"
- #include "vislearning/classifier/fpclassifier/randomforest/FPCRandomForests.h"
- #include <string>
- namespace OBJREC {
- class CodebookRandomForest : public Codebook
- {
- protected:
-
- std::map<DecisionNode *, int> leafMap;
-
- FPCRandomForests *clusterforest;
-
- int maxDepth;
-
- int restrictedCodebookSize;
-
- void buildParentStructure ( DecisionNode *node,
- std::map<DecisionNode *, DecisionNode *> & parentStructure );
-
- void pruneForest ();
-
- void buildLeafMap ();
- public:
-
- CodebookRandomForest( int maxDepth, int restrictedCodebookSize = 0 );
-
-
- CodebookRandomForest( FPCRandomForests *clusterforest, int maxDepth, int restrictedCodebookSize = 0 );
-
-
- virtual ~CodebookRandomForest();
-
-
- void setClusterForest( FPCRandomForests *clusterforest);
-
-
- void vote ( const NICE::Vector & feature, int & codebookEntry, double & weight, double & distance ) const;
- virtual void voteVQ ( const NICE::Vector & feature, int & codebookEntry, double & weight, double & distance ) const
- {
- this->vote(feature,codebookEntry, weight, distance);
- }
- void vote ( const NICE::Vector & feature, NICE::Vector & histogram, int & codebookEntry, double & weight, double & distance ) const;
- virtual void voteVQ (const NICE::Vector &feature, NICE::Vector &histogram, int & codebookEntry, double & weight, double & distance ) const {
- this->vote(feature, histogram, codebookEntry, weight, distance);
- }
- virtual void voteVA ( const NICE::Vector & feature, NICE::Vector & votes ) const {
- int codebookEntry = 0;
- double weight = 0.0f;
- double distance = 0.0f;
- this->vote(feature, votes, codebookEntry, weight, distance);
- }
-
-
- void vote ( const NICE::Vector & feature, NICE::SparseVector & votes ) const;
-
- void voteAndClassify ( const NICE::Vector & feature, NICE::SparseVector & votes, FullVector & distribution ) const;
-
- void voteAndClassify ( const NICE::Vector & feature, NICE::SparseVector & votes, NICE::Vector & distribution ) const;
- virtual void voteVA ( const NICE::Vector & feature, NICE::SparseVector & votes ) const {
- this->vote(feature, votes);
- }
-
-
- bool allowsMultipleVoting () { return true; }
-
- FPCRandomForests *getRandomForest (void) { return clusterforest; }
- void add ( const Codebook *codebook );
- void copy ( const Codebook *codebook );
- Codebook *clone () const;
-
- void clear ();
-
- void restore ( std::istream & is, int format = 0);
-
- void store ( std::ostream & os, int format = 0) const;
- int getMaxDepth() const
- {
- return this->maxDepth;
- }
- int getRestrictedCodebookSize() const
- {
- return restrictedCodebookSize;
- }
- };
- }
- #endif
|