1 #ifndef HOPS_EXPECTEDSQUAREDJUMPDISTANCE_HPP
2 #define HOPS_EXPECTEDSQUAREDJUMPDISTANCE_HPP
8 #include <Eigen/Cholesky>
23 template<
typename StateType,
typename MatrixType>
25 unsigned long numUnseen,
27 unsigned long numSeen,
29 size_t numDraws = draws.size(),
32 if (numSeen > 0 && draws.size() > numUnseen) {
42 eta = 1.0 * (numSeen - 1) / (numSeen + numUnseen - 1),
45 if (!isConstantChain<StateType>({&draws})) {
46 for (
unsigned long i = numDraws - numUnseen - correction; i < numDraws - 1; ++i) {
47 StateType distance = sqrtCovariance.template triangularView<Eigen::Lower>().solve(draws[i] - draws[i+1]);
48 distance = sqrtCovariance.template triangularView<Eigen::Lower>().transpose().solve(distance);
49 squaredDistance = (draws[i] - draws[i+1]).transpose() * distance;
50 esjd += squaredDistance;
52 esjd /= numUnseen - 1 + correction;
55 return eta * esjdSeen + (1 - eta) * esjd;
61 template<
typename StateType,
typename MatrixType>
63 return computeExpectedSquaredJumpDistance<StateType, MatrixType>(draws, draws.size(), 0, 0, sqrtCovariance);
69 template<
typename StateType,
typename MatrixType>
71 MatrixType covariance = computeCovariance<StateType, MatrixType>(draws);
72 MatrixType sqrtCovariance = covariance.llt().matrixL();
73 return computeExpectedSquaredJumpDistance<StateType, MatrixType>(draws, sqrtCovariance);
79 template<
typename StateType,
typename MatrixType>
81 unsigned long numUnseen,
82 std::vector<double> esjdSeen,
83 unsigned long numSeen,
85 std::vector<double> esjds(chains.size());
86 for (
size_t i = 0; i < chains.size(); ++i) {
87 esjds[i] = computeExpectedSquaredJumpDistance<StateType, MatrixType>(chains[i], numUnseen, esjdSeen[i], numSeen, sqrtCovariance);
95 template<
typename StateType,
typename MatrixType>
97 return computeExpectedSquaredJumpDistance<StateType, MatrixType>(chains, chains[0].size(), std::vector<double>(chains.size()), 0, sqrtCovariance);
103 template<
typename StateType,
typename MatrixType>
105 MatrixType covariance = computeCovariance<StateType, MatrixType>(chains);
106 MatrixType sqrtCovariance = covariance.llt().matrixL();
107 return computeExpectedSquaredJumpDistance<StateType, MatrixType>(chains, sqrtCovariance);
114 template<
typename StateType,
typename MatrixType>
116 unsigned long numUnseen,
117 std::vector<double> esjdSeen,
118 unsigned long numSeen,
120 std::vector<double> esjds(chains.size());
121 for (
size_t i = 0; i < chains.size(); ++i) {
122 esjds[i] = computeExpectedSquaredJumpDistance<StateType, MatrixType>(*chains[i], numUnseen, esjdSeen[i], numSeen, sqrtCovariance);
131 template<
typename StateType,
typename MatrixType>
134 return computeExpectedSquaredJumpDistance<StateType, MatrixType>(chains, chains[0]->size(), std::vector<double>(chains.size()), 0, sqrtCovariance);
141 template<
typename StateType,
typename MatrixType>
143 MatrixType covariance = computeCovariance<StateType, MatrixType>(chains);
144 MatrixType sqrtCovariance = covariance.llt().matrixL();
145 return computeExpectedSquaredJumpDistance<StateType, MatrixType>(chains, sqrtCovariance);
150 #endif //HOPS_EXPECTEDSQUAREDJUMPDISTANCE_HPP