ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
script_interface/accumulators/MeanVarianceCalculator.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2022 The ESPResSo project
3 * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010
4 * Max-Planck-Institute for Polymer Research, Theory Group
5 *
6 * This file is part of ESPResSo.
7 *
8 * ESPResSo is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * ESPResSo is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
24#include "AccumulatorBase.hpp"
25
28
31
32#include <memory>
33#include <string>
34#include <utility>
35
36namespace ScriptInterface {
37namespace Accumulators {
38
40public:
41 MeanVarianceCalculator() { add_parameters({{"obs", std::as_const(m_obs)}}); }
42
43 void do_construct(VariantMap const &params) override {
44 set_from_args(m_obs, params, "obs");
45
46 if (m_obs)
47 m_accumulator = std::make_shared<::Accumulators::MeanVarianceCalculator>(
49 get_value_or<int>(params, "delta_N", 1), m_obs->observable());
50 }
51
52 std::shared_ptr<::Accumulators::MeanVarianceCalculator>
54 return m_accumulator;
55 }
56
57 std::shared_ptr<const ::Accumulators::MeanVarianceCalculator>
59 return m_accumulator;
60 }
61
62 Variant do_call_method(std::string const &method,
63 VariantMap const &parameters) override {
64 if (method == "update") {
66 [&]() { mean_variance_calculator()->update(context()->get_comm()); });
67 return {};
68 }
69 if (method == "mean")
70 return mean_variance_calculator()->mean();
71 if (method == "variance")
72 return mean_variance_calculator()->variance();
73 if (method == "std_error")
74 return mean_variance_calculator()->std_error();
75 return AccumulatorBase::do_call_method(method, parameters);
76 }
77
78 std::shared_ptr<::Accumulators::AccumulatorBase> accumulator() override {
79 return m_accumulator;
80 }
81
82 std::shared_ptr<const ::Accumulators::AccumulatorBase>
83 accumulator() const override {
84 return std::static_pointer_cast<::Accumulators::AccumulatorBase>(
85 m_accumulator);
86 }
87
88private:
89 /* The actual accumulator */
90 std::shared_ptr<::Accumulators::MeanVarianceCalculator> m_accumulator;
91 std::shared_ptr<Observables::Observable> m_obs;
92};
93
94} // namespace Accumulators
95} // namespace ScriptInterface
Variant do_call_method(std::string const &method, VariantMap const &parameters) override
std::shared_ptr<::Accumulators::MeanVarianceCalculator > mean_variance_calculator()
Variant do_call_method(std::string const &method, VariantMap const &parameters) override
std::shared_ptr< const ::Accumulators::MeanVarianceCalculator > mean_variance_calculator() const
std::shared_ptr< const ::Accumulators::AccumulatorBase > accumulator() const override
void add_parameters(std::vector< AutoParameter > &&params)
virtual void parallel_try_catch(std::function< void()> const &cb) const =0
Context * context() const
Responsible context.
std::unordered_map< std::string, Variant > VariantMap
Definition Variant.hpp:69
boost::make_recursive_variant< None, bool, int, std::size_t, double, std::string, ObjectRef, Utils::Vector3b, Utils::Vector3i, Utils::Vector2d, Utils::Vector3d, Utils::Vector4d, std::vector< int >, std::vector< double >, std::vector< boost::recursive_variant_ >, std::unordered_map< int, boost::recursive_variant_ >, std::unordered_map< std::string, boost::recursive_variant_ > >::type Variant
Possible types for parameters.
Definition Variant.hpp:67
void set_from_args(T &dst, VariantMap const &vals, const char *name)
static SteepestDescentParameters params
Currently active steepest descent instance.