bazar  1.3.1
image_classification_node.h
Go to the documentation of this file.
1 /*
2 Copyright 2005, 2006 Computer Vision Lab,
3 Ecole Polytechnique Federale de Lausanne (EPFL), Switzerland.
4 All rights reserved.
5 
6 This file is part of BazAR.
7 
8 BazAR is free software; you can redistribute it and/or modify it under the
9 terms of the GNU General Public License as published by the Free Software
10 Foundation; either version 2 of the License, or (at your option) any later
11 version.
12 
13 BazAR is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15 PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License along with
18 BazAR; if not, write to the Free Software Foundation, Inc., 51 Franklin
19 Street, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21 #ifndef IMAGE_CLASSIFICATION_NODE_H
22 #define IMAGE_CLASSIFICATION_NODE_H
23 
24 #include <fstream>
25 #include <iostream>
26 #include <vector>
27 
28 using namespace std;
29 
30 #include <math.h>
31 #include "image_class_example.h"
32 
34 
35 
41 {
42 public:
45  image_classification_node(int depth, int class_number, image_classification_node * parent = 0);
46 
47  friend ostream& operator<< (ostream& o, const image_classification_node& node);
48  friend istream& operator>> (istream& i, image_classification_node& node);
49 
50  void add_example(image_class_example * pv);
51 
52  bool should_stop_recursion(void);
53  void end_recursion(void);
54  void expand(void);
55  void premature_end_recursion(void);
56 
57  bool is_leaf(void) const;
58  int leaves_number(void);
59  int node_number(void);
60  int subtree_depth(void);
61  void set_Dot(int image_width, int image_height);
62  void set_Dot(int _du1, int _dv1, int _du2, int _dv2, int image_width, int image_height);
63  bool fall_in_child(image_class_example * pv, int child_index);
64  int dot_product(image_class_example * pv) const;
65  int child_index(image_class_example * pv) const;
66 
67  void reestimate_probabilities_recursive(float * weights = 0);
68  void restore_occurances_recursive(float * weights = 0);
69  void reset_class_occurances_recursive(int class_index);
70  void save_probability_sums_recursive(std::ofstream& wfs);
71  void load_probability_sums_recursive(std::ifstream& wfs);
72 
73  float projection(image_class_example * pv) const;
74 
75  void change_class_number_and_reset_probabilities(int new_class_number);
76 
77  int represented_class_number(void) const;
78 
79  void print_name(void);
80  ostream& name(ostream& o) const;
81 
82  int nb_examples() { if (examples == 0) return 0; else return int(examples->size()); }
83 
84  const int children_number;
85  int d1, d2, du1, dv1, du2, dv2;
86  bool leaf;
89  int depth, index;
90 
91  int * children_index; // for tree loading only
92 
93  float * P;
95  float P_sum;
96 
98 
99  vector<image_class_example *> *examples;
100 
102 };
103 
104 inline bool image_classification_node::is_leaf(void) const
105 {
106  return leaf;
107 }
108 
109 extern int global_patch_size;
110 
111 ostream& operator<< (ostream& o, const image_classification_node& node);
112 istream& operator>> (istream& i, image_classification_node& node);
113 
115 #endif // IMAGE_CLASSIFICATION_NODE_H