1 #ifndef HOPS_AUTOCORRELATION_HPP
2 #define HOPS_AUTOCORRELATION_HPP
5 #include <unsupported/Eigen/FFT>
15 while ((m % 2) == 0) {
18 while ((m % 3) == 0) {
21 while ((m % 5) == 0) {
31 template <
typename StateType>
33 Eigen::VectorXd& autocorrelations,
34 unsigned long dimension) {
38 template <
typename StateType>
40 Eigen::VectorXd& autocorrelations,
41 unsigned long dimension) {
42 size_t N = draws->size();
43 Eigen::VectorXd X = Eigen::VectorXd::Zero(N);
44 for (
size_t n = 0; n < N; ++n) {
45 X(n) = (*draws)[n](dimension);
48 Eigen::FFT<typename StateType::Scalar> fft;
53 Eigen::VectorXd centeredX(Mt2);
55 centeredX.head(N) = X.array() - X.mean();
59 Eigen::VectorXcd frequency(Mt2);
60 fft.fwd(frequency, centeredX);
62 frequency = frequency.cwiseAbs2();
64 Eigen::VectorXcd autocorrelationsTmp(Mt2);
65 fft.inv(autocorrelationsTmp, frequency);
68 autocorrelations = autocorrelationsTmp.head(N).real().array() / (N * N * 2);
69 autocorrelations /= autocorrelations(0);
73 #endif // HOPS_AUTOCORRELATION_HPP