Series expansion library being integrated into the new library.

This commit is contained in:
Dongryeol Lee
2011-01-17 02:27:23 +00:00
parent 423666288e
commit a09e5ca18f
12 changed files with 88 additions and 71 deletions
@@ -4,8 +4,7 @@
# It sets TRILINOS_INCLUDE_DIR and TRILINOS_LIBS and also finds MPI_INCLUDE_DIR
## Location of trilinos
set(TRILINOS_LIB_DIR /usr/local/lib CACHE PATH
"Directory where trilinos is installed.")
set(TRILINOS_LIB_DIR $ENV{HOME}/local/trilinos-10.6.2/lib)
## library
if(NOT "${TRILINOS_REQUIRED_LIBS}") # some defaults
@@ -35,17 +34,16 @@ foreach(lib ${TRILINOS_REQUIRED_LIBS})
endforeach()
## include dirs
message(STATUS "Finding ${TRILINOS_LIB_DIR}/../include")
find_path(TRILINOS_INCLUDE_DIR Trilinos_version.h
PATHS
${TRILINOS_LIB_DIR}/../include
/opt/trilinos/include
PATH_SUFFIXES
trilinos
${TRILINOS_LIB_DIR}/../include
CMAKE_FIND_ROOT_PATH_BOTH
)
if(TRILINOS_INCLUDE_DIR AND TRILINOS_LIBS)
set(TRILINOS_FOUND "YES")
message(STATUS "Found trilinos libraries.")
message(STATUS "Found trilinos libraries in ${TRILINOS_LIBS}.")
message(STATUS "Found trilinos headers in ${TRILINOS_INCLUDE_DIR}")
else()
message(FATAL_ERROR "Couldn't find trilinos.")
@@ -55,9 +53,7 @@ mark_as_advanced(TRILINOS_INCLUDE_DIR trilinos_lib)
find_path(MPI_INCLUDE_DIR mpi.h
PATHS
$ENV{HOME}/local/openmpi-1.4.3/include
PATH_SUFFIXES
mpi
openmpi
CMAKE_FIND_ROOT_PATH_BOTH
)
if(MPI_INCLUDE_DIR)
set(MPI_FOUND "YES")
@@ -9,7 +9,7 @@ project(FASTLIB C CXX Fortran)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMake")
# find LAPACK
find_package(LAPACK REQUIRED) # LAPACK finds BLAS as a dependency
# find_package(LAPACK REQUIRED) # LAPACK finds BLAS as a dependency
# find pthreads
find_package(Pthreads REQUIRED)
@@ -16,9 +16,6 @@ add_subdirectory(util)
add_library(core ${CORE_SRCS})
target_link_libraries(core
armadillo
lapack
blas
gsl
gslcblas
pthread
@@ -52,7 +52,7 @@ class Timer {
double GetElapsedTime(int checkpoint_id) {
timeval result;
timersub(&checkpoints_[checkpoint_id], &start_, &result);
return (result.tv_sec + static_cast<double>(result.tv_usec) / 1000000.0);
return (result.tv_sec + (double)(result.tv_usec) / 1000000.0);
}
private:
@@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 2.8)
project(FASTLIB C CXX Fortran)
add_subdirectory(kde)
add_subdirectory(distributed_kde)
add_subdirectory(kde)
add_subdirectory(mixed_logit_dcm)
add_subdirectory(series_expansion)
@@ -20,7 +20,6 @@ double MixedLogitDCM<TableType>::SimulationError_(
// Assumption: num_active_people in both samples are equal.
double simulation_error = 0;
// Lastly divide by squared of the number of active people.
simulation_error /=
core::math::Sqr(static_cast<double>(first_sample.num_active_people()));
@@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 2.8)
# test executable
add_executable(series_expansion-test
EXCLUDE_FROM_ALL
series_expansion.test.cc
)
# link dependencies of test executable
target_link_libraries(series_expansion-test
core
${Boost_LIBRARIES}
)
@@ -1,15 +1,24 @@
/** @file series_expansion_aux.h
/** @file cartesian_expansion_global.h
*
* @author Dongryeol Lee (dongryel@cc.gatech.edu)
*/
#ifndef SERIES_EXPANSION_AUX
#define SERIES_EXPANSION_AUX
#ifndef MLPACK_SERIES_EXPANSION_SERIES_EXPANSION_GLOBAL_H
#define MLPACK_SERIES_EXPANSION_SERIES_EXPANSION_GLOBAL_H
#include "fastlib/fastlib.h"
#include "core/table/dense_matrix.h"
#include "core/table/dense_point.h"
#include "mlpack/series_expansion/cartesian_expansion_type.h"
/**
* Series expansion class.
namespace mlpack {
namespace series_expansion {
/** @brief The set of global mappings and constants necessary for
* performing a Cartesian series expansion of a pairwise
* kernel.
*/
class SeriesExpansionAux {
template<enum mlpack::series_expansion::CartesianExpansionType::Type>
class CartesianExpansionGlobal {
private:
@@ -17,15 +26,15 @@ class SeriesExpansionAux {
int max_order_;
Vector factorials_;
core::table::DensePoint factorials_;
ArrayList<int> list_total_num_coeffs_;
Vector inv_multiindex_factorials_;
core::table::DensePoint inv_multiindex_factorials_;
Vector neg_inv_multiindex_factorials_;
core::table::DensePoint neg_inv_multiindex_factorials_;
Matrix multiindex_combination_;
core::table::DenseMatrix multiindex_combination_;
ArrayList< ArrayList<short int> > multiindex_mapping_;
@@ -44,21 +53,7 @@ class SeriesExpansionAux {
ArrayList< ArrayList<short int> > upper_mapping_index_;
/** row index is for n, column index is for k */
Matrix n_choose_k_;
OT_DEF_BASIC(SeriesExpansionAux) {
OT_MY_OBJECT(dim_);
OT_MY_OBJECT(max_order_);
OT_MY_OBJECT(factorials_);
OT_MY_OBJECT(list_total_num_coeffs_);
OT_MY_OBJECT(inv_multiindex_factorials_);
OT_MY_OBJECT(neg_inv_multiindex_factorials_);
OT_MY_OBJECT(multiindex_combination_);
OT_MY_OBJECT(multiindex_mapping_);
OT_MY_OBJECT(lower_mapping_index_);
OT_MY_OBJECT(upper_mapping_index_);
OT_MY_OBJECT(n_choose_k_);
}
core::table::DenseMatrix n_choose_k_;
public:
@@ -169,7 +164,6 @@ class SeriesExpansionAux {
} // end of i-loop
}
// getters and setters
double factorial(int k) const {
return factorials_[k];
}
@@ -182,7 +176,7 @@ class SeriesExpansionAux {
int get_max_total_num_coeffs() const;
const Vector& get_inv_multiindex_factorials() const;
const core::table::DensePoint& get_inv_multiindex_factorials() const;
const ArrayList< short int > * get_lower_mapping_index() const;
@@ -192,7 +186,7 @@ class SeriesExpansionAux {
const ArrayList< short int > * get_multiindex_mapping() const;
const Vector& get_neg_inv_multiindex_factorials() const;
const core::table::DensePoint& get_neg_inv_multiindex_factorials() const;
double get_n_choose_k(int n, int k) const;
@@ -231,8 +225,9 @@ class SeriesExpansionAux {
/**
* Print useful information about this object
*/
void PrintDebug(const char *name = "", FILE *stream = stderr) const;
void Print(const char *name = "", FILE *stream = stderr) const;
};
}
}
#endif
@@ -1,4 +1,15 @@
#include "series_expansion_aux.h"
/** @file cartesian_expansion_global.h
*
* @author Dongryeol Lee (dongryel@cc.gatech.edu)
*/
#ifndef MLPACK_SERIES_EXPANSION_SERIES_EXPANSION_GLOBAL_DEV_H
#define MLPACK_SERIES_EXPANSION_SERIES_EXPANSION_GLOBAL_DEV_H
#include "mlpack/series_expansion/cartesian_expansion_global.h"
namespace mlpack {
namespace series_expansion {
const Vector& SeriesExpansionAux::get_inv_multiindex_factorials() const {
return inv_multiindex_factorials_;
@@ -188,3 +199,7 @@ void SeriesExpansionAux::PrintDebug(const char *name, FILE *stream) const {
}
fprintf(stream, "\n");
}
}
}
#endif
@@ -182,10 +182,10 @@ class CartesianFarField {
* expansion for any query point within the specified region
* for a given bound.
*/
template<typename TBound>
template<typename BoundType>
int OrderForEvaluating(
const TBound &far_field_region,
const TBound &local_field_region,
const BoundType &far_field_region,
const BoundType &local_field_region,
double min_dist_sqd_regions,
double max_dist_sqd_regions,
double max_error, double *actual_error) const;
@@ -199,10 +199,10 @@ class CartesianFarField {
* @return the minimum approximation order required for the error,
* -1 if approximation up to the maximum order is not possible.
*/
template<typename TBound>
template<typename BoundType>
int OrderForConvertingToLocal(
const TBound &far_field_region,
const TBound &local_field_region,
const BoundType &far_field_region,
const BoundType &local_field_region,
double min_dist_sqd_regions,
double max_dist_sqd_regions,
double required_bound,
@@ -222,7 +222,7 @@ class CartesianFarField {
* coefficients are added up to the passed-in local
* expansion coefficients.
*/
void TranslateToLocal(LocalExpansion<TKernelAux> &se, int truncation_order);
void TranslateToLocal(int truncation_order, LocalExpansion<TKernelAux> *se);
};
}
}
@@ -10,12 +10,14 @@
#ifndef MLPACK_SERIES_EXPANSION_CARTESIAN_FARFIELD_DEV_H
#define MLPACK_SERIES_EXPANSION_CARTESIAN_FARFIELD_DEV_H
#include "mlpack/series_expansion/cartesian_expansion_global.h"
#include "mlpack/series_expansion/cartesian_farfield.h"
namespace mlpack {
namespace series_expansion {
template<TKernelAux>
void CartesianFarField<TKernelAux>::Accumulate(
void CartesianFarField::Accumulate(
const CartesianExpansionGlobal &sea,
const core::table::DensePoint &v, double weight, int order) {
int dim = v.length();
@@ -87,7 +89,7 @@ void CartesianFarField<TKernelAux>::Accumulate(
}
template<typename TKernelAux>
void CartesianFarField<TKernelAux>::AccumulateCoeffs(
void CartesianFarField::AccumulateCoeffs(
const core::table::DenseMatrix& data,
const core::table::DensePoint& weights,
int begin, int end, int order) {
@@ -166,7 +168,7 @@ void CartesianFarField<TKernelAux>::AccumulateCoeffs(
}
template<typename TKernelAux>
void CartesianFarField<TKernelAux>::RefineCoeffs(
void CartesianFarField::RefineCoeffs(
const core::table::DenseMatrix& data,
const core::table::DensePoint& weights,
int begin, int end, int order) {
@@ -243,13 +245,13 @@ void CartesianFarField<TKernelAux>::RefineCoeffs(
}
template<typename TKernelAux>
double CartesianFarField<TKernelAux>::EvaluateField(
double CartesianFarField::EvaluateField(
const core::table::DenseMatrix& data, int row_num, int order) const {
return EvaluateField(data.GetColumnPtr(row_num), order);
}
template<typename TKernelAux>
double CartesianFarField<TKernelAux>::EvaluateField(
double CartesianFarField::EvaluateField(
const double *x_q, int order) const {
// dimension
@@ -305,8 +307,8 @@ double CartesianFarField<TKernelAux>::EvaluateField(
}
template<typename TKernelAux>
void CartesianFarField<TKernelAux>::Init(const core::table::DensePoint& center,
const TKernelAux &ka) {
void CartesianFarField::Init(const core::table::DensePoint& center,
const TKernelAux &ka) {
// copy kernel type, center, and bandwidth squared
kernel_ = &(ka.kernel_);
@@ -321,7 +323,7 @@ void CartesianFarField<TKernelAux>::Init(const core::table::DensePoint& center,
}
template<typename TKernelAux>
void CartesianFarField<TKernelAux>::Init(const TKernelAux &ka) {
void CartesianFarField::Init(const TKernelAux &ka) {
// copy kernel type, center, and bandwidth squared
kernel_ = &(ka.kernel_);
@@ -338,7 +340,7 @@ void CartesianFarField<TKernelAux>::Init(const TKernelAux &ka) {
template<typename TKernelAux>
template<typename TBound>
int CartesianFarField<TKernelAux>::OrderForEvaluating
int CartesianFarField::OrderForEvaluating
(const TBound &far_field_region,
const TBound &local_field_region, double min_dist_sqd_regions,
double max_dist_sqd_regions, double max_error, double *actual_error) const {
@@ -352,7 +354,7 @@ int CartesianFarField<TKernelAux>::OrderForEvaluating
template<typename TKernelAux>
template<typename TBound>
int CartesianFarField<TKernelAux>::
int CartesianFarField::
OrderForConvertingToLocal(const TBound &far_field_region,
const TBound &local_field_region,
double min_dist_sqd_regions,
@@ -368,7 +370,7 @@ OrderForConvertingToLocal(const TBound &far_field_region,
}
template<typename TKernelAux>
void CartesianFarField<TKernelAux>::Print(
void CartesianFarField::Print(
const char *name, FILE *stream) const {
int dim = sea_->get_dimension();
@@ -417,7 +419,7 @@ void CartesianFarField<TKernelAux>::Print(
}
template<typename TKernelAux>
void CartesianFarField<TKernelAux>::TranslateFromFarField(
void CartesianFarField::TranslateFromFarField(
const CartesianFarField &se) {
double bandwidth_factor = ka_->BandwidthFactor(se.bandwidth_sq());
@@ -509,8 +511,8 @@ void CartesianFarField<TKernelAux>::TranslateFromFarField(
}
template<typename TKernelAux>
void CartesianFarField<TKernelAux>::TranslateToLocal(
CartesianLocal<TKernelAux> &se, int truncation_order) {
void CartesianFarField::TranslateToLocal(
CartesianLocal &se, int truncation_order) {
core::table::DensePoint pos_arrtmp, neg_arrtmp;
core::table::DenseMatrix derivative_map;