41namespace triqs::stat {
51 auto jackknife_impl(std::optional<mpi::communicator> comm,
auto &&f, StatCompatibleRange
auto &&...rgs) {
53 auto rgs_tup = std::tie(rgs...);
54 auto size = std::ranges::size(std::get<0>(rgs_tup));
55 if (((std::ranges::size(rgs) !=
size) or ...))
throw std::runtime_error(
"Error in jackknife: Ranges must have the same size.");
58 if (comm) mpi::all_reduce_in_place(
size, *comm);
61 auto [mean_tup, jk_tup] = [&comm,
size, &rgs_tup]<std::size_t... Is>(std::index_sequence<Is...>) {
62 auto mtup = std::make_tuple(
mean_mpi(comm, std::get<Is>(rgs_tup))...);
63 auto jtup = std::make_tuple(std::ranges::transform_view(
64 std::get<Is>(rgs_tup), [m = std::get<Is>(mtup),
size](
auto const &x) {
return (
size * m - x) / (
size - 1); })...);
65 return std::make_pair(mtup, jtup);
66 }(std::make_index_sequence<
sizeof...(rgs)>{});
69 auto zipped = std::apply([](
auto &&...jks) {
return std::ranges::zip_view(jks...); }, jk_tup);
72 auto f_wrapped = [f](
auto const &...args) {
return nda::make_regular(f(args...)); };
74 comm, std::ranges::transform_view(zipped, [f_wrapped](
auto const &tup) {
return std::apply(f_wrapped, tup); }));
77 auto naive_f = nda::make_regular(std::apply(f, mean_tup));
78 auto corr_f = nda::make_regular(
size * naive_f - (
size - 1) * jk_f);
80 return std::make_tuple(corr_f, jk_err, jk_f, naive_f);
119 requires(not std::same_as<std::remove_cvref_t<F>, mpi::communicator>)
121 return detail::jackknife_impl(std::nullopt, std::forward<F>(f), rg, rgs...);
139 template <
typename F, StatCompatibleRange R, StatCompatibleRange... Rs>
141 return detail::jackknife_impl(comm, std::forward<F>(f), rg, rgs...);
int size() const
Get the total number of blocks.
Concept to check if a range can be used with various Statistical analysis tools.
auto mean_and_err_mpi(std::optional< mpi::communicator > c, R &&rg)
Calculate the arithmetic mean or the simple sum as well as a corresponding error estimate of some ran...
auto mean_mpi(std::optional< mpi::communicator > c, R &&rg)
Calculate the arithmetic mean or the simple sum of some range of values spread across multiple MPI pr...
auto jackknife(F &&f, R &&rg, Rs &&...rgs)
Perform jackknife resampling.
auto jackknife_mpi(mpi::communicator comm, F &&f, R &&rg, Rs &&...rgs)
Perform jackknife resampling with MPI support.
Provides functions to calculate the arithmetic mean and standard error of a range of values.
Provides various concepts for the Utilities.