naive_ortho_range_search.h

Go to the documentation of this file.
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  */
00040 #ifndef NAIVE_ORTHO_RANGE_SEARCH_H
00041 #define NAIVE_ORTHO_RANGE_SEARCH_H
00042 
00043 #include "fastlib/fastlib.h"
00044 
00045 
00059 template<typename T>
00060 class NaiveOrthoRangeSearch {
00061   
00062   // This class object cannot be copied!
00063   FORBID_ACCIDENTAL_COPIES(NaiveOrthoRangeSearch);
00064 
00065  private:
00066 
00069   GenMatrix<T> data_;
00070   
00071  public:
00072   
00074 
00077   NaiveOrthoRangeSearch() {}
00078 
00081   ~NaiveOrthoRangeSearch() {}
00082 
00084 
00089   void Init(const GenMatrix<T> &data) {
00090 
00091     // copy the incoming data
00092     data_.StaticCopy(data);
00093   }
00094 
00102   void Compute(const GenMatrix<T> &low_coord_limits, 
00103                const GenMatrix<T> &high_coord_limits,
00104                GenMatrix<bool> *search_results) {
00105 
00106     // Allocate the space for holding the search results.
00107     search_results->Init(data_.n_cols(), low_coord_limits.n_cols());
00108 
00109     // Start the search.
00110     fx_timer_start(NULL, "naive_search");
00111     for(index_t j = 0; j < low_coord_limits.n_cols(); j++) {
00112       for(index_t i = 0; i < data_.n_cols(); i++) {     
00113         GenVector<T> pt;
00114         bool flag = true;
00115         data_.MakeColumnVector(i, &pt);
00116         
00117         // Determine which one of the two cases we have: EXCLUDE, SUBSUME
00118         // first the EXCLUDE case: when dist is above the upper bound distance
00119         // of this dimension, or dist is below the lower bound distance of
00120         // this dimension
00121         for(index_t d = 0; d < data_.n_rows(); d++) {
00122           if(pt[d] < low_coord_limits.get(d, j) || 
00123              pt[d] > high_coord_limits.get(d, j)) {
00124             flag = false;
00125             break;
00126           }
00127         }
00128         (*search_results).set(i, j, flag);
00129       }
00130     }
00131     fx_timer_stop(NULL, "naive_search");
00132     
00133     // Search is now finished.
00134     
00135   }
00136 
00137 };
00138 
00139 
00140 #endif
Generated on Mon Jan 24 12:04:38 2011 for FASTlib by  doxygen 1.6.3