7#ifndef THEORETICA_DATASET_H
8#define THEORETICA_DATASET_H
10#ifndef THEORETICA_NO_PRINT
24 template<
typename Vector, enable_vector<Vector> = true>
33 for(
unsigned int i = 1; i <
X.size(); i++)
41 template<
typename Vector>
44 if(
X.size() !=
Y.size() || !
X.size()) {
49 auto res =
X[0] *
Y[0];
50 for(
unsigned int i = 1; i <
X.size(); i++)
58 template<
typename Vector>
61 if(
X.size() !=
Y.size() || !
X.size()) {
66 auto res = (
X[0] *
X[0]) * (
Y[0] *
Y[0]);
68 for(
unsigned int i = 1; i <
X.size(); i++)
69 res += (
X[i] *
X[i]) * (
Y[i] *
Y[i]);
76 template<
typename Vector>
79 if(
X.size() !=
Y.size() ||
X.size() !=
Z.size() || !
X.size()) {
84 auto res =
X[0] *
Y[0] *
Z[0];
85 for(
unsigned int i = 1; i <
X.size(); i++)
93 template<
typename Vector>
96 if(
X.size() !=
Y.size()) {
106 auto res =
X[0] /
Y[0];
107 for(
unsigned int i = 1; i <
X.size(); i++) {
122 template<
typename Vector>
130 auto res =
X[0] *
X[0];
131 for(
unsigned int i = 1; i <
X.size(); i++)
143 template<
typename Vector>
152 for (
unsigned int i = 0; i <
X.size(); i++) {
177 template<
typename Vector>
179 const Vector&
X,
size_t begin = 0,
180 size_t end = 0,
size_t base_size = 128) {
190 for (
size_t i = begin; i < end; ++i)
196 const size_t m = (end - begin) / 2;
197 const size_t cutoff = begin +
m;
213 std::enable_if_t<has_real_elements<Vector>::value> =
true
223 template<
typename Vector>
231 for(
unsigned int i = 1; i <
X.size(); i++)
245 template<
typename Vector,
typename Function>
248 for (
unsigned int i = 0; i <
X.size(); i++)
262 template<
typename Vector1,
typename Vector2 = Vector1,
typename Function>
265 if(
src.size() !=
dest.size()) {
270 for (
unsigned int i = 0; i <
src.size(); i++)
282 template<
typename Vector2,
typename Vector1,
typename Function>
286 res.resize(
X.size());
288 for (
unsigned int i = 0; i <
X.size(); i++)
300 template<
typename Vector,
typename Function>
307 template<
typename Vector1,
typename Vector2,
typename Vector3 = Vector1>
311 res.resize(
v1.size() +
v2.size());
312 const unsigned int offset =
v1.size();
314 for (
unsigned int i = 0; i <
offset; ++i)
317 for (
unsigned int i = 0; i <
v2.size(); ++i)
325 template<
typename Vector>
328 using Type = vector_element_t<Vector>;
337 for (
unsigned int i = 1; i <
X.size(); ++i)
346 template<
typename Vector>
349 using Type = vector_element_t<Vector>;
358 for (
unsigned int i = 1; i <
X.size(); ++i)
370 template<
typename Dataset>
379 return sum(data) / (
real) data.size();
384 template<
typename Dataset>
394 for (
unsigned int i = 0; i < data.size(); ++i) {
401 res += 1.0 / data[i];
404 return static_cast<real>(data.size()) /
res;
410 template<
typename Dataset>
418 template<
typename Dataset1,
typename Dataset2>
428 template<
typename Dataset>
Mathematical constants and default algorithm parameters.
#define TH_CONSTIF
Enable constexpr in if statements if C++17 is supported.
Definition constants.h:178
#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
Error handling for IO operations.
Vector & vec_error(Vector &v)
Overwrite the given vector with the error vector with NaN values.
Definition algebra.h:58
Main namespace of the library which contains all functions and objects.
Definition algebra.h:27
double real
A real number, defined as a floating point type.
Definition constants.h:207
Vector & transform(Function f, Vector &X)
Transform a vector by applying a function to each of its elements.
Definition dataset.h:246
real weighted_mean(const Dataset1 &data, const Dataset2 &weights)
Compute the weighted mean of a set of values <data> and <weights> must have the same size.
Definition dataset.h:419
real arithmetic_mean(const Dataset &data)
Compute the arithmetic mean of a set of values.
Definition dataset.h:371
auto min(const Vector &X)
Finds the minimum value inside a dataset.
Definition dataset.h:347
real harmonic_mean(const Dataset &data)
Compute the harmonic mean of a set of values.
Definition dataset.h:385
real sum_compensated(const Vector &X)
Compute the sum of a set of values using the compensated Neumaier-Kahan-Babushka summation algorithm ...
Definition dataset.h:144
dual2 sqrt(dual2 x)
Compute the square root of a second order dual number.
Definition dual2_functions.h:54
Vector3 concatenate(const Vector1 &v1, const Vector2 &v2)
Concatenate two datasets to form a single one.
Definition dataset.h:308
Vector2 & map(Function f, const Vector1 &src, Vector2 &dest)
Overwrite a vector by applying a function to the elements of another vector.
Definition dataset.h:263
dual2 abs(dual2 x)
Compute the absolute value of a second order dual number.
Definition dual2_functions.h:242
real sum_pairwise(const Vector &X, size_t begin=0, size_t end=0, size_t base_size=128)
Compute the sum of a set of values using pairwise summation to reduce round-off error.
Definition dataset.h:178
Vector make_error()
Create a vector representing an error state, with all NaN values.
Definition algebra.h:103
auto sum(const Vector &X)
Compute the sum of a vector of real values using pairwise summation to reduce round-off error.
Definition dataset.h:215
real geometric_mean(const Dataset &data)
Compute the geometric mean of a set of values as .
Definition dataset.h:411
auto max(const Vector &X)
Finds the maximum value inside a dataset.
Definition dataset.h:326
auto product_sum(const Vector &X, const Vector &Y)
Sum the products of two sets of values.
Definition dataset.h:42
auto product_sum_squares(const Vector &X, const Vector &Y)
Sum the products of the squares of two sets of data.
Definition dataset.h:59
TH_CONSTEXPR real nan()
Return a quiet NaN number in floating point representation.
Definition error.h:74
real quadratic_mean(const Dataset &data)
Compute the quadratic mean (Root Mean Square) of a set of values .
Definition dataset.h:429
@ InvalidArgument
Invalid argument.
@ DivByZero
Division by zero.
auto quotient_sum(const Vector &X, const Vector &Y)
Sum the quotients of two sets of values.
Definition dataset.h:94
constexpr real MACH_EPSILON
Machine epsilon for the real type.
Definition constants.h:216
real root(real x, int n)
Compute the n-th root of x.
Definition real_analysis.h:812
auto product(const Vector &X)
Compute the product of a set of values.
Definition dataset.h:25
auto sum_squares(const Vector &X)
Sum the squares of a set of values.
Definition dataset.h:123