gen_metric_tree.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  */
00043 #ifndef TREE_GEN_METRIC_TREE_H
00044 #define TREE_GEN_METRIC_TREE_H
00045 
00046 #include "general_spacetree.h"
00047 
00048 #include "fastlib/base/common.h"
00049 #include "fastlib/col/arraylist.h"
00050 #include "fastlib/fx/fx.h"
00051 
00052 #include "gen_metric_tree_impl.h"
00053 
00057 namespace proximity {
00058 
00075   template<typename TMetricTree>
00076   TMetricTree *MakeGenMetricTree(Matrix& matrix, index_t leaf_size,
00077                                  ArrayList<index_t> *old_from_new = NULL,
00078                                  ArrayList<index_t> *new_from_old = NULL) {
00079 
00080     TMetricTree *node = new TMetricTree();
00081     index_t *old_from_new_ptr;
00082 
00083     if (old_from_new) {
00084       old_from_new->Init(matrix.n_cols());
00085       
00086       for (index_t i = 0; i < matrix.n_cols(); i++) {
00087         (*old_from_new)[i] = i;
00088       }
00089       
00090       old_from_new_ptr = old_from_new->begin();
00091     } else {
00092       old_from_new_ptr = NULL;
00093     }
00094 
00095     node->Init(0, matrix.n_cols());
00096     node->bound().center().Init(matrix.n_rows());
00097     tree_gen_metric_tree_private::SplitGenMetricTree<TMetricTree>
00098       (matrix, node, leaf_size, old_from_new_ptr);
00099     
00100     if (new_from_old) {
00101       new_from_old->Init(matrix.n_cols());
00102       for (index_t i = 0; i < matrix.n_cols(); i++) {
00103         (*new_from_old)[(*old_from_new)[i]] = i;
00104       }
00105     }
00106     
00107     return node;
00108   }
00109 
00110 };
00111 
00112 #endif
Generated on Mon Jan 24 12:04:38 2011 for FASTlib by  doxygen 1.6.3