Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable GNC Optimizer #1572

Merged
merged 35 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
d0b3f1d
code for computing quantile of chi-squared distribution
varunagrawal May 10, 2023
8201c77
refactor IncompleteGamma class
varunagrawal May 10, 2023
d577160
Simplified IncompleteGamma
varunagrawal May 10, 2023
7ce5684
remove recursion for Halley update
varunagrawal May 10, 2023
a807127
update GncOptimizer and make it available
varunagrawal May 11, 2023
6fb3f0f
use templated is_nan check
varunagrawal May 11, 2023
d614fda
try older version
varunagrawal May 11, 2023
64c2850
switch from IndexVector to FastVector<size_t> now that pybind/stl.h i…
varunagrawal Jul 10, 2023
a5fd9c1
fix chi_squared_quantile
varunagrawal Jul 10, 2023
3641dd1
Merge branch 'develop' into chi-squared-quantile
varunagrawal Jul 10, 2023
00f5596
Revert "switch from IndexVector to FastVector<size_t> now that pybind…
varunagrawal Jul 10, 2023
7c935d9
small update to GNC IndexVector
varunagrawal Jul 10, 2023
1d9b83b
Merge branch 'develop' into chi-squared-quantile
varunagrawal Oct 18, 2023
dcb4299
rename GncHelpers to chiSquaredInverse and move to internal directory
varunagrawal Oct 19, 2023
e8817ae
rename other files accordingly
varunagrawal Oct 19, 2023
a46a78d
update paths
varunagrawal Oct 19, 2023
c8a0cdc
much improved chi_squared_quantile, incremental update
varunagrawal Oct 20, 2023
bebb275
compute initial guess for inverse gamma value
varunagrawal Oct 20, 2023
6f38616
gamma inverse functional
varunagrawal Oct 20, 2023
25ebdd5
add gamma_p_inverse_func
varunagrawal Oct 22, 2023
203a84d
add more gamma functions
varunagrawal Dec 27, 2023
87c5729
more code
varunagrawal Dec 27, 2023
4326195
cephes source code
varunagrawal Dec 28, 2023
3538488
refactor Cephes CMakeLists.txt to allow building from parent directory
varunagrawal Dec 28, 2023
5481159
Link to cephes from gtsam
varunagrawal Dec 28, 2023
ea81675
minor refactor to be consistent
varunagrawal Dec 28, 2023
3cde40d
OS-based improved support
varunagrawal Dec 28, 2023
5806f5f
add M_PI definition if unavailable (e.g. in Windows)
varunagrawal Dec 28, 2023
8db9e01
additional M_PI definitions
varunagrawal Dec 28, 2023
b1ce501
hopefully last of M_ definitions
varunagrawal Dec 28, 2023
70f1d4a
mark GTSAM_EXPORT and update docstring
varunagrawal Dec 28, 2023
98444ab
another windows fix
varunagrawal Dec 28, 2023
e0b8c52
kill testChiSquaredInverse
varunagrawal Dec 28, 2023
ba93dec
only used built in version of Cephes since there doesn't seem to be a…
varunagrawal Dec 29, 2023
687667a
minor formatting
varunagrawal Dec 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ include(cmake/HandleCCache.cmake) # ccache
include(cmake/HandleCPack.cmake) # CPack
include(cmake/HandleEigen.cmake) # Eigen3
include(cmake/HandleMetis.cmake) # metis
include(cmake/HandleCephes.cmake) # cephes
include(cmake/HandleMKL.cmake) # MKL
include(cmake/HandleOpenMP.cmake) # OpenMP
include(cmake/HandlePerfTools.cmake) # Google perftools
Expand Down
44 changes: 44 additions & 0 deletions cmake/HandleCephes.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# ##############################################################################
# Cephes library

# For both system or bundle version, a cmake target "cephes-gtsam-if" is defined
# (interface library)

option(
GTSAM_USE_SYSTEM_CEPHES
"Find and use system-installed cephes. If 'off', use the one bundled with GTSAM"
OFF)

if(GTSAM_USE_SYSTEM_CEPHES)
# # Debian package: libmetis-dev

# find_path(METIS_INCLUDE_DIR metis.h REQUIRED) find_library(METIS_LIBRARY
# metis REQUIRED)

# if(METIS_INCLUDE_DIR AND METIS_LIBRARY) mark_as_advanced(METIS_INCLUDE_DIR)
# mark_as_advanced(METIS_LIBRARY)

