All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Groups
cholesky_corr_free.hpp
Go to the documentation of this file.
#ifndef STAN_MATH_PRIM_MAT_FUN_CHOLESKY_CORR_FREE_HPP
#define STAN_MATH_PRIM_MAT_FUN_CHOLESKY_CORR_FREE_HPP
#include <stan/math/prim/mat/err/check_square.hpp>
#include <stan/math/prim/mat/fun/Eigen.hpp>
#include <stan/math/prim/scal/fun/corr_constrain.hpp>
#include <stan/math/prim/scal/fun/square.hpp>
#include <stan/math/prim/scal/fun/corr_free.hpp>
#include <cmath>
namespace stan {
namespace math {
template <typename T>
Eigen::Matrix<T, Eigen::Dynamic, 1>
cholesky_corr_free(const Eigen::Matrix
<T, Eigen::Dynamic, Eigen::Dynamic>& x) {
using std::sqrt;
using Eigen::Matrix;
using Eigen::Dynamic;
using stan::math::square;
stan::math::check_square("cholesky_corr_free", "x", x);
// should validate lower-triangular, unit lengths
int K = (x.rows() * (x.rows() - 1)) / 2;
Matrix<T, Dynamic, 1> z(K);
int k = 0;
for (int i = 1; i < x.rows(); ++i) {
z(k++) = corr_free(x(i, 0));
double sum_sqs = square(x(i, 0));
for (int j = 1; j < i; ++j) {
z(k++) = corr_free(x(i, j) / sqrt(1.0 - sum_sqs));
sum_sqs += square(x(i, j));
}
}
return z;
}
}
}
#endif
stan::math::cholesky_corr_free
Eigen::Matrix< T, Eigen::Dynamic, 1 > cholesky_corr_free(const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &x)
Definition: cholesky_corr_free.hpp:18
stan::math::sqrt
fvar< T > sqrt(const fvar< T > &x)
Definition: sqrt.hpp:15
stan::math::corr_free
T corr_free(const T y)
Return the unconstrained scalar that when transformed to a valid correlation produces the specified v...
Definition: corr_free.hpp:29
square.hpp
stan::math::square
fvar< T > square(const fvar< T > &x)
Definition: square.hpp:15
corr_constrain.hpp
Eigen.hpp
stan::math::check_square
bool check_square(const char *function, const char *name, const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y)
Return true if the specified matrix is square.
Definition: check_square.hpp:28
check_square.hpp
corr_free.hpp

[ Stan Home Page ] © 2011–2015, Stan Development Team.