Computers hold a finite amount of precision by using (binary) scientific notation.
# NOTE: You should really use all.equal! (0.1 + 0.2) == 0.3
## [1] FALSE
Arbitrary-precision arithmetic
Note: Whenever possible, use a more accurate fixed-precision algorithm
\(W \sim W_p(n, \Sigma) \Rightarrow W = X^TX,\) \(X(i,) \sim N_p(0, \Sigma), i=1,\ldots,n.\)
Problem: For \(n,p\) large, both the determinant and the normalization constant are large.
R
packagesSome of the available options:
gmp
and Rmpfr
: Link to C/C++ librariesRyacas
: Interfaces with a Computer Algebra SystemBH
“Boost provides free peer-reviewed portable C++ source libraries.”
BH
allows R
users to work with these libraries.#include <boost/multiprecision/cpp_dec_float.hpp> using namespace boost::multiprecision; // Define new type with 100-digit precision typedef number<cpp_dec_float<100>> mp_float;
RcppEigen
“Eigen is a C++ template library for linear algebra”
#include <Eigen/Dense> Eigen::Matrix<mp_float,100,1> vec; // Compute dot product mp_float dot = vec.dot(vec);
rootWishart
: n=25, p=15, fixed precisionx <- seq(0, 100, length.out = 50) y <- rootWishart::singleWishart(x, p=15, n=25, type="fixed") plot(x, y, type = 'l', ylim = c(0,1))
rootWishart
: n=25, p=15, arbitrary precisionx <- seq(0, 100, length.out = 50) y <- rootWishart::singleWishart(x, p=15, n=25, type="arbitrary") plot(x, y, type = 'l', ylim = c(0,1))
BH
and RcppEigen
provides a lot of flexibility.C++
rootWishart