19template<
typename UncertainType>
29 using value_t =
typename uncertain_t::value_t;
32 using dep_sd_t =
typename uncertain_t::dep_sd_t;
62 if(std::abs(m_x_.m_mean_ - mean) >= m_x_.threshold())
73 for(
const auto& [dep, deriv] : m_x_.m_deps_) {
74 m_x_.m_sd_ += std::pow(*dep.get() * deriv, 2.0);
76 m_x_.m_sd_ = std::sqrt(m_x_.m_sd_);
93 if(std::abs(dxda) < m_x_.threshold() || dxda == 0.0) {
100 if(dxda == 1.0)
return;
103 m_removed_deps_.clear();
104 for(
const auto& [dep, deriv] : m_x_.m_deps_) {
105 m_x_.m_deps_[dep] *= dxda;
106 if(std::abs(m_x_.m_deps_[dep]) < m_x_.threshold()) {
107 m_removed_deps_.emplace_back(dep);
116 if(m_removed_deps_.size() == 0) {
117 if(dxda != -1.0) m_x_.m_sd_ *= std::abs(dxda);
119 for(
const auto& dep : m_removed_deps_) m_x_.m_deps_.erase(dep);
141 if(std::abs(dxda) < m_x_.threshold() || dxda == 0.0) {
return; }
146 m_removed_deps_.clear();
147 size_t n_updated = 0;
148 for(
const auto& [dep, deriv] : deps) {
149 if(m_x_.m_deps_.count(dep)) {
150 m_x_.m_deps_[dep] += dxda * deriv;
151 if(std::abs(m_x_.m_deps_[dep]) < m_x_.threshold() ||
152 m_x_.m_deps_[dep] == 0.0) {
153 m_removed_deps_.emplace_back(dep);
157 if(std::abs(dxda * deriv) < m_x_.threshold())
continue;
158 if(std::abs(*dep.get()) < m_x_.threshold())
continue;
159 m_x_.m_deps_.emplace(dep, dxda * deriv);
168 if(n_updated > (m_x_.m_deps_.size() / 2)) {
169 for(
const auto& dep : m_removed_deps_) m_x_.m_deps_.erase(dep);
173 m_x_.m_sd_ = std::pow(m_x_.m_sd_, 2.0);
176 for(
const auto& [dep, deriv] : deps) {
178 if(!m_x_.m_deps_.count(dep))
continue;
181 auto old_deriv = m_x_.m_deps_[dep] - dxda * deriv;
184 if(m_x_.m_deps_[dep] != 0.0) {
185 m_x_.m_sd_ += std::pow(*dep.get() * m_x_.m_deps_[dep], 2.0);
189 if(old_deriv != 0.0) {
190 m_x_.m_sd_ -= std::pow(*dep.get() * old_deriv, 2.0);
193 m_x_.m_sd_ = std::sqrt(m_x_.m_sd_);
194 for(
const auto& dep : m_removed_deps_) m_x_.m_deps_.erase(dep);
UncertainType uncertain_t
The numeric type of the variable.
Definition setter.hpp:26
void update_derivatives(value_t dxda)
Update of existing derivatives.
Definition setter.hpp:90
typename uncertain_t::dep_sd_ptr dep_sd_ptr
A pointer to a dependency of this variable.
Definition setter.hpp:35
void update_derivatives(const deps_map_t &deps, value_t dxda)
Update/addition of derivatives.
Definition setter.hpp:138
Setter(uncertain_t &u)
Construct a Setter for a variable.
Definition setter.hpp:49
Setter< UncertainType > my_t
Type of the instance.
Definition setter.hpp:23
void update_mean(value_t mean)
Update the mean of the wrapped variable.
Definition setter.hpp:61
typename uncertain_t::value_t value_t
The type of the values of the variable.
Definition setter.hpp:29
typename uncertain_t::dep_sd_t dep_sd_t
The type of a standard deviation that this instance depends on.
Definition setter.hpp:32
typename uncertain_t::deps_map_t deps_map_t
The type of the map holding the variable's dependencies.
Definition setter.hpp:38
void recalculate_sd()
Recalculate the standard deviation of the wrapped variable from its dependencies.
Definition setter.hpp:71
typename std::vector< dep_sd_ptr > deps_vector_t
The type of a vector of dependencies of this variable.
Definition setter.hpp:41
The namespace that contains the implementation details of the library.
Defines the Uncertain class.