Class prob_dens_mdim_gaussian (o2scl)¶
-
template<class vec_t = boost::numeric::ublas::vector<double>, class mat_t = boost::numeric::ublas::matrix<double>>
class prob_dens_mdim_gaussian : public o2scl::prob_dens_mdim<boost::numeric::ublas::vector<double>>¶ A multi-dimensional Gaussian probability density function using a Cholesky decomposition.
Given a (square) covariance matrix, \( \Sigma \), and a mean vector \( \mu \) the PDF is
\[ P(x) = \det \left( 2 \pi \Sigma \right)^{-1/2} \exp \left[ -\frac{1}{2} (x-\mu)^T \Sigma^{-1} (x-\mu) \right] \]Given the Cholesky decomposition \( A A^{T} = \Sigma \), and a vector, \( z \) of samples from the standard Gaussian with 0 mean and unit variance, one can create a sample \( x \) from \( x = \mu + A z \) .
A separate class for the two-dimensional case is in prob_dens_mdim_biv_gaussian .
Note
This class inverts the matrix, necessary for computing the pdf, but not for sampling the distribution, so for large matrices the inversion can be a waste of computation if the pdf is not needed.
Note
Note that, for example, a LU decomposition does not work for this class because a Cholesky decomposition (or a spectral decomposition) is required for sampling. For this reason, we cannot use a generic o2scl::matrix_invert_det object. However, we still could use Cholesky decompositions from armadillo or Eigen.
Subclassed by o2scl::prob_dens_mdim_bound_gaussian< vec_t, mat_t >
Set functions
-
template<class mat2_t, class vec2_t, class mat2_col_t = const_matrix_column_gen<mat2_t>>
inline int set_ret_wgts(size_t p_mdim, size_t n_pts, const mat2_t &pts, const vec2_t &wgts, vec_t &peak_arg, mat_t &covar_arg)¶ Create a distribution from a set of weighted samples from a multidimensional Gaussian, returning the peak values and covariance matrix.
The matrix
pts
should have a size ofn_pts
in the first index andp_mdim
in the second index
-
template<class mat2_t, class mat2_col_t = const_matrix_column_gen<mat2_t>>
inline int set_ret(size_t p_mdim, size_t n_pts, const mat2_t &pts, vec_t &peak_arg, mat_t &covar_arg)¶ Create a distribution from a set of samples from a multidimensional Gaussian, returning the peak values and covariance matrix.
The matrix
pts
should have a size ofn_pts
in the first index andp_mdim
in the second index
-
template<class mat2_t, class vec2_t, class mat2_col_t = const_matrix_column_gen<mat2_t>>
inline int set_wgts(size_t p_mdim, size_t n_pts, const mat2_t &pts, const vec2_t &wgts)¶ Create a distribution from a set of weighted samples from a multidimensional Gaussian.
The matrix
pts
should have a size ofn_pts
in the first index andp_mdim
in the second index
-
template<class mat2_t, class mat2_col_t = const_matrix_column_gen<mat2_t>>
inline int set(size_t p_mdim, size_t n_pts, const mat2_t &pts)¶ Create a distribution from a set of samples from a multidimensional Gaussian.
The matrix
pts
should have a size ofn_pts
in the first index andp_mdim
in the second index
-
inline int set_covar(size_t p_ndim, vec_t &p_peak, mat_t &covar)¶
Set the peak and covariance matrix for the distribution.
Note
This function is called in constructors and thus should not be virtual.
-
inline int set_from_biv(prob_dens_mdim_biv_gaussian<vec_t> &pdmbg)¶
Set the probability distribution from a bivariate Gaussian.
-
inline void set_alt(size_t p_ndim, vec_t &p_peak, mat_t &p_chol, mat_t &p_covar_inv, double p_norm)¶
Alternate set function for use when covariance matrix has already been decomposed and inverted.
-
template<class vec_vec_t, class mat_col_t, class func_t>
inline void set_gproc(size_t n_dim, size_t n_init, vec_vec_t &x, vec_t &y, func_t &fcovar)¶ Given a data set and a covariance function, construct probability distribution based on a Gaussian process.
- Idea for Future:
Clarify the relationship between this and interpm_krige.
Note
The type
mat_col_t
is a matrix column type for the internal object matrix typemat_t
, and not associated with the data typevec_vec_t
. Since the default matrix type isboost::numeric::ublas::matrix < double >
a good matrix column type for this function isboost::numeric::ublas::matrix_column < boost::numeric::ublas::matrix < double > >
. This matrix column type is needed for the LU decomposition and inversion.
Generic methods for multidimensional prob. dists.
-
inline prob_dens_mdim_biv_gaussian<vec_t> make_biv() const¶
Create a bivariate Gaussian probability distribution.
Public Functions
-
inline virtual int read_generic(std::istream &fin)¶
Read the distribution from an input file.
-
inline virtual int write_generic(std::ostream &fout)¶
Write the Gaussian to a generic output file.
-
template<class mat2_t>
inline void get_covar(mat2_t &m) const¶ Get the covariance matrix.
The covariance matrix is not stored. This function computes it directly from the Cholesky decomposition.
-
inline double get_norm() const¶
Get the normalization.
-
inline virtual size_t dim() const¶
The dimensionality.
-
inline prob_dens_mdim_gaussian()¶
Create an empty distribution.
-
inline virtual ~prob_dens_mdim_gaussian()¶
-
inline prob_dens_mdim_gaussian(const prob_dens_mdim_gaussian &pdmg_loc)¶
Copy constructor.
-
inline prob_dens_mdim_gaussian(size_t p_ndim, vec_t &p_peak, mat_t &covar)¶
Create a distribution from the covariance matrix.
-
inline prob_dens_mdim_gaussian &operator=(const prob_dens_mdim_gaussian &pdmg_loc)¶
Copy constructor with operator=.
Public Members
-
int verbose¶
Verbosity parameter (default 0)
-
o2scl::prob_dens_gaussian pdg¶
Standard normal .
-
bool err_nonconv¶
If true, call the error handler when convergence fails.
-
template<class mat2_t, class vec2_t, class mat2_col_t = const_matrix_column_gen<mat2_t>>