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

Generalize covariance RNG type #450

Merged
merged 1 commit into from
Sep 5, 2023
Merged
Changes from all commits
Commits
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
23 changes: 12 additions & 11 deletions include/albatross/src/utils/random_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ void gaussian_fill(Eigen::Matrix<_Scalar, _Rows, _Cols> &matrix) {
gaussian_fill(matrix, 0., 1., rng);
}

template <typename Distribution>
template <typename Distribution, typename RandomNumberGenerator>
inline Eigen::MatrixXd
random_covariance_matrix(Eigen::Index k, Distribution &eigen_value_distribution,
std::default_random_engine &gen) {
RandomNumberGenerator &gen) {

Eigen::MatrixXd Q(k, k);
gaussian_fill(Q, gen);
Expand All @@ -116,16 +116,17 @@ random_covariance_matrix(Eigen::Index k, Distribution &eigen_value_distribution,
return Q * diag.asDiagonal() * Q.transpose();
}

inline Eigen::MatrixXd
random_covariance_matrix(Eigen::Index k, std::default_random_engine &gen) {
template <typename RandomNumberGenerator>
inline Eigen::MatrixXd random_covariance_matrix(Eigen::Index k,
RandomNumberGenerator &gen) {
std::gamma_distribution<double> distribution(1.0, 1.0);
return random_covariance_matrix(k, distribution, gen);
}

inline Eigen::VectorXd
random_multivariate_normal(const Eigen::VectorXd &mean,
const Eigen::MatrixXd &cov,
std::default_random_engine &gen) {
template <typename RandomNumberGenerator>
inline Eigen::VectorXd random_multivariate_normal(const Eigen::VectorXd &mean,
const Eigen::MatrixXd &cov,
RandomNumberGenerator &gen) {
std::normal_distribution<double> dist;
ALBATROSS_ASSERT(mean.size() == cov.rows());
ALBATROSS_ASSERT(cov.rows() == cov.cols());
Expand All @@ -140,9 +141,9 @@ random_multivariate_normal(const Eigen::VectorXd &mean,
return sample;
}

inline Eigen::VectorXd
random_multivariate_normal(const Eigen::MatrixXd &cov,
std::default_random_engine &gen) {
template <typename RandomNumberGenerator>
inline Eigen::VectorXd random_multivariate_normal(const Eigen::MatrixXd &cov,
RandomNumberGenerator &gen) {
return random_multivariate_normal(Eigen::VectorXd::Zero(cov.rows()), cov,
gen);
}
Expand Down
Loading