kde_stat.h

00001 /* MLPACK 0.2
00002  *
00003  * Copyright (c) 2008, 2009 Alexander Gray,
00004  *                          Garry Boyer,
00005  *                          Ryan Riegel,
00006  *                          Nikolaos Vasiloglou,
00007  *                          Dongryeol Lee,
00008  *                          Chip Mappus, 
00009  *                          Nishant Mehta,
00010  *                          Hua Ouyang,
00011  *                          Parikshit Ram,
00012  *                          Long Tran,
00013  *                          Wee Chin Wong
00014  *
00015  * Copyright (c) 2008, 2009 Georgia Institute of Technology
00016  *
00017  * This program is free software; you can redistribute it and/or
00018  * modify it under the terms of the GNU General Public License as
00019  * published by the Free Software Foundation; either version 2 of the
00020  * License, or (at your option) any later version.
00021  *
00022  * This program is distributed in the hope that it will be useful, but
00023  * WITHOUT ANY WARRANTY; without even the implied warranty of
00024  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00025  * General Public License for more details.
00026  *
00027  * You should have received a copy of the GNU General Public License
00028  * along with this program; if not, write to the Free Software
00029  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00030  * 02110-1301, USA.
00031  */
00032 #ifndef KDE_STAT_H
00033 #define KDE_STAT_H
00034 
00035 template<typename TKernel>
00036 class VKdeStat {
00037  public:
00038 
00042   TKernel min_bandwidth_kernel_;
00043 
00047   TKernel max_bandwidth_kernel_;
00048 
00051   double weight_sum_;
00052 
00056   double mass_l_;
00057   
00061   double mass_u_;
00062   
00066   double used_error_;
00067   
00071   double n_pruned_;
00072 
00075   double postponed_l_;
00076   
00079   double postponed_e_;
00080 
00083   double postponed_u_;
00084 
00088   double postponed_used_error_;
00089 
00094   double postponed_n_pruned_;
00095 
00098   double get_weight_sum() {
00099     return weight_sum_;
00100   }
00101 
00104   void AddPostponed(const VKdeStat& parent_stat) {
00105     postponed_l_ += parent_stat.postponed_l_;
00106     postponed_e_ += parent_stat.postponed_e_;
00107     postponed_u_ += parent_stat.postponed_u_;
00108     postponed_used_error_ += parent_stat.postponed_used_error_;
00109     postponed_n_pruned_ += parent_stat.postponed_n_pruned_;
00110   }
00111 
00114   void ClearPostponed() {      
00115     postponed_l_ = 0;
00116     postponed_e_ = 0;
00117     postponed_u_ = 0;
00118     postponed_used_error_ = 0;
00119     postponed_n_pruned_ = 0;      
00120   }
00121 
00124   void RefineBoundStatistics(const VKdeStat &left_child_stat,
00125                              const VKdeStat &right_child_stat) {
00126     mass_l_ = std::min(left_child_stat.mass_l_ + left_child_stat.postponed_l_,
00127                        right_child_stat.mass_l_ +
00128                        right_child_stat.postponed_l_);
00129     mass_u_ = std::max(left_child_stat.mass_u_ + left_child_stat.postponed_u_,
00130                        right_child_stat.mass_u_ +
00131                        right_child_stat.postponed_u_);
00132     used_error_ =
00133       std::max(left_child_stat.used_error_ +
00134                left_child_stat.postponed_used_error_,
00135                right_child_stat.used_error_ +
00136                right_child_stat.postponed_used_error_);
00137     n_pruned_ = 
00138       std::min(left_child_stat.n_pruned_ + left_child_stat.postponed_n_pruned_,
00139                right_child_stat.n_pruned_ + right_child_stat.n_pruned_);
00140   }
00141 
00144   void ResetBoundStatistics() {
00145     mass_l_ = DBL_MAX;
00146     mass_u_ = -DBL_MAX;
00147     used_error_ = 0;
00148     n_pruned_ = DBL_MAX;
00149   }
00150 
00153   void Init() {
00154     weight_sum_ = 0;
00155     mass_l_ = 0;
00156     mass_u_ = 0;
00157     used_error_ = 0;
00158     n_pruned_ = 0;
00159      
00160     postponed_l_ = 0;
00161     postponed_e_ = 0;
00162     postponed_u_ = 0;
00163     postponed_used_error_ = 0;
00164     postponed_n_pruned_ = 0;
00165   }
00166     
00167   void Init(const Matrix& dataset, index_t &start, index_t &count) {
00168     Init();
00169   }
00170     
00171   void Init(const Matrix& dataset, index_t &start, index_t &count,
00172             const VKdeStat& left_stat, const VKdeStat& right_stat) {
00173     Init();
00174   }
00175   
00176   VKdeStat() {
00177   }
00178     
00179   ~VKdeStat() {
00180   }
00181     
00182 };
00183 
00184 template<typename TKernelAux>
00185 class KdeStat {
00186  public:
00187   
00191   double mass_l_;
00192   
00196   double mass_u_;
00197   
00201   double used_error_;
00202   
00206   double n_pruned_;
00207 
00210   double postponed_l_;
00211   
00214   double postponed_e_;
00215 
00218   double postponed_u_;
00219 
00223   double postponed_used_error_;
00224 
00229   double postponed_n_pruned_;
00230 
00234   typename TKernelAux::TFarFieldExpansion farfield_expansion_;
00235     
00238   typename TKernelAux::TLocalExpansion local_expansion_;
00239 
00242   double get_weight_sum() {
00243     return farfield_expansion_.get_weight_sum();
00244   }
00245  
00248   void AddPostponed(const KdeStat& parent_stat) {
00249     postponed_l_ += parent_stat.postponed_l_;
00250     postponed_e_ += parent_stat.postponed_e_;
00251     postponed_u_ += parent_stat.postponed_u_;
00252     postponed_used_error_ += parent_stat.postponed_used_error_;
00253     postponed_n_pruned_ += parent_stat.postponed_n_pruned_;
00254   }
00255 
00258   void ClearPostponed() {      
00259     postponed_l_ = 0;
00260     postponed_e_ = 0;
00261     postponed_u_ = 0;
00262     postponed_used_error_ = 0;
00263     postponed_n_pruned_ = 0;      
00264   }
00265 
00268   void RefineBoundStatistics(const KdeStat &left_child_stat,
00269                              const KdeStat &right_child_stat) {
00270     mass_l_ = std::min(left_child_stat.mass_l_ + left_child_stat.postponed_l_,
00271                        right_child_stat.mass_l_ +
00272                        right_child_stat.postponed_l_);
00273     mass_u_ = std::max(left_child_stat.mass_u_ + left_child_stat.postponed_u_,
00274                        right_child_stat.mass_u_ +
00275                        right_child_stat.postponed_u_);
00276     used_error_ =
00277       std::max(left_child_stat.used_error_ +
00278                left_child_stat.postponed_used_error_,
00279                right_child_stat.used_error_ +
00280                right_child_stat.postponed_used_error_);
00281     n_pruned_ = 
00282       std::min(left_child_stat.n_pruned_ + left_child_stat.postponed_n_pruned_,
00283                right_child_stat.n_pruned_ + right_child_stat.n_pruned_);
00284   }
00285 
00288   void ResetBoundStatistics() {
00289     mass_l_ = DBL_MAX;
00290     mass_u_ = -DBL_MAX;
00291     used_error_ = 0;
00292     n_pruned_ = DBL_MAX;
00293   }
00294 
00297   void Init() {
00298     mass_l_ = 0;
00299     mass_u_ = 0;
00300     used_error_ = 0;
00301     n_pruned_ = 0;
00302      
00303     postponed_l_ = 0;
00304     postponed_e_ = 0;
00305     postponed_u_ = 0;
00306     postponed_used_error_ = 0;
00307     postponed_n_pruned_ = 0;
00308   }
00309     
00310   void Init(const TKernelAux &ka) {
00311     farfield_expansion_.Init(ka);
00312     local_expansion_.Init(ka);
00313   }
00314     
00315   void Init(const Matrix& dataset, index_t &start, index_t &count) {
00316     Init();
00317   }
00318     
00319   void Init(const Matrix& dataset, index_t &start, index_t &count,
00320             const KdeStat& left_stat,
00321             const KdeStat& right_stat) {
00322     Init();
00323   }
00324     
00325   void Init(const Vector& center, const TKernelAux &ka) {
00326       
00327     farfield_expansion_.Init(center, ka);
00328     local_expansion_.Init(center, ka);
00329     Init();
00330   }
00331     
00332   KdeStat() { }
00333     
00334   ~KdeStat() { }
00335     
00336 };
00337 
00338 #endif
Generated on Mon Jan 24 12:04:38 2011 for FASTlib by  doxygen 1.6.3