Alexandria 2.31.0
SDC-CH common library for the Euclid project
|
Classes | |
class | AdaptativeIntegration |
Class implementing the NumericalIntegrationScheme interface. More... | |
struct | Chi2Distance |
class | CubicInterpolator |
class | Cumulative |
Class for build cumulative from PDF and extract feature out of it. More... | |
class | DefaultMultiplication |
interface | Differentiable |
Interface representing a differentiable function. More... | |
struct | EuclideanDistance |
struct | ExtractKnots |
struct | ExtractKnots< Euclid::_index_sequence< Is... > > |
class | FunctionAdapter |
Adapt a std::function<double(double)> to the Function Interface. More... | |
interface | Integrable |
Interface representing an integrable function. More... | |
class | InterpN |
struct | InterpolationException |
struct | InverseChi2 |
class | InverseCumulative |
struct | InverseEuclidean |
struct | Likelihood |
class | LinearInterpolator |
class | ModeInfo |
Class for storing the information of a PDF mode. More... | |
interface | NAryFunction |
Interface class representing a function with an arbitrary number of parameters. More... | |
interface | NAryFunctionImpl |
class | NAryFunctionImpl< _index_sequence< Is... > > |
class | NdSampler |
interface | NumericalIntegrationScheme |
Interface class representing a numerical integration scheme. More... | |
class | Piecewise |
Represents a piecewise function. More... | |
class | PiecewiseBase |
Represents a piecewise function. More... | |
class | Polynomial |
Represents a polynomial function. More... | |
struct | SecantParams |
struct | SecantReturn |
class | SimpsonsRule |
Typedefs | |
using | Function = NAryFunction< 1 > |
Alias for an unary function. | |
using | BinaryFunction = NAryFunction< 2 > |
Alias for a binary function. | |
using | TernaryFunction = NAryFunction< 3 > |
Alias for a ternary function. | |
typedef std::unique_ptr< Function >(* | MultiplyFunction) (const Function &, const Function &) |
Alias of a function which multiplies Function objects. | |
template<std::size_t N> | |
using | Coordinates = std::array< std::vector< double >, N > |
Used to pass the grid coordinates to interpn. Internally will make a copy of the required values. | |
Enumerations | |
enum class | InterpolationType { LINEAR , CUBIC_SPLINE } |
Enumeration of the different supported interpolation types. More... | |
enum class | SecantEndReason { SUCCESS , MAX_ITER , GRADIENT , OUT_OF_BOUNDS , VALUE_ERROR } |
Alias for a binary function.
Definition at line 119 of file Function.h.
using Euclid::MathUtils::Coordinates = typedef std::array<std::vector<double>, N> |
Used to pass the grid coordinates to interpn. Internally will make a copy of the required values.
Alias for an array of references to vectors of doubles
N | Number of dimensions |
Definition at line 86 of file interpolation.h.
Alias for an unary function.
Definition at line 116 of file Function.h.
typedef std::unique_ptr< Function >(* Euclid::MathUtils::MultiplyFunction) (const Function &, const Function &) |
Alias of a function which multiplies Function objects.
Definition at line 40 of file multiplication.h.
Alias for a ternary function.
Definition at line 122 of file Function.h.
Enumeration of the different supported interpolation types.
Enumerator | |
---|---|
LINEAR | |
CUBIC_SPLINE |
Definition at line 43 of file interpolation.h.
Enumerator | |
---|---|
SUCCESS | |
MAX_ITER | |
GRADIENT | |
OUT_OF_BOUNDS | |
VALUE_ERROR |
Definition at line 28 of file SecantMethod.h.
std::pair< double, double > Euclid::MathUtils::avgArea | ( | std::pair< std::vector< double >, std::vector< double > > & | pdf, |
size_t | min_x, | ||
size_t | max_x | ||
) |
Definition at line 99 of file PdfModeExtraction.cpp.
References std::make_pair(), and std::array< T >::size().
Referenced by extractNBigestModes(), and extractNHighestModes().
std::pair< size_t, size_t > Euclid::MathUtils::catchPeak | ( | const std::vector< double > & | pdf, |
size_t | center_index, | ||
double | merge_ratio | ||
) |
Definition at line 65 of file PdfModeExtraction.cpp.
References std::make_pair(), and std::array< T >::size().
Referenced by extractNBigestModes(), and extractNHighestModes().
std::unique_ptr< NdSampler< Axes... > > Euclid::MathUtils::createSamplerFromGrid | ( | const GridContainer::GridContainer< std::vector< double >, Axes... > & | grid | ) |
Helper function to generate a NdSampler from a GridContainer with a vector of double as a cell manager
Axes | Grid axes |
The compiler should be able to infer the axis types. Example:
Definition at line 57 of file NdSamplerFromGrid.h.
References std::array< T >::begin(), std::array< T >::end(), Euclid::make_unique(), and std::move().
Referenced by createSamplerFromGrid().
std::unique_ptr< NdSampler< std::size_t, GridAxes... > > Euclid::MathUtils::createSamplerFromGrid | ( | const GridContainer::GridContainer< std::vector< std::vector< double > >, GridAxes... > & | grid | ) |
Helper function to generate a NdSampler from a GridContainer with a vector of vector of doubles as a cell manager. It works similarly to createSamplerFromGrid, except that the cell content is considered an extra, implicit, axis. Assumes the embedded axis to be discrete, with its knots being sequential between 0 and the size of the cell.
GridAxes | Grid axes |
Definition at line 117 of file NdSamplerFromGrid.h.
References std::array< T >::begin(), createSamplerFromGrid(), std::array< T >::end(), std::iota(), and std::array< T >::size().
std::unique_ptr< NdSampler< CellAxis, GridAxes... > > Euclid::MathUtils::createSamplerFromGrid | ( | const GridContainer::GridContainer< std::vector< std::vector< double > >, GridAxes... > & | grid, |
const std::vector< CellAxis > & | cell_axis | ||
) |
Helper function to generate a NdSampler from a GridContainer with a vector of vector of doubles as a cell manager. It works similarly to createSamplerFromGrid, except that the cell content is considered an extra, implicit, axis.
GridAxes | Grid axes |
CellAxis | Axis embedded into the cell |
The compiler should be able to infer the axis types. Example:
grid | The GridContainer |
cell_axis | User-defined knots for the embedded axis |
Definition at line 84 of file NdSamplerFromGrid.h.
References std::array< T >::at(), std::make_tuple(), Euclid::make_unique(), std::move(), std::array< T >::size(), std::tuple_cat(), and Euclid::NdArray::unravel_index().
Derivative using finite differences: \( f'(x) = \frac{f(x+h) - f(x)}{h} \)
f | The Function to derive |
x | The point where to do the derivation |
Definition at line 41 of file FiniteDifference.cpp.
References guess_h(), and std::sqrt().
Referenced by Euclid::MathUtils::Polynomial::~Polynomial().
Second derivative using finite differences: \( f''(x) = \frac{f(x+h) - 2f(x) + f(x - h)}{h^2} \)
f | The Function to derive |
x | The point where to do the derivation |
Definition at line 50 of file FiniteDifference.cpp.
References guess_h(), and std::sqrt().
std::vector< ModeInfo > Euclid::MathUtils::extractNBigestModes | ( | const XYDataset::XYDataset & | pdf, |
double | merge_ratio, | ||
size_t | n | ||
) |
Extract the n modes with biggest area in the provided pdf and compute for each of them the location of the mode and its area. A mode is discovered as the highest point of the pdf, then, on both sides, samples are added until the pdf starts to rise again. In order to avoid truncating the mode due to a noisy pdf it is possible to specify a merge_ratio. In this case the samples are added until their values is below the hight of the peak times the merge ratio, then additional point are added until the pdf rise again.
The sampling of the pdf to be analysed. | |
merge_ratio | The parameter for mode cutting. |
n | The (maximum) number of modes to be returned. |
Definition at line 239 of file PdfModeExtraction.cpp.
References extractNBigestModes(), and getXYs().
Referenced by extractNBigestModes().
std::vector< ModeInfo > Euclid::MathUtils::extractNBigestModes | ( | std::vector< double > & | x_sampling, |
std::vector< double > & | pdf_sampling, | ||
double | merge_ratio, | ||
size_t | n | ||
) |
Extract the n modes with biggest area in the provided pdf and compute for each of them the location of the mode and its area. A mode is discovered as the highest point of the pdf, then, on both sides, samples are added until the pdf starts to rise again. In order to avoid truncating the mode due to a noisy pdf it is possible to specify a merge_ratio. In this case the samples are added until their values is below the hight of the peak times the merge ratio, then additional point are added until the pdf rise again.
x_sampling | The horizontal sampling of the pdf to be analysed. |
pdf_sampling | The sampling of the pdf to be analysed. |
merge_ratio | The parameter for mode cutting. |
n | The (maximum) number of modes to be returned. |
Definition at line 198 of file PdfModeExtraction.cpp.
References avgArea(), std::array< T >::back(), std::array< T >::begin(), catchPeak(), std::array< T >::end(), findMaximumIndex(), flatternPeak(), getInterpolationAround(), std::make_pair(), and std::array< T >::size().
std::vector< ModeInfo > Euclid::MathUtils::extractNHighestModes | ( | const XYDataset::XYDataset & | pdf, |
double | merge_ratio, | ||
size_t | n | ||
) |
Extract the n highest modes in the provided pdf and compute for each of them the location of the mode and its area. A mode is discovered as the highest point of the pdf, then, on both sides, samples are added until the pdf starts to rise again. In order to avoid truncating the mode due to a noisy pdf it is possible to specify a merge_ratio. In this case the samples are added until their values is below the hight of the peak times the merge ratio, then additional point are added until the pdf rise again.
The sampling of the pdf to be analysed. | |
merge_ratio | The parameter for mode cutting. |
n | The (maximum) number of modes to be returned. |
Definition at line 193 of file PdfModeExtraction.cpp.
References extractNHighestModes(), and getXYs().
Referenced by extractNHighestModes().
std::vector< ModeInfo > Euclid::MathUtils::extractNHighestModes | ( | std::vector< double > & | x_sampling, |
std::vector< double > & | pdf_sampling, | ||
double | merge_ratio, | ||
size_t | n | ||
) |
Extract the n highest modes in the provided pdf and compute for each of them the location of the mode and its area. A mode is discovered as the highest point of the pdf, then, on both sides, samples are added until the pdf starts to rise again. In order to avoid truncating the mode due to a noisy pdf it is possible to specify a merge_ratio. In this case the samples are added until their values is below the hight of the peak times the merge ratio, then additional point are added until the pdf rise again.
x_sampling | The horizontal sampling of the pdf to be analysed. |
pdf_sampling | The sampling of the pdf to be analysed. |
merge_ratio | The parameter for mode cutting. |
n | The (maximum) number of modes to be returned. |
Definition at line 176 of file PdfModeExtraction.cpp.
References avgArea(), catchPeak(), findMaximumIndex(), flatternPeak(), getInterpolationAround(), and std::make_pair().
size_t Euclid::MathUtils::findMaximumIndex | ( | const std::vector< double > & | ) |
Definition at line 50 of file PdfModeExtraction.cpp.
References std::array< T >::begin(), and std::array< T >::end().
Referenced by extractNBigestModes(), and extractNHighestModes().
std::pair< std::vector< double >, std::vector< double > > Euclid::MathUtils::flatternPeak | ( | const std::pair< std::vector< double >, std::vector< double > > & | pdf, |
size_t | min_x, | ||
size_t | max_x, | ||
double | value | ||
) |
Definition at line 168 of file PdfModeExtraction.cpp.
References std::make_pair().
Referenced by extractNBigestModes(), and extractNHighestModes().
double Euclid::MathUtils::getInterpolationAround | ( | const std::pair< std::vector< double >, std::vector< double > > & | pdf, |
size_t | x_index | ||
) |
Definition at line 121 of file PdfModeExtraction.cpp.
References std::array< T >::back(), std::array< T >::front(), and std::array< T >::size().
Referenced by extractNBigestModes(), and extractNHighestModes().
std::pair< std::vector< double >, std::vector< double > > Euclid::MathUtils::getXYs | ( | const XYDataset::XYDataset & | ) |
Definition at line 36 of file PdfModeExtraction.cpp.
References std::array< T >::begin(), std::array< T >::end(), and std::make_pair().
Referenced by extractNBigestModes(), and extractNHighestModes().
Definition at line 32 of file FiniteDifference.cpp.
References std::nextafter().
Referenced by derivative(), and derivative2nd().
double Euclid::MathUtils::integrate | ( | const Function & | function, |
const double | min, | ||
const double | max, | ||
std::unique_ptr< NumericalIntegrationScheme > | numericalIntegrationScheme = nullptr |
||
) |
Returns the integral of the given function inside the range [min,max]. This method will take advantage of Functions which also implement the Integrable interface. For other Function the integration will be delegated to the NumericalIntegrationScheme. Note that at the moment there is no default numerical implementation, so if the given function is not Integrable and no numerical integration scheme is provided an exception will be thrown.
function | The function to integrate |
min | The minimum range of the integration |
max | The maximum range of the integration |
numericalIntegrationScheme | The class in charge of the numerical integration (if the function do not implement the Integrable interface). |
Definition at line 35 of file function_tools.cpp.
Referenced by Euclid::MathUtils::Differentiable::indefiniteIntegral(), Euclid::MathUtils::Piecewise::integrate(), and Euclid::MathUtils::Piecewise::~Piecewise().
ELEMENTS_API std::unique_ptr< NAryFunction< N > > Euclid::MathUtils::interpn | ( | const Coordinates< N > & | grid, |
const NdArray::NdArray< double > & | values, | ||
InterpolationType | type, | ||
bool | extrapolate = false |
||
) |
std::unique_ptr< Function > Euclid::MathUtils::interpolate | ( | const Euclid::XYDataset::XYDataset & | dataset, |
InterpolationType | type, | ||
bool | extrapolate = false |
||
) |
Returns a Function which performs interpolation for the data points of the given dataset.
dataset | The dataset containing the data points |
type | The type of the interpolation to perform |
InterpolationException | if there are decreasing x values |
InterpolationException | if there are (X,Y) pairs with same X value but different Y value (step functions) |
Definition at line 88 of file interpolation.cpp.
References std::array< T >::back(), CUBIC_SPLINE, std::array< T >::empty(), std::array< T >::front(), LINEAR, linearInterpolation(), std::array< T >::size(), and splineInterpolation().
std::unique_ptr< Function > Euclid::MathUtils::interpolate | ( | const std::vector< double > & | x, |
const std::vector< double > & | y, | ||
InterpolationType | type, | ||
bool | extrapolate = false |
||
) |
Returns a Function which performs interpolation for the given set of data points. Duplicate (x,y) pairs are ignored and treated as a single one.
x | The x values of the data points |
y | The y values of the data points |
type | The type of the interpolation to perform |
InterpolationException | if the x and y vectors do not have the same size |
InterpolationException | if there are decreasing x values |
InterpolationException | if there are (X,Y) pairs with same X value but different Y value (step functions) |
Definition at line 40 of file interpolation.cpp.
References CUBIC_SPLINE, std::array< T >::front(), LINEAR, linearInterpolation(), std::array< T >::size(), and splineInterpolation().
Referenced by Euclid::MathUtils::Cumulative::eval().
std::unique_ptr< Function > Euclid::MathUtils::linearInterpolation | ( | const std::vector< double > & | x, |
const std::vector< double > & | y, | ||
bool | extrapolate | ||
) |
Performs linear interpolation for the given set of data points.
Definition at line 129 of file linear.cpp.
References std::array< T >::back(), std::array< T >::front(), std::numeric_limits::lowest(), std::numeric_limits::max(), std::move(), and std::array< T >::size().
Referenced by interpolate(), and interpolate().
std::pair< double, double > Euclid::MathUtils::linearRegression | ( | const std::vector< double > & | x, |
const std::vector< double > & | y | ||
) |
Computes factors a and b such that y = a * x + b
x | Independent variable |
y | Dependent variable |
Definition at line 25 of file LinearRegression.cpp.
References std::array< T >::empty(), std::make_pair(), and std::array< T >::size().
std::unique_ptr< Function > Euclid::MathUtils::multiply | ( | const Function & | f1, |
const Function & | f2 | ||
) |
Returns a function which represents the multiplication of the two parameters. This method makes use of the multiplySpecificSpecificMap and multiplySpecificGenericMap maps for detecting efficient ways of multiplying the parameters.
f1 | The first function to multiply |
f2 | The second function to multiply |
Definition at line 72 of file function_tools.cpp.
References std::array< T >::end(), multiplySpecificGenericMap, and multiplySpecificSpecificMap.
Referenced by multiplyPiecewises().
std::unique_ptr< Function > Euclid::MathUtils::multiplyPiecewises | ( | const Function & | f1, |
const Function & | f2 | ||
) |
Definition at line 101 of file multiplication.cpp.
References std::array< T >::back(), std::array< T >::empty(), std::move(), multiply(), and overlappingKnots().
std::unique_ptr< Function > Euclid::MathUtils::multiplyPiecewiseWithGeneric | ( | const Function & | f1, |
const Function & | f2 | ||
) |
Function for multiplying a Piecewise with any other type. It multiplies each sub-function of the Piecewise with the other function.
Definition at line 53 of file multiplication.cpp.
References std::array< T >::begin(), std::array< T >::end(), std::array< T >::size(), and std::transform().
std::unique_ptr< Function > Euclid::MathUtils::multiplyPolynomials | ( | const Function & | f1, |
const Function & | f2 | ||
) |
Function for multiplying two Polynomials. It multiplies their coefficients.
Definition at line 39 of file multiplication.cpp.
References std::move(), and std::array< T >::size().
std::vector< double > Euclid::MathUtils::overlappingKnots | ( | const std::vector< double > & | knots1, |
const std::vector< double > & | knots2 | ||
) |
Returns a vector of the overlapping knots from the given vectors.
Definition at line 82 of file multiplication.cpp.
References std::array< T >::begin(), std::array< T >::end(), overlappingStart(), and std::tie().
Referenced by multiplyPiecewises().
|
static |
Definition at line 64 of file multiplication.cpp.
Referenced by overlappingKnots().
SecantReturn Euclid::MathUtils::secantMethod | ( | const Function & | func, |
double | x0, | ||
double | x1, | ||
const SecantParams & | params = SecantParams{} |
||
) |
Find the root of the function func (i.e. func(root) = 0) applying the secant method. The solution should be close to the initial guesses x0, x1
func | The function to solve |
x0 | |
x1 | |
params |
Definition at line 25 of file SecantMethod.cpp.
References GRADIENT, std::isfinite(), OUT_OF_BOUNDS, SUCCESS, and VALUE_ERROR.
double Euclid::MathUtils::simple_interpolation | ( | double | x, |
const std::vector< double > & | xp, | ||
const std::vector< double > & | yp, | ||
bool | extrapolate = false |
||
) |
Simple linear interpolation
x | Target value |
xp | x samples |
yp | Function samples (yp = f(xp)) |
extrapolate | If true, extrapolate |
Definition at line 125 of file interpolation.cpp.
References std::array< T >::back(), std::array< T >::begin(), std::array< T >::empty(), std::array< T >::end(), std::array< T >::front(), simple_interpolation(), std::array< T >::size(), and std::upper_bound().
Referenced by simple_interpolation().
|
noexcept |
Linear interpolation on a segment
Definition at line 153 of file interpolation.cpp.
std::pair< double, double > Euclid::MathUtils::solveSquare | ( | double | a, |
double | b, | ||
double | c, | ||
double | y | ||
) |
Solve x for y = a * x^2 + b * x + c
Elements::Exception | If a == b == 0. (can not be solved) |
Definition at line 25 of file Solvers.cpp.
References std::make_pair(), and std::sqrt().
std::unique_ptr< Function > Euclid::MathUtils::splineInterpolation | ( | const std::vector< double > & | x, |
const std::vector< double > & | y, | ||
bool | extrapolate | ||
) |
Performs cubic spline interpolation for the given set of data points.
Definition at line 139 of file spline.cpp.
References std::array< T >::back(), std::array< T >::front(), std::numeric_limits::lowest(), std::numeric_limits::max(), std::move(), and std::array< T >::size().
Referenced by interpolate(), and interpolate().
std::map< std::type_index, MultiplyFunction > Euclid::MathUtils::multiplySpecificGenericMap |
A map for retrieving specific function multiplication implementations. The keys of the map are the type of a Function which can be multiplied with any other function and the value of the map is the function which can be used for performing this multiplication in an efficient way.
Definition at line 136 of file multiplication.cpp.
Referenced by multiply().
std::map< std::pair< std::type_index, std::type_index >, MultiplyFunction > Euclid::MathUtils::multiplySpecificSpecificMap |
A map for retrieving specific function multiplication implementations. The keys of the map are the pairs of the Function types and the value of the map is the function which can be used for performing this multiplication in an efficient way.
Definition at line 132 of file multiplication.cpp.
Referenced by multiply().