6#ifndef THEORETICA_ERRORPROP_H
7#define THEORETICA_ERRORPROP_H
29 typename Matrix = mat<real>,
typename Dataset = vec<real>,
30 enable_vector<Dataset> =
true
32 inline Matrix
covar_mat(
const std::vector<Dataset>& v) {
35 cm.resize(v.size(), v.size());
37 for (
unsigned int i = 0; i < cm.rows(); ++i)
38 for (
unsigned int j = 0; j < cm.cols(); ++j)
67 for (
unsigned int i = 0; i < x_best.
size(); ++i)
90 typename Matrix, enable_matrix<Matrix> =
true,
94 MultiDualFunction f,
const vec<real, N>& x_best,
const Matrix& cm) {
97 if(cm.rows() != x_best.
size()) {
102 if(cm.cols() != x_best.
size()) {
110 for (
unsigned int i = 0; i < cm.rows(); ++i)
111 for (
unsigned int j = 0; j < cm.cols(); ++j)
112 err_sqr += df.
Dual(i) * df.
Dual(j) * cm(i, j);
114 return sqrt(err_sqr);
137 const std::vector<Dataset>& v) {
142 for (
unsigned int i = 0; i < v.size(); ++i)
168 template<
typename Function>
170 Function f, std::vector<pdf_sampler>& rv,
unsigned int N = 1
E+6) {
Differential operators using automatic differentiation.
A generic matrix with a fixed number of rows and columns.
Definition mat.h:136
Multidual number algebra for functions of the form .
Definition multidual.h:26
vec< real, N > Dual() const
Get the multidual part.
Definition multidual.h:79
static vec< multidual< N >, N > make_argument(const Vector &x)
Construct an N-dimensional vector of multidual numbers to be passed as argument to a multidual functi...
Definition multidual.h:401
A statically allocated N-dimensional vector with elements of the given type.
Definition vec.h:92
void resize(size_t n) const
Compatibility function to allow for allocation or resizing of dynamic vectors.
Definition vec.h:459
TH_CONSTEXPR unsigned int size() const
Returns the size of the vector (N).
Definition vec.h:449
#define TH_MATH_ERROR(F_NAME, VALUE, EXCEPTION)
TH_MATH_ERROR is a macro which throws exceptions or modifies errno (depending on which compilation op...
Definition error.h:219
multidual< N > dreal_t
Real type for multivariate automatic differentiation (read "differential real").
Definition autodiff_types.h:139
vec< dreal_t< N >, N > dvec_t
Vector type for multivariate automatic differentiation (read "differential vector").
Definition autodiff_types.h:144
Statistical functions.
Definition distributions.h:19
real propagerr(MultiDualFunction f, const vec< real, N > &x_best, const vec< real, N > &delta_x)
Automatically propagate uncertainties under quadrature on an arbitrary function given the uncertainti...
Definition errorprop.h:60
real stdev(const histogram &h)
Compute the standard deviation of the values of a histogram.
Definition histogram.h:366
real propagerr_mc(Function f, std::vector< pdf_sampler > &rv, unsigned int N=1E+6)
Propagate the statistical error on a given function using the Monte Carlo method, by generating a sam...
Definition errorprop.h:169
real covariance(const Dataset1 &X, const Dataset2 &Y, unsigned int constraints=1)
Compute the covariance between two datasets with the given number of constraints.
Definition statistics.h:262
real mean(const histogram &h)
Compute the mean of the values of a histogram.
Definition histogram.h:342
Matrix covar_mat(const std::vector< Dataset > &v)
Build the covariance matrix given a vector of datasets by computing the covariance between all couple...
Definition errorprop.h:32
Main namespace of the library which contains all functions and objects.
Definition algebra.h:27
dual2 sqrt(dual2 x)
Compute the square root of a second order dual number.
Definition dual2_functions.h:54
double real
A real number, defined as a floating point type.
Definition constants.h:207
TH_CONSTEXPR real nan()
Return a quiet NaN number in floating point representation.
Definition error.h:74
Vector sample_mc(Function f, std::vector< pdf_sampler > &rv, unsigned int N)
Generate a Monte Carlo sample of values of a given function of arbitrary variables following the give...
Definition montecarlo.h:376
@ InvalidArgument
Invalid argument.
Definition error.h:32
constexpr real E
The Euler mathematical constant (e).
Definition constants.h:246
dual2 square(dual2 x)
Return the square of a second order dual number.
Definition dual2_functions.h:23
Sampling from probability distributions.
Vector class and operations.