From bf53e2bf7d0ccc2719aa9e5a55a1d97cbc9958c7 Mon Sep 17 00:00:00 2001 From: Dongryeol Lee Date: Mon, 19 May 2008 18:45:17 +0000 Subject: [PATCH] Initial checkin of the matrix-factorized FMM --- .../dongryel/matrix_factorized_fmm/build.py | 42 ++++++++++ .../matrix_factorized_fmm.h | 82 +++++++++++++++++++ .../matrix_factorized_fmm_impl.h | 37 +++++++++ .../matrix_factorized_fmm_stat.h | 71 ++++++++++++++++ .../proximity_project/subspace_stat.h | 2 +- 5 files changed, 233 insertions(+), 1 deletion(-) create mode 100644 fastlib2/contrib/dongryel/matrix_factorized_fmm/build.py create mode 100644 fastlib2/contrib/dongryel/matrix_factorized_fmm/matrix_factorized_fmm.h create mode 100644 fastlib2/contrib/dongryel/matrix_factorized_fmm/matrix_factorized_fmm_impl.h create mode 100644 fastlib2/contrib/dongryel/matrix_factorized_fmm/matrix_factorized_fmm_stat.h diff --git a/fastlib2/contrib/dongryel/matrix_factorized_fmm/build.py b/fastlib2/contrib/dongryel/matrix_factorized_fmm/build.py new file mode 100644 index 0000000000..f0625f9211 --- /dev/null +++ b/fastlib2/contrib/dongryel/matrix_factorized_fmm/build.py @@ -0,0 +1,42 @@ +# Library build rule for the series expansion implementation +librule( + name = "series_expansion", + sources = ["series_expansion_aux.cc"], + headers = ["cur_decomposition.h", + "farfield_expansion.h", + "farfield_expansion_impl.h", + "matrix_factorized_farfield_expansion.h", + "matrix_factorized_farfield_expansion_impl.h", + "mult_farfield_expansion.h", + "mult_farfield_expansion_impl.h", + "kernel_aux.h", + "local_expansion.h", + "local_expansion_impl.h", + "matrix_factorized_local_expansion.h", + "matrix_factorized_local_expansion_impl.h", + "mult_local_expansion.h", + "mult_local_expansion_impl.h", + "mult_series_expansion_aux.h", + "series_expansion_aux.h", + "mult_series_expansion_aux.h"], + deplibs = ["fastlib:fastlib_int"] + ) + +# Test driver for series expansion library +binrule( + name = "main", + sources = ["main.cc"], + headers = [], + deplibs = [":series_expansion"] + ) + +# to build: +# 1. make sure have environment variables set up: +# $ source /full/path/to/fastlib/script/fl-env /full/path/to/fastlib +# (you might want to put this in bashrc) +# 2. fl-build main +# - this automatically will assume --mode=check, the default +# - type fl-build --help for help +# 3. ./main +# - to build same target again, type: make +# - to force recompilation, type: make clean diff --git a/fastlib2/contrib/dongryel/matrix_factorized_fmm/matrix_factorized_fmm.h b/fastlib2/contrib/dongryel/matrix_factorized_fmm/matrix_factorized_fmm.h new file mode 100644 index 0000000000..2f8aeebcf7 --- /dev/null +++ b/fastlib2/contrib/dongryel/matrix_factorized_fmm/matrix_factorized_fmm.h @@ -0,0 +1,82 @@ +/** @file matrix_factorized_fmm.h + * + * This file implements a prototype algorithm for computing the + * pairwise summation using a matrix-factorized formulation of fast + * multipole methods. + * + * @author Dongryeol Lee (dongryel) + * @bug In progress + */ + +#ifndef MATRIX_FACTORIZED_FMM_H +#define MATRIX_FACTORIZED_FMM_H + +#include "matrix_factorized_farfield_expansion.h" +#include "matrix_factorized_local_expansion.h" +#include "fastlib/fastlib.h" + +#define INSIDE_MATRIX_FACTORIZED_FMM_IMPL_H + + + +template +class MatrixFactorizedFMM { + + private: + +#include "matrix_factorized_fmm_stat.h" + + ////////// Private Member Variables ////////// + + /** @brief The module holding the parameters. + */ + struct datanode *module_; + + /** @brief Series expansion auxilary object. + */ + TKernelAux ka_; + + /** @brief The reference dataset. + */ + Matrix reference_set_; + + /** @brief The reference weights. + */ + Vector reference_weights_; + + /** @brief The root of the reference tree. + */ + ReferenceTree *reference_tree_root_; + + /** @brief The permutation mapping indices of reference_set_ to its + * original order. + */ + ArrayList old_from_new_references_; + + ////////// Private Member Functions ////////// + + /** @brief The exhaustive base case for evaluating the reference + * contributions to the given set of query points. + */ + void BaseCase_(const Matrix &query_set, + const ArrayList &query_index_permutation, + const QueryTree *query_node, + const ReferenceTree *reference_node, + Vector &query_kernel_sums) const; + + public: + + /** @brief Initializes the fast multipole method with the given + * reference set. + * + * @param references The reference set. + * @param module_in The module holding the parameters. + */ + void Init(const Matrix &references, struct datanode *module_in); + +}; + +#include "matrix_factorized_fmm_impl.h" +#undef INSIDE_MATRIX_FACTORIZED_FMM_IMPL_H + +#endif diff --git a/fastlib2/contrib/dongryel/matrix_factorized_fmm/matrix_factorized_fmm_impl.h b/fastlib2/contrib/dongryel/matrix_factorized_fmm/matrix_factorized_fmm_impl.h new file mode 100644 index 0000000000..dfd9a5e7ba --- /dev/null +++ b/fastlib2/contrib/dongryel/matrix_factorized_fmm/matrix_factorized_fmm_impl.h @@ -0,0 +1,37 @@ +#ifndef INSIDE_MATRIX_FACTORIZED_FMM_IMPL_H +#error "This is not a public header file!" +#endif + +template +void MatrixFactorizedFMM::BaseCase_ +(const Matrix &query_set, const ArrayList &query_index_permutation, + const QueryTree *query_node, const ReferenceTree *reference_node, + Vector &query_kernel_sums) const { + + + // Loop over each query point in the query node. + for(index_t q = query_node->begin(); q < query_node->end(); q++) { + + // Get the pointer to the current query point. + const double *query_point = query_set.GetColumnPtr(q); + + // Loop over each reference point in the reference node. + for(index_t r = reference_node->begin(); r < reference_node->end(); + r++) { + + // Get the pointer to the current reference point. + const double *reference_point = reference_set_.GetColumnPtr(r); + + // Compute the pairwise distance and kernel value. + double squared_distance = la::DistanceSqEuclidean(query_set.n_rows(), + query_point, + reference_point); + double weighted_kernel_value = reference_weights_[r] * + ka_.kernel_.EvalUnnormOnSq(squared_distance); + + query_kernel_sums[query_index_permutation[q]] += weighted_kernel_value; + + } // end of iterating over each reference point. + + } // end of looping over each query point. +} diff --git a/fastlib2/contrib/dongryel/matrix_factorized_fmm/matrix_factorized_fmm_stat.h b/fastlib2/contrib/dongryel/matrix_factorized_fmm/matrix_factorized_fmm_stat.h new file mode 100644 index 0000000000..ef0c203b94 --- /dev/null +++ b/fastlib2/contrib/dongryel/matrix_factorized_fmm/matrix_factorized_fmm_stat.h @@ -0,0 +1,71 @@ +#ifndef INSIDE_MATRIX_FACTORIZED_FMM_IMPL_H +#error "This is not a public header file!" +#endif + +class MatrixFactorizedFMMReferenceNodeStat { + public: + + /** @brief The default constructor. + */ + MatrixFactorizedFMMReferenceNodeStat() { + } + + /** @brief The default destructor. + */ + ~MatrixFactorizedFMMReferenceNodeStat() {} + + /** @brief Far field expansion created by the reference points in + * this node. + */ + typename TKernelAux::TFarFieldExpansion farfield_expansion_; + + void Init(const TKernelAux &ka) { + farfield_expansion_.Init(ka); + } + + void Init(const Matrix& dataset, index_t &start, index_t &count) { + } + + void Init(const Matrix& dataset, index_t &start, index_t &count, + const MatrixFactorizedFMMReferenceNodeStat& left_stat, + const MatrixFactorizedFMMReferenceNodeStat& right_stat) { + } + +}; + +class MatrixFactorizedFMMQueryNodeStat { + public: + + /** @brief The default constructor. + */ + MatrixFactorizedFMMQueryNodeStat() { + } + + /** @brief The default destructor. + */ + ~MatrixFactorizedFMMQueryNodeStat() {} + + /** @brief The local expansion for the query points in this node. + */ + typename TKernelAux::TFarFieldExpansion local_expansion_; + + void Init(const TKernelAux &ka) { + local_expansion_.Init(ka); + } + + void Init(const Matrix& dataset, index_t &start, index_t &count) { + } + + void Init(const Matrix& dataset, index_t &start, index_t &count, + const MatrixFactorizedFMMQueryNodeStat& left_stat, + const MatrixFactorizedFMMQueryNodeStat& right_stat) { + } +}; + +/** @brief The type of our query tree. + */ +typedef BinarySpaceTree, Matrix, MatrixFactorizedFMMQueryNodeStat > QueryTree; + +/** @brief The type of our reference tree. + */ +typedef BinarySpaceTree, Matrix, MatrixFactorizedFMMReferenceNodeStat > ReferenceTree; diff --git a/fastlib2/contrib/dongryel/proximity_project/subspace_stat.h b/fastlib2/contrib/dongryel/proximity_project/subspace_stat.h index ec5990f0e8..de98d25e62 100644 --- a/fastlib2/contrib/dongryel/proximity_project/subspace_stat.h +++ b/fastlib2/contrib/dongryel/proximity_project/subspace_stat.h @@ -7,7 +7,7 @@ class SubspaceStat { private: - static const double epsilon_ = 0.01; + static const double epsilon_ = 0.1; static void ComputeResidualBasis_(const Matrix &first_basis, const Matrix &second_basis,