sigma  0.0.0
Loading...
Searching...
No Matches
operation_common.hpp
Go to the documentation of this file.
1#pragma once
2
4#include "sigma/uncertain.hpp"
5
9
10namespace sigma::detail_ {
11
13constexpr double pi = 3.14159265358979323846;
14
24template<typename T>
25void inplace_unary(Uncertain<T>& c, T mean, T dcda) {
27 c_setter.update_mean(mean);
28 c_setter.update_derivatives(dcda);
29}
30
43template<typename T>
44Uncertain<T> unary_result(const Uncertain<T>& a, T mean, T dcda) {
45 Uncertain<T> c(a);
46 detail_::inplace_unary(c, mean, dcda);
47 return c;
48}
49
61template<typename T>
62void inplace_binary(Uncertain<T>& c, const Uncertain<T>& b, T mean, T dcda,
63 T dcdb) {
65 c_setter.update_mean(mean);
66 c_setter.update_derivatives(dcda, false);
67 c_setter.update_derivatives(b.deps(), dcdb);
68}
69
84template<typename T>
86 T dcda, T dcdb) {
87 Uncertain<T> c(a);
88 detail_::inplace_binary(c, b, mean, dcda, dcdb);
89 return c;
90}
91
103template<typename FunctionType, typename NumericType>
104NumericType numeric_derivative(FunctionType f, NumericType a) {
105 // Step and step size chosen for consistency with uncertainties package
106 auto step_size = std::sqrt(std::numeric_limits<float>::epsilon());
107 auto step = step_size * std::abs(a);
108 auto a_plus = f(a + step);
109 auto a_minus = f(a - step);
110 auto dcda = (a_plus - a_minus) / (2 * step);
111 return dcda;
112}
113
114} // namespace sigma::detail_
Models an unceratin variable.
Definition uncertain.hpp:33
const deps_map_t & deps() const
Get the dependencies of the variable.
Definition uncertain.hpp:98
Modifies an unceratin variable.
Definition setter.hpp:19
void update_derivatives(value_t dxda, bool call_update_std=true)
Update of existing derivatives.
Definition setter.hpp:84
void update_mean(value_t mean)
Update the mean of the wrapped variable.
Definition setter.hpp:53
The namespace that contains the implementation details of the library.
Definition operation_common.hpp:10
void inplace_binary(Uncertain< T > &c, const Uncertain< T > &b, T mean, T dcda, T dcdb)
Generalized Inplace Binary Changes.
Definition operation_common.hpp:62
void inplace_unary(Uncertain< T > &c, T mean, T dcda)
Generalized Inplace Unary Changes.
Definition operation_common.hpp:25
constexpr double pi
Value of Pi.
Definition operation_common.hpp:13
Uncertain< T > unary_result(const Uncertain< T > &a, T mean, T dcda)
Generalized Unary Changes.
Definition operation_common.hpp:44
Uncertain< T > binary_result(const Uncertain< T > &a, const Uncertain< T > &b, T mean, T dcda, T dcdb)
Generalized Binary Changes.
Definition operation_common.hpp:85
NumericType numeric_derivative(FunctionType f, NumericType a)
Compute the numeric derivative of a function.
Definition operation_common.hpp:104
Defines the Setter class.
Defines the Uncertain class.