X-Boost  2.3.8
WeightedPattern.h
Go to the documentation of this file.
1 /* XBoost: Ada-Boost and Friends on Haar/ICF/HOG Features, Library and ToolBox
2  *
3  * Copyright (c) 2008-2014 Paolo Medici <medici@ce.unipr.it>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20 
21 #ifndef _WPATTERN_H
22 #define _WPATTERN_H
23 
27 #include "Pattern.h"
28 #include "DataSet.h"
29 #include <iostream> // cout debug
30 
31 // NOTE those data are used inside train algorithm (internal use)
32 // TODO: convert totally Pattern ?
33 
41 template<class Descriptor>
42 struct WeightedPattern: public Pattern<Descriptor> {
43 
45  double d;
46 
48  int test;
49 
50 public:
51 
52  WeightedPattern() : d(0.0) { }
53  WeightedPattern(const Pattern<Descriptor> & src) : Pattern<Descriptor>(src), d(0.0) { }
54  WeightedPattern(const Descriptor & des, int cat) : Pattern<Descriptor>(des, cat), d(0.0) { }
55 
58  float GetWeightedCategory() const {
59  return d * (float) Pattern<Descriptor>::category ;
60  }
61 
64  inline bool correct() const {
66  }
67 };
68 
69 
74 template<class DataSet>
75 void ResetWeight(DataSet & list, double priori_knownledge)
76 {
77  if(priori_knownledge>0.0)
78  {
79  double A = priori_knownledge;
80  double B = 1.0 - priori_knownledge;
81  double dA = A/(list.n_patternP);
82  double dB = B/(list.n_patternN);
83  std::cout << "Initialize weight with " << dA<< " for " << list.n_patternP << " positives, " << dB << " for " << list.n_patternN << " negatives, " << list.Size() << " total patterns." << std::endl;
84  for(unsigned int i =0; i<list.Size(); i++)
85  list.templates[i].d = (list.templates[i].category==1) ? dA : dB;
86  }
87  else
88  {
89 // initialize m_d
90  double d0 = 1.0 / (double) list.Size();
91  std::cout << "Initialize weight with " << d0 << " for " << list.Size() << " patterns" << std::endl;
92  for(unsigned int i =0; i<list.Size(); i++)
93  list.templates[i].d = d0;
94  }
95 
96 }
97 
98 
99 #endif
void ResetWeight(DataSet &list, double priori_knownledge)
Definition: WeightedPattern.h:75
unsigned int n_patternP
Definition: DataSet.h:70
Definition: Pattern.h:39
double d
Current weight associated to this pattern.
Definition: WeightedPattern.h:45
Definition: DataSet.h:33
unsigned int Size() const
Return number of allocated samples (complete size of DataSet)
Definition: DataSet.h:101
ListType templates
a collection of Pattern used in this dataset
Definition: DataSet.h:73
implement the generic pattern object
bool correct() const
Definition: WeightedPattern.h:64
Definition: WeightedPattern.h:42
int test
Result on the last evaluate (-1,0,1) of Weak Classifier (binary problem)
Definition: WeightedPattern.h:48
declare a DataSet
float GetWeightedCategory() const
Definition: WeightedPattern.h:58