# add_library(cephes-gtsam-if INTERFACE)
# target_include_directories(cephes-gtsam-if BEFORE INTERFACE
# ${METIS_INCLUDE_DIR} # gtsam_unstable/partition/FindSeparator-inl.h uses
# internal metislib.h API # via extern "C"
# $<BUILD_INTERFACE:${GTSAM_SOURCE_DIR}/gtsam/3rdparty/metis/libmetis>
# $<BUILD_INTERFACE:${GTSAM_SOURCE_DIR}/gtsam/3rdparty/metis/GKlib> )
# target_link_libraries(cephes-gtsam-if INTERFACE ${METIS_LIBRARY}) endif()

else()
# Bundled version:
add_subdirectory(${GTSAM_SOURCE_DIR}/gtsam/3rdparty/cephes)

list(APPEND GTSAM_EXPORTED_TARGETS cephes-gtsam)

add_library(cephes-gtsam-if INTERFACE)
target_link_libraries(cephes-gtsam-if INTERFACE cephes-gtsam)

endif()

list(APPEND GTSAM_EXPORTED_TARGETS cephes-gtsam-if)
install(
TARGETS cephes-gtsam-if
EXPORT GTSAM-exports
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
123 changes: 123 additions & 0 deletions gtsam/3rdparty/cephes/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
cmake_minimum_required(VERSION 3.12)
enable_testing()
project(
cephes
DESCRIPTION "Cephes Mathematical Function Library"
VERSION 1.0.0
LANGUAGES C)

set(CEPHES_HEADER_FILES
cephes.h
cephes/cephes_names.h
cephes/dd_idefs.h
cephes/dd_real.h
cephes/dd_real_idefs.h
cephes/expn.h
cephes/igam.h
cephes/lanczos.h
cephes/mconf.h
cephes/polevl.h
cephes/sf_error.h)

# Add header files
install(FILES ${CEPHES_HEADER_FILES} DESTINATION include/gtsam/3rdparty/cephes)

set(CEPHES_SOURCES
cephes/airy.c
cephes/bdtr.c
cephes/besselpoly.c
cephes/beta.c
cephes/btdtr.c
cephes/cbrt.c
cephes/chbevl.c
cephes/chdtr.c
cephes/const.c
cephes/dawsn.c
cephes/dd_real.c
cephes/ellie.c
cephes/ellik.c
cephes/ellpe.c
cephes/ellpj.c
cephes/ellpk.c
cephes/erfinv.c
cephes/exp10.c
cephes/exp2.c
cephes/expn.c
cephes/fdtr.c
cephes/fresnl.c
cephes/gamma.c
cephes/gammasgn.c
cephes/gdtr.c
cephes/hyp2f1.c
cephes/hyperg.c
cephes/i0.c
cephes/i1.c
cephes/igam.c
cephes/igami.c
cephes/incbet.c
cephes/incbi.c
cephes/j0.c
cephes/j1.c
cephes/jv.c
cephes/k0.c
cephes/k1.c
cephes/kn.c
cephes/kolmogorov.c
cephes/lanczos.c
cephes/nbdtr.c
cephes/ndtr.c
cephes/ndtri.c
cephes/owens_t.c
cephes/pdtr.c
cephes/poch.c
cephes/psi.c
cephes/rgamma.c
cephes/round.c
cephes/sf_error.c
cephes/shichi.c
cephes/sici.c
cephes/sindg.c
cephes/sinpi.c
cephes/spence.c
cephes/stdtr.c
cephes/tandg.c
cephes/tukey.c
cephes/unity.c
cephes/yn.c
cephes/yv.c
cephes/zeta.c
cephes/zetac.c)

# Add library source files
add_library(cephes-gtsam SHARED ${CEPHES_SOURCES})

# Add include directory (aka headers)
target_include_directories(
cephes-gtsam BEFORE PUBLIC $<INSTALL_INTERFACE:include/gtsam/3rdparty/cephes/>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)

set_target_properties(
cephes-gtsam
PROPERTIES VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
C_STANDARD 99)

if(WIN32)
set_target_properties(
cephes-gtsam
PROPERTIES PREFIX ""
COMPILE_FLAGS /w
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/../../../bin")
endif()

if(APPLE)
set_target_properties(cephes-gtsam PROPERTIES INSTALL_NAME_DIR
"${CMAKE_INSTALL_PREFIX}/lib")
endif()

install(
TARGETS cephes-gtsam
EXPORT GTSAM-exports
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
163 changes: 163 additions & 0 deletions gtsam/3rdparty/cephes/cephes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
#ifndef CEPHES_H
#define CEPHES_H

#include "cephes/cephes_names.h"

#ifdef __cplusplus
extern "C" {
#endif

extern int airy(double x, double *ai, double *aip, double *bi, double *bip);

extern double bdtrc(double k, int n, double p);
extern double bdtr(double k, int n, double p);
extern double bdtri(double k, int n, double y);

extern double besselpoly(double a, double lambda, double nu);

extern double beta(double a, double b);
extern double lbeta(double a, double b);

extern double btdtr(double a, double b, double x);

extern double cbrt(double x);
extern double chbevl(double x, double array[], int n);
extern double chdtrc(double df, double x);
extern double chdtr(double df, double x);
extern double chdtri(double df, double y);
extern double dawsn(double xx);

extern double ellie(double phi, double m);
extern double ellik(double phi, double m);
extern double ellpe(double x);

extern int ellpj(double u, double m, double *sn, double *cn, double *dn, double *ph);
extern double ellpk(double x);
extern double exp10(double x);
extern double exp2(double x);

extern double expn(int n, double x);

extern double fdtrc(double a, double b, double x);
extern double fdtr(double a, double b, double x);
extern double fdtri(double a, double b, double y);

extern int fresnl(double xxa, double *ssa, double *cca);
extern double Gamma(double x);
extern double lgam(double x);
extern double lgam_sgn(double x, int *sign);
extern double gammasgn(double x);

extern double gdtr(double a, double b, double x);
extern double gdtrc(double a, double b, double x);
extern double gdtri(double a, double b, double y);

extern double hyp2f1(double a, double b, double c, double x);
extern double hyperg(double a, double b, double x);
extern double threef0(double a, double b, double c, double x, double *err);

extern double i0(double x);
extern double i0e(double x);
extern double i1(double x);
extern double i1e(double x);
extern double igamc(double a, double x);
extern double igam(double a, double x);
extern double igam_fac(double a, double x);
extern double igamci(double a, double q);
extern double igami(double a, double p);

extern double incbet(double aa, double bb, double xx);
extern double incbi(double aa, double bb, double yy0);

extern double iv(double v, double x);
extern double j0(double x);
extern double y0(double x);
extern double j1(double x);
extern double y1(double x);

extern double jn(int n, double x);
extern double jv(double n, double x);
extern double k0(double x);
extern double k0e(double x);
extern double k1(double x);
extern double k1e(double x);
extern double kn(int nn, double x);

extern double nbdtrc(int k, int n, double p);
extern double nbdtr(int k, int n, double p);
extern double nbdtri(int k, int n, double p);

extern double ndtr(double a);
extern double log_ndtr(double a);
extern double erfc(double a);
extern double erf(double x);
extern double erfinv(double y);
extern double erfcinv(double y);
extern double ndtri(double y0);

extern double pdtrc(double k, double m);
extern double pdtr(double k, double m);
extern double pdtri(int k, double y);

extern double poch(double x, double m);

extern double psi(double x);

extern double rgamma(double x);
extern double round(double x);

extern int shichi(double x, double *si, double *ci);
extern int sici(double x, double *si, double *ci);

extern double radian(double d, double m, double s);
extern double sindg(double x);
extern double sinpi(double x);
extern double cosdg(double x);
extern double cospi(double x);

extern double spence(double x);

extern double stdtr(int k, double t);
extern double stdtri(int k, double p);

extern double struve_h(double v, double x);
extern double struve_l(double v, double x);
extern double struve_power_series(double v, double x, int is_h, double *err);
extern double struve_asymp_large_z(double v, double z, int is_h, double *err);
extern double struve_bessel_series(double v, double z, int is_h, double *err);

extern double yv(double v, double x);

extern double tandg(double x);
extern double cotdg(double x);

extern double log1p(double x);
extern double log1pmx(double x);
extern double expm1(double x);
extern double cosm1(double x);
extern double lgam1p(double x);

extern double yn(int n, double x);
extern double zeta(double x, double q);
extern double zetac(double x);

extern double smirnov(int n, double d);
extern double smirnovi(int n, double p);
extern double smirnovp(int n, double d);
extern double smirnovc(int n, double d);
extern double smirnovci(int n, double p);
extern double kolmogorov(double x);
extern double kolmogi(double p);
extern double kolmogp(double x);
extern double kolmogc(double x);
extern double kolmogci(double p);

extern double lanczos_sum_expg_scaled(double x);

extern double owens_t(double h, double a);

#ifdef __cplusplus
}
#endif

#endif /* CEPHES_H */
Loading