00001 #ifndef rgrl_data_manager_h
00002 #define rgrl_data_manager_h
00003
00004
00005
00006
00007
00008
00009 #include <rgrl/rgrl_estimator_sptr.h>
00010 #include <rgrl/rgrl_feature_set_sptr.h>
00011 #include <rgrl/rgrl_matcher_sptr.h>
00012 #include <rgrl/rgrl_scale_estimator_sptr.h>
00013 #include <rgrl/rgrl_weighter_sptr.h>
00014 #include <rgrl/rgrl_estimator.h>
00015 #include <rgrl/rgrl_feature_set.h>
00016 #include <rgrl/rgrl_matcher.h>
00017 #include <rgrl/rgrl_scale_estimator.h>
00018 #include <rgrl/rgrl_weighter.h>
00019 #include <rgrl/rgrl_object.h>
00020
00021 #include <vcl_vector.h>
00022 #include <vcl_map.h>
00023 #include <vcl_string.h>
00024
00025
00026
00027
00028
00029
00030
00031
00032 class rgrl_data_manager_data_item
00033 {
00034 public:
00035 rgrl_data_manager_data_item( rgrl_feature_set_sptr in_from_set,
00036 rgrl_feature_set_sptr in_to_set,
00037 rgrl_matcher_sptr in_matcher,
00038 rgrl_weighter_sptr in_weighter,
00039 rgrl_scale_estimator_unwgted_sptr in_unwgted_scale_est,
00040 rgrl_scale_estimator_wgted_sptr in_wgted_scale_est,
00041 const vcl_string& in_label = vcl_string() )
00042 : from_set( in_from_set ),
00043 to_set( in_to_set ),
00044 matcher( in_matcher ),
00045 unwgted_scale_est( in_unwgted_scale_est ),
00046 wgted_scale_est( in_wgted_scale_est ),
00047 weighter( in_weighter ),
00048 label( in_label )
00049 {
00050 }
00051
00052 rgrl_feature_set_sptr from_set;
00053 rgrl_feature_set_sptr to_set;
00054 rgrl_matcher_sptr matcher;
00055 rgrl_scale_estimator_unwgted_sptr unwgted_scale_est;
00056 rgrl_scale_estimator_wgted_sptr wgted_scale_est;
00057 rgrl_weighter_sptr weighter;
00058 vcl_string label;
00059 };
00060
00061
00062
00063
00064
00065
00066
00067 class rgrl_data_manager_data_storage
00068 {
00069 public:
00070 typedef vcl_vector< rgrl_data_manager_data_item > data_vector;
00071 typedef vcl_map< unsigned, data_vector > data_map;
00072 typedef vcl_vector< rgrl_estimator_sptr > estimator_vector;
00073 typedef vcl_map< unsigned, estimator_vector > estimator_map;
00074
00075
00076 data_vector& operator[]( unsigned i )
00077 {
00078 return map_[i];
00079 }
00080
00081
00082 data_vector const& operator[]( unsigned i ) const
00083 {
00084 return map_.find( i )->second;
00085 }
00086
00087
00088 bool has(unsigned i ) const
00089 {
00090 return map_.find( i ) != map_.end();
00091 }
00092
00093
00094 void add_estimator( unsigned i, rgrl_estimator_sptr estimator)
00095 {
00096 estimators_[i].push_back( estimator );
00097 }
00098
00099
00100 bool has_estimator_hierarchy(unsigned i ) const
00101 {
00102 return estimators_.find( i ) != estimators_.end();
00103 }
00104
00105
00106 estimator_vector const& estimator_hierarchy(unsigned i) const
00107 {
00108 return estimators_.find( i )->second;
00109 }
00110
00111
00112 void set_dimension_increase_for_next_stage( unsigned i, double rate)
00113 {
00114 dim_increase_for_next_stage_[i] = rate;
00115 }
00116
00117
00118 double dimension_increase_for_next_stage(unsigned i) const
00119 {
00120 return dim_increase_for_next_stage_.find( i )->second;
00121 }
00122
00123 private:
00124 data_map map_;
00125 estimator_map estimators_;
00126 vcl_map< unsigned, double > dim_increase_for_next_stage_;
00127 };
00128
00129
00130
00131
00132
00133 class rgrl_data_manager: public rgrl_object
00134 {
00135 public:
00136
00137
00138
00139
00140
00141
00142
00143 rgrl_data_manager( bool multi_stage = false );
00144
00145 ~rgrl_data_manager();
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160 void add_data( unsigned stage,
00161 rgrl_feature_set_sptr from_set,
00162 rgrl_feature_set_sptr to_set,
00163 rgrl_matcher_sptr matcher = 0,
00164 rgrl_weighter_sptr weighter = 0,
00165 rgrl_scale_estimator_unwgted_sptr unwgted_scale_est = 0,
00166 rgrl_scale_estimator_wgted_sptr wgted_scale_est = 0,
00167 const vcl_string& label = vcl_string() );
00168
00169
00170
00171
00172
00173 void add_data( rgrl_feature_set_sptr from_set,
00174 rgrl_feature_set_sptr to_set,
00175 rgrl_matcher_sptr matcher = 0,
00176 rgrl_weighter_sptr weighter = 0,
00177 rgrl_scale_estimator_unwgted_sptr unwgted_scale_est = 0,
00178 rgrl_scale_estimator_wgted_sptr wgted_scale_est = 0,
00179 const vcl_string& label = vcl_string() );
00180
00181
00182 void add_estimator( unsigned stage,
00183 rgrl_estimator_sptr estimator);
00184
00185
00186
00187
00188
00189 void add_estimator( rgrl_estimator_sptr estimator);
00190
00191
00192
00193
00194
00195 void set_dimension_increase_for_next_stage( unsigned stage, double rate);
00196
00197
00198 double dimension_increase_for_next_stage(unsigned stage) const;
00199
00200
00201
00202 bool is_multi_feature() const;
00203
00204
00205
00206 void
00207 get_data_at_stage( unsigned stage,
00208 vcl_vector<rgrl_feature_set_sptr> & from_sets,
00209 vcl_vector<rgrl_feature_set_sptr> & to_sets,
00210 vcl_vector<rgrl_matcher_sptr> & matchers,
00211 vcl_vector<rgrl_weighter_sptr> & weighters,
00212 vcl_vector<rgrl_scale_estimator_unwgted_sptr> & unwgted_scale_ests,
00213 vcl_vector<rgrl_scale_estimator_wgted_sptr> & wgted_scale_ests,
00214 vcl_vector<rgrl_estimator_sptr> & estimators) const;
00215
00216
00217
00218 void
00219 get_data_at_stage( unsigned stage,
00220 rgrl_feature_set_sptr & from_sets,
00221 rgrl_feature_set_sptr & to_sets,
00222 rgrl_matcher_sptr & matchers,
00223 rgrl_weighter_sptr & weighters,
00224 rgrl_scale_estimator_unwgted_sptr & unwgted_scale_ests,
00225 rgrl_scale_estimator_wgted_sptr & wgted_scale_ests,
00226 vcl_vector<rgrl_estimator_sptr> & estimators) const;
00227
00228
00229
00230
00231 void
00232 get_data( vcl_vector<rgrl_feature_set_sptr> & from_sets,
00233 vcl_vector<rgrl_feature_set_sptr> & to_sets,
00234 vcl_vector<rgrl_matcher_sptr> & matchers,
00235 vcl_vector<rgrl_weighter_sptr> & weighters,
00236 vcl_vector<rgrl_scale_estimator_unwgted_sptr> & unwgted_scale_ests,
00237 vcl_vector<rgrl_scale_estimator_wgted_sptr> & wgted_scale_ests,
00238 vcl_vector<rgrl_estimator_sptr> & estimators) const;
00239
00240
00241
00242
00243 void
00244 get_data( rgrl_feature_set_sptr & from_sets,
00245 rgrl_feature_set_sptr & to_sets,
00246 rgrl_matcher_sptr & matchers,
00247 rgrl_weighter_sptr & weighters,
00248 rgrl_scale_estimator_unwgted_sptr & unwgted_scale_ests,
00249 rgrl_scale_estimator_wgted_sptr & wgted_scale_ests,
00250 vcl_vector<rgrl_estimator_sptr> & estimators) const;
00251
00252
00253 void get_label( unsigned stage, vcl_vector<vcl_string>& labels ) const;
00254
00255
00256 void get_label( vcl_vector<vcl_string>& labels ) const;
00257
00258
00259 bool has_stage(unsigned i ) const;
00260
00261
00262 rgrl_type_macro( rgrl_data_manager, rgrl_object );
00263
00264 private:
00265 void generate_defaults(rgrl_matcher_sptr& matcher,
00266 rgrl_weighter_sptr& weighter,
00267 rgrl_scale_estimator_unwgted_sptr& unwgted_scale_est );
00268
00269 private:
00270 rgrl_data_manager_data_storage data_;
00271 bool multi_stage_;
00272 bool multi_feature_;
00273 };
00274
00275 #endif