21 #ifndef _NAIVE_DECISION_STUMP_ORACLE_H
22 #define _NAIVE_DECISION_STUMP_ORACLE_H
36 struct detail_thread_naive_decision_stump {
43 template<
class FeatureGenerator,
class Aggregator >
77 void Thread_OptimizeClassifier(detail_thread_naive_decision_stump<WeakClassifierType> * ptr )
93 m_featureGenerator = &f;
113 return m_training_set;
124 void SetPreloadSize(
int n) {
128 void SetFastHeuristic(
bool enable,
bool reoptimize,
int size) {
139 pp = pn = nn = np = pz = nz = 0.0;
144 int value = h.response( getData1( *i, m_training_set), getData2( *i, m_training_set) );
147 if( i->category == 1)
170 double w1 = pp + nn + nz;
172 double w2 = pn + np + nz;
193 if(m_featureGenerator == 0)
195 std::cerr <<
"No Feature Generator loaded. Use SetFeatureGenerator API before call GetHypothesis" << std::endl;
199 bestH.debug_name(
"internal error");
202 if(m_training_set.Size() == 0)
204 std::cerr <<
"No pattern loaded. Init Trainer Failed" << std::endl;
208 if(m_threadCount<=1) m_threadCount = 1;
213 m_featureGenerator->
Reset();
217 detail_thread_naive_decision_stump<WeakClassifierType> * storage =
new detail_thread_naive_decision_stump<WeakClassifierType>[m_threadCount];
220 while( m_featureGenerator->
Next( storage[token].h ) )
223 if(token == m_threadCount)
230 for(
int i =0; i<m_threadCount; ++i)
231 thread_pool_.
create_thread(sprint::thread_bind(&NaiveDecisionStumpOracle::Thread_OptimizeClassifier,
this, &storage[i]));
236 Thread_OptimizeClassifier(&storage[0]);
239 for(
int i =0; i<m_threadCount; ++i)
242 double w = storage[i].w;
246 bestH = storage[i].h;
247 std::cout << count <<
" (" << (100.0f * (double)count/(
double)m_featureGenerator->
Count()) <<
"%): name:" << bestH.debug_name() <<
" w+:"<< bestW << std::endl;
250 if((count & (32*1024-1))==0)
252 float fs = count/t.GetTime();
253 float pr = (float)count/(
float)m_featureGenerator->
Count();
254 int rem = (m_featureGenerator->
Count() - count)/fs;
255 std::cout << fs <<
" feature/secs: " << (100.0f * pr) <<
"% ";
257 std::cout << rem <<
"s remaining" << std::endl;
259 std::cout << rem/60 <<
"min remaining" << std::endl;
271 for(
int i =0; i<token; ++i)
272 thread_pool_.
create_thread(sprint::thread_bind(&NaiveDecisionStumpOracle::Thread_OptimizeClassifier,
this, &storage[i]));
277 Thread_OptimizeClassifier(&storage[0]);
280 for(
int i =0; i<token; ++i)
283 double w = storage[i].w;
287 bestH = storage[i].h;
288 std::cout << count <<
" (" << (100.0f * (double)count/(
double)m_featureGenerator->
Count()) <<
"%): name:" << bestH.debug_name() <<
" w+:"<< bestW << std::endl;
329 std::cout <<
"Expected W:" << bestW<< std::endl;
Feature FeatureType
The feature type generate by this generator.
Definition: FeatureGenerator.h:41
A classifier composed by a Feature Extractor and an Evaluation Policy A "Second Level" classifier...
Definition: BinaryClassifier.h:38
DataSetHandle< Aggregator > & GetTrainingSet()
return R/W the training set
Definition: NaiveDecisionStumpOracle.h:111
A very simple decision stump with threshold 0 (could be a more luminance insesitive) Implements the c...
virtual void Reset()=0
reset any interal counters
Definition: FeatureGenerator.h:36
void SetFeatureGenerator(FeatureGenerator &f)
Associate a Feature Generator to Decision Stump Generator.
Definition: NaiveDecisionStumpOracle.h:91
Definition: thread_group.h:82
image/size TODO namespace
Definition: Types.h:39
void join_all()
wait all threads terminate
Definition: thread_group.h:114
void SetNumberOfThreads(int th)
Change the thread number used in Multi Threading training.
Definition: NaiveDecisionStumpOracle.h:117
BinaryClassifier< FeatureType, NaiveDecisionStump > WeakClassifierType
The weak classifier.
Definition: NaiveDecisionStumpOracle.h:53
BoostableClassifier< WeakClassifierType > ClassifierType
The weak classifier reported by this oracle.
Definition: NaiveDecisionStumpOracle.h:56
double Optimize(WeakClassifierType &h)
Definition: NaiveDecisionStumpOracle.h:134
virtual bool Next(Feature &out)=0
return the next feature, or return false
bool create_thread(const sprint::thread_function &p)
create an additional thread
Definition: thread_group.h:102
FeatureGenerator::FeatureType FeatureType
The Feature Extracted by FeatureGenerator.
Definition: NaiveDecisionStumpOracle.h:50
Definition: BoostableClassifier.h:40
virtual unsigned int Count() const =0
return the count of feature available
Definition: NaiveDecisionStumpOracle.h:44
void SetTrainingSet(const DataSetHandle< Aggregator > &set)
Set the training set used to recover the threshold.
Definition: NaiveDecisionStumpOracle.h:85