| Stan Math Library 2.12.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

factor_U.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_FACTOR_U_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_FACTOR_U_HPP
3
4 #include <stan/math/prim/mat/fun/Eigen.hpp>
5 #include <stan/math/prim/scal/fun/constants.hpp>
6
7 #include <cmath>
8 #include <cstddef>
9 #include <iostream>
10 #include <limits>
11 #include <stdexcept>
12 #include <sstream>
13 #include <vector>
14
15 namespace stan {
16 namespace math {
17
25 template<typename T>
26 void
27 factor_U(const Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>& U,
28 Eigen::Array<T, Eigen::Dynamic, 1>& CPCs) {
29 size_t K = U.rows();
30 size_t position = 0;
31 size_t pull = K - 1;
32
33 if (K == 2) {
34 CPCs(0) = atanh(U(0, 1));
35 return;
36 }
37
38 Eigen::Array<T, 1, Eigen::Dynamic> temp = U.row(0).tail(pull);
39
40 CPCs.head(pull) = temp;
41
42 Eigen::Array<T, Eigen::Dynamic, 1> acc(K);
43 acc(0) = -0.0;
44 acc.tail(pull) = 1.0 - temp.square();
45 for (size_t i = 1; i < (K - 1); i++) {
46 position += pull;
47 pull--;
48 temp = U.row(i).tail(pull);
49 temp /= sqrt(acc.tail(pull) / acc(i));
50 CPCs.segment(position, pull) = temp;
51 acc.tail(pull) *= 1.0 - temp.square();
52 }
53 CPCs = 0.5 * ( (1.0 + CPCs) / (1.0 - CPCs) ).log(); // now unbounded
54 }
55
56 }
57
58 }
59
60 #endif
stan::math::atanh
fvar< T > atanh(const fvar< T > &x)
Definition: atanh.hpp:13
stan::math::sqrt
fvar< T > sqrt(const fvar< T > &x)
Definition: sqrt.hpp:14
stan
Definition: log_sum_exp.hpp:8
stan::math::log
fvar< T > log(const fvar< T > &x)
Definition: log.hpp:14
stan::math::factor_U
void factor_U(const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &U, Eigen::Array< T, Eigen::Dynamic, 1 > &CPCs)
This function is intended to make starting values, given a unit upper-triangular matrix U such that U...
Definition: factor_U.hpp:27
Eigen.hpp
constants.hpp

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