Stan Math Library: stan/math/prim/mat/fun/factor_U.hpp Source File

| Stan Math Library 2.10.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
16 namespace stan {
17
18 namespace math {
19
27 template<typename T>
28 void
29 factor_U(const Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>& U,
30 Eigen::Array<T, Eigen::Dynamic, 1>& CPCs) {
31 size_t K = U.rows();
32 size_t position = 0;
33 size_t pull = K - 1;
34
35 if (K == 2) {
36 CPCs(0) = atanh(U(0, 1));
37 return;
38 }
39
40 Eigen::Array<T, 1, Eigen::Dynamic> temp = U.row(0).tail(pull);
41
42 CPCs.head(pull) = temp;
43
44 Eigen::Array<T, Eigen::Dynamic, 1> acc(K);
45 acc(0) = -0.0;
46 acc.tail(pull) = 1.0 - temp.square();
47 for (size_t i = 1; i < (K - 1); i++) {
48 position += pull;
49 pull--;
50 temp = U.row(i).tail(pull);
51 temp /= sqrt(acc.tail(pull) / acc(i));
52 CPCs.segment(position, pull) = temp;
53 acc.tail(pull) *= 1.0 - temp.square();
54 }
55 CPCs = 0.5 * ( (1.0 + CPCs) / (1.0 - CPCs) ).log(); // now unbounded
56 }
57
58 }
59
60 }
61
62 #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:15
stan
Definition: log_sum_exp.hpp:8
stan::math::log
fvar< T > log(const fvar< T > &x)
Definition: log.hpp:15
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:29
Eigen.hpp
constants.hpp

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