1 #ifndef STAN_MATH_PRIM_MAT_FUN_AUTOCORRELATION_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_AUTOCORRELATION_HPP
5 #include <unsupported/Eigen/FFT>
19 size_t fft_next_good_size(
size_t N) {
23 while ((m % 2) == 0) m /= 2;
24 while ((m % 3) == 0) m /= 3;
25 while ((m % 5) == 0) m /= 5;
61 size_t M = fft_next_good_size(N);
65 vector<complex<T> > freqvec;
68 vector<T> centered_signal(y);
69 centered_signal.insert(centered_signal.end(), Mt2-N, 0.0);
71 for (
size_t i = 0; i < N; i++)
72 centered_signal[i] -= mean;
74 fft.fwd(freqvec, centered_signal);
75 for (
size_t i = 0; i < Mt2; ++i)
76 freqvec[i] = complex<T>(norm(freqvec[i]), 0.0);
98 for (
size_t i = 0; i < N; ++i) {
102 for (
size_t i = 0; i < N; ++i)
122 template <
typename T>
124 std::vector<T>& ac) {
Independent (input) and dependent (output) variables for gradients.
boost::math::tools::promote_args< T >::type mean(const std::vector< T > &v)
Returns the sample mean (i.e., average) of the coefficients in the specified standard vector...
void autocorrelation(const std::vector< T > &y, std::vector< T > &ac, Eigen::FFT< T > &fft)
Write autocorrelation estimates for every lag for the specified input sequence into the specified res...