Loading [MathJax]/extensions/tex2jax.js
ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages Concepts
MeanVarianceCalculator.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2016-2022 The ESPResSo project
3 *
4 * This file is part of ESPResSo.
5 *
6 * ESPResSo is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * ESPResSo is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
21
22#include <boost/archive/binary_iarchive.hpp>
23#include <boost/archive/binary_oarchive.hpp>
24#include <boost/iostreams/device/array.hpp>
25#include <boost/iostreams/stream.hpp>
26#include <boost/serialization/shared_ptr.hpp>
27#include <boost/serialization/string.hpp>
28#include <boost/serialization/vector.hpp>
29
30#include <sstream>
31#include <string>
32#include <vector>
33
34namespace Accumulators {
35void MeanVarianceCalculator::update(boost::mpi::communicator const &comm) {
36 if (comm.rank() == 0) {
37 m_acc(m_obs->operator()(comm));
38 } else {
39 m_obs->operator()(comm);
40 }
41}
42
43std::vector<double> MeanVarianceCalculator::mean() { return m_acc.mean(); }
44
45std::vector<double> MeanVarianceCalculator::variance() {
46 return m_acc.variance();
47}
48
49std::vector<double> MeanVarianceCalculator::std_error() {
50 return m_acc.std_error();
51}
52
54 std::stringstream ss;
55 boost::archive::binary_oarchive oa(ss);
56
57 oa << m_acc;
58
59 return ss.str();
60}
61
62void MeanVarianceCalculator::set_internal_state(std::string const &state) {
63 namespace iostreams = boost::iostreams;
64 iostreams::array_source src(state.data(), state.size());
65 iostreams::stream<iostreams::array_source> ss(src);
66 boost::archive::binary_iarchive ia(ss);
67
68 ia >> m_acc;
69 m_system = nullptr;
70}
71} // namespace Accumulators
void const * m_system
for bookkeeping purposes
void set_internal_state(std::string const &) final
void update(boost::mpi::communicator const &comm) override
std::vector< double > std_error() const
Compute the standard error of the mean, assuming uncorrelated data.
std::vector< double > variance() const
Compute the Bessel-corrected sample variance, assuming uncorrelated data.
std::vector< double > mean() const
Compute the sample mean.