Alexandria 2.31.0
SDC-CH common library for the Euclid project
Loading...
Searching...
No Matches
Classes | Typedefs | Enumerations | Functions | Variables
Euclid::MathUtils Namespace Reference

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
}
 

Functions

ELEMENTS_API double integrate (const Function &function, const double min, const double max, std::unique_ptr< NumericalIntegrationScheme > numericalIntegrationScheme=nullptr)
 
ELEMENTS_API std::unique_ptr< Functionmultiply (const Function &f1, const Function &f2)
 
std::pair< double, doublesolveSquare (double a, double b, double c, double y)
 
ELEMENTS_API std::unique_ptr< Functioninterpolate (const std::vector< double > &x, const std::vector< double > &y, InterpolationType type, bool extrapolate=false)
 
ELEMENTS_API std::unique_ptr< Functioninterpolate (const Euclid::XYDataset::XYDataset &dataset, InterpolationType type, bool extrapolate=false)
 
template<std::size_t N>
ELEMENTS_API std::unique_ptr< NAryFunction< N > > interpn (const Coordinates< N > &grid, const NdArray::NdArray< double > &values, InterpolationType type, bool extrapolate=false)
 
ELEMENTS_API double simple_interpolation (double x, const std::vector< double > &xp, const std::vector< double > &yp, bool extrapolate=false)
 
ELEMENTS_API double simple_interpolation (double x, double x0, double x1, double y0, double y1, bool extrapolate) noexcept
 
double derivative (const Function &f, const double x)
 
double derivative2nd (const Function &f, const double x)
 
template<typename... Axes>
std::unique_ptr< NdSampler< Axes... > > createSamplerFromGrid (const GridContainer::GridContainer< std::vector< double >, Axes... > &grid)
 
template<typename CellAxis , typename... GridAxes>
std::unique_ptr< NdSampler< CellAxis, GridAxes... > > createSamplerFromGrid (const GridContainer::GridContainer< std::vector< std::vector< double > >, GridAxes... > &grid, const std::vector< CellAxis > &cell_axis)
 
template<typename... GridAxes>
std::unique_ptr< NdSampler< std::size_t, GridAxes... > > createSamplerFromGrid (const GridContainer::GridContainer< std::vector< std::vector< double > >, GridAxes... > &grid)
 
std::vector< ModeInfoextractNHighestModes (const XYDataset::XYDataset &pdf, double merge_ratio, size_t n)
 
std::vector< ModeInfoextractNHighestModes (std::vector< double > &x_sampling, std::vector< double > &pdf_sampling, double merge_ratio, size_t n)
 
std::vector< ModeInfoextractNBigestModes (const XYDataset::XYDataset &pdf, double merge_ratio, size_t n)
 
std::vector< ModeInfoextractNBigestModes (std::vector< double > &x_sampling, std::vector< double > &pdf_sampling, double merge_ratio, size_t n)
 
std::pair< double, doublelinearRegression (const std::vector< double > &x, const std::vector< double > &y)
 
SecantReturn secantMethod (const Function &func, double x0, double x1, const SecantParams &params=SecantParams{})
 
std::unique_ptr< FunctionmultiplyPolynomials (const Function &f1, const Function &f2)
 Function for multiplying two Polynomials. It multiplies their coefficients.
 
std::unique_ptr< FunctionmultiplyPiecewiseWithGeneric (const Function &f1, const Function &f2)
 
template<typename Iter >
static std::pair< Iter, IteroverlappingStart (Iter start1, Iter end1, Iter start2, Iter end2)
 
std::vector< doubleoverlappingKnots (const std::vector< double > &knots1, const std::vector< double > &knots2)
 Returns a vector of the overlapping knots from the given vectors.
 
std::unique_ptr< FunctionmultiplyPiecewises (const Function &f1, const Function &f2)
 
std::unique_ptr< FunctionlinearInterpolation (const std::vector< double > &x, const std::vector< double > &y, bool extrapolate)
 Performs linear interpolation for the given set of data points.
 
std::unique_ptr< FunctionsplineInterpolation (const std::vector< double > &x, const std::vector< double > &y, bool extrapolate)
 Performs cubic spline interpolation for the given set of data points.
 
static double guess_h (double initial_h, double x)
 
std::pair< std::vector< double >, std::vector< double > > getXYs (const XYDataset::XYDataset &pdf)
 
size_t findMaximumIndex (const std::vector< double > &pdf)
 
std::pair< size_t, size_t > catchPeak (const std::vector< double > &pdf, size_t center_index, double merge_ratio)
 
std::pair< double, doubleavgArea (std::pair< std::vector< double >, std::vector< double > > &pdf, size_t min_x, size_t max_x)
 
double getInterpolationAround (const std::pair< std::vector< double >, std::vector< double > > &pdf, size_t x_index)
 
std::pair< std::vector< double >, std::vector< double > > flatternPeak (const std::pair< std::vector< double >, std::vector< double > > &pdf, size_t min_x, size_t max_x, double value)
 

Variables

ELEMENTS_API std::map< std::pair< std::type_index, std::type_index >, MultiplyFunctionmultiplySpecificSpecificMap
 
ELEMENTS_API std::map< std::type_index, MultiplyFunctionmultiplySpecificGenericMap
 

Typedef Documentation

◆ BinaryFunction

Alias for a binary function.

Definition at line 119 of file Function.h.

◆ Coordinates

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

Template Parameters
NNumber of dimensions
Examples
/builddir/build/BUILD/Alexandria-2.31.0/MathUtils/MathUtils/interpolation/interpolation.h.

Definition at line 86 of file interpolation.h.

◆ Function

Alias for an unary function.

Definition at line 116 of file Function.h.

◆ MultiplyFunction

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.

◆ TernaryFunction

Alias for a ternary function.

Definition at line 122 of file Function.h.

Enumeration Type Documentation

◆ InterpolationType

Enumeration of the different supported interpolation types.

Enumerator
LINEAR 
CUBIC_SPLINE 
Examples
/builddir/build/BUILD/Alexandria-2.31.0/MathUtils/MathUtils/interpolation/interpolation.h.

Definition at line 43 of file interpolation.h.

◆ SecantEndReason

Enumerator
SUCCESS 
MAX_ITER 
GRADIENT 
OUT_OF_BOUNDS 
VALUE_ERROR 

Definition at line 28 of file SecantMethod.h.

Function Documentation

◆ avgArea()

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().

Here is the call graph for this function:

◆ catchPeak()

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().

Here is the call graph for this function:

◆ createSamplerFromGrid() [1/3]

template<typename... Axes>
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

Template Parameters
AxesGrid axes

The compiler should be able to infer the axis types. Example:

std::unique_ptr< NdSampler< Axes... > > createSamplerFromGrid(const GridContainer::GridContainer< std::vector< double >, Axes... > &grid)

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().

Here is the call graph for this function:

◆ createSamplerFromGrid() [2/3]

template<typename... GridAxes>
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.

Template Parameters
GridAxesGrid 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().

Here is the call graph for this function:

◆ createSamplerFromGrid() [3/3]

template<typename CellAxis , typename... GridAxes>
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.

Template Parameters
GridAxesGrid axes
CellAxisAxis embedded into the cell

The compiler should be able to infer the axis types. Example:

Parameters
gridThe GridContainer
cell_axisUser-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().

Here is the call graph for this function:

◆ derivative()

double Euclid::MathUtils::derivative ( const Function f,
const double  x 
)

Derivative using finite differences: \( f'(x) = \frac{f(x+h) - f(x)}{h} \)

Note
h is computed automatically following the same approach as boost numeric differentiation: \( h =(x + \sqrt{\epsilon} * 2) - x \) This guarantees that xh is representable using floating point (since (x + h) - x is not necessarily equal to h) If h happens to be 0, std::nextafter is called
Parameters
fThe Function to derive
xThe point where to do the derivation
Returns
An approximation of f'(x)

Definition at line 41 of file FiniteDifference.cpp.

References guess_h(), and std::sqrt().

Referenced by Euclid::MathUtils::Polynomial::~Polynomial().

Here is the call graph for this function:

◆ derivative2nd()

double Euclid::MathUtils::derivative2nd ( const Function f,
const double  x 
)

Second derivative using finite differences: \( f''(x) = \frac{f(x+h) - 2f(x) + f(x - h)}{h^2} \)

Note
h is computed automatically as follows: \( h =(x + \sqrt[4]{\epsilon} * 2) - x \) This guarantees that xh is representable using floating point (since (x + h) - x is not necessarily equal to h) If h happens to be 0, std::nextafter is called
Parameters
fThe Function to derive
xThe point where to do the derivation
Returns
An approximation of f''(x)

Definition at line 50 of file FiniteDifference.cpp.

References guess_h(), and std::sqrt().

Here is the call graph for this function:

◆ extractNBigestModes() [1/2]

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.

Parameters
pdfThe sampling of the pdf to be analysed.
merge_ratioThe parameter for mode cutting.
nThe (maximum) number of modes to be returned.
Returns
A vector of ModeInfo containing the position and the area of the modes.

Definition at line 239 of file PdfModeExtraction.cpp.

References extractNBigestModes(), and getXYs().

Referenced by extractNBigestModes().

Here is the call graph for this function:

◆ extractNBigestModes() [2/2]

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.

Parameters
x_samplingThe horizontal sampling of the pdf to be analysed.
pdf_samplingThe sampling of the pdf to be analysed.
merge_ratioThe parameter for mode cutting.
nThe (maximum) number of modes to be returned.
Returns
A vector of ModeInfo containing the position and the area of the modes.

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().

Here is the call graph for this function:

◆ extractNHighestModes() [1/2]

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.

Parameters
pdfThe sampling of the pdf to be analysed.
merge_ratioThe parameter for mode cutting.
nThe (maximum) number of modes to be returned.
Returns
A vector of ModeInfo containing the position and the area of the modes.

Definition at line 193 of file PdfModeExtraction.cpp.

References extractNHighestModes(), and getXYs().

Referenced by extractNHighestModes().

Here is the call graph for this function:

◆ extractNHighestModes() [2/2]

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.

Parameters
x_samplingThe horizontal sampling of the pdf to be analysed.
pdf_samplingThe sampling of the pdf to be analysed.
merge_ratioThe parameter for mode cutting.
nThe (maximum) number of modes to be returned.
Returns
A vector of ModeInfo containing the position and the area of the modes.

Definition at line 176 of file PdfModeExtraction.cpp.

References avgArea(), catchPeak(), findMaximumIndex(), flatternPeak(), getInterpolationAround(), and std::make_pair().

Here is the call graph for this function:

◆ findMaximumIndex()

size_t Euclid::MathUtils::findMaximumIndex ( const std::vector< double > &  pdf)

Definition at line 50 of file PdfModeExtraction.cpp.

References std::array< T >::begin(), and std::array< T >::end().

Referenced by extractNBigestModes(), and extractNHighestModes().

Here is the call graph for this function:

◆ flatternPeak()

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().

Here is the call graph for this function:

◆ getInterpolationAround()

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().

Here is the call graph for this function:

◆ getXYs()

std::pair< std::vector< double >, std::vector< double > > Euclid::MathUtils::getXYs ( const XYDataset::XYDataset pdf)

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().

Here is the call graph for this function:

◆ guess_h()

static double Euclid::MathUtils::guess_h ( double  initial_h,
double  x 
)
static

Definition at line 32 of file FiniteDifference.cpp.

References std::nextafter().

Referenced by derivative(), and derivative2nd().

Here is the call graph for this function:

◆ integrate()

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.

Parameters
functionThe function to integrate
minThe minimum range of the integration
maxThe maximum range of the integration
numericalIntegrationSchemeThe class in charge of the numerical integration (if the function do not implement the Integrable interface).
Returns
The integral in the range [min,max]

Definition at line 35 of file function_tools.cpp.

Referenced by Euclid::MathUtils::Differentiable::indefiniteIntegral(), Euclid::MathUtils::Piecewise::integrate(), and Euclid::MathUtils::Piecewise::~Piecewise().

◆ interpn()

template<std::size_t N>
ELEMENTS_API std::unique_ptr< NAryFunction< N > > Euclid::MathUtils::interpn ( const Coordinates< N > &  grid,
const NdArray::NdArray< double > &  values,
InterpolationType  type,
bool  extrapolate = false 
)

◆ interpolate() [1/2]

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.

Parameters
datasetThe dataset containing the data points
typeThe type of the interpolation to perform
Returns
A function representing the interpolation
Exceptions
InterpolationExceptionif there are decreasing x values
InterpolationExceptionif 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().

Here is the call graph for this function:

◆ interpolate() [2/2]

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.

Parameters
xThe x values of the data points
yThe y values of the data points
typeThe type of the interpolation to perform
Returns
A function representing the interpolation
Exceptions
InterpolationExceptionif the x and y vectors do not have the same size
InterpolationExceptionif there are decreasing x values
InterpolationExceptionif there are (X,Y) pairs with same X value but different Y value (step functions)
Examples
/builddir/build/BUILD/Alexandria-2.31.0/MathUtils/MathUtils/interpolation/interpolation.h.

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().

Here is the call graph for this function:

◆ linearInterpolation()

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().

Here is the call graph for this function:

◆ linearRegression()

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

Parameters
xIndependent variable
yDependent variable
Returns
The factors (a, b)

Definition at line 25 of file LinearRegression.cpp.

References std::array< T >::empty(), std::make_pair(), and std::array< T >::size().

Here is the call graph for this function:

◆ multiply()

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.

Parameters
f1The first function to multiply
f2The second function to multiply
Returns
A function representing the multiplication of the parameters

Definition at line 72 of file function_tools.cpp.

References std::array< T >::end(), multiplySpecificGenericMap, and multiplySpecificSpecificMap.

Referenced by multiplyPiecewises().

Here is the call graph for this function:

◆ 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().

Here is the call graph for this function:

◆ multiplyPiecewiseWithGeneric()

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().

Here is the call graph for this function:

◆ multiplyPolynomials()

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().

Here is the call graph for this function:

◆ overlappingKnots()

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().

Here is the call graph for this function:

◆ overlappingStart()

template<typename Iter >
static std::pair< Iter, Iter > Euclid::MathUtils::overlappingStart ( Iter  start1,
Iter  end1,
Iter  start2,
Iter  end2 
)
static

Definition at line 64 of file multiplication.cpp.

Referenced by overlappingKnots().

◆ secantMethod()

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

Parameters
funcThe function to solve
x0
x1
params
Returns
The result of the root solution
See also
SecantReturn
SecantEndReason

Definition at line 25 of file SecantMethod.cpp.

References GRADIENT, std::isfinite(), OUT_OF_BOUNDS, SUCCESS, and VALUE_ERROR.

Here is the call graph for this function:

◆ simple_interpolation() [1/2]

double Euclid::MathUtils::simple_interpolation ( double  x,
const std::vector< double > &  xp,
const std::vector< double > &  yp,
bool  extrapolate = false 
)

Simple linear interpolation

Parameters
xTarget value
xpx samples
ypFunction samples (yp = f(xp))
extrapolateIf true, extrapolate
Returns
An approximation for f(x)
Examples
/builddir/build/BUILD/Alexandria-2.31.0/MathUtils/MathUtils/interpolation/interpolation.h.

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().

Here is the call graph for this function:

◆ simple_interpolation() [2/2]

double Euclid::MathUtils::simple_interpolation ( double  x,
double  x0,
double  x1,
double  y0,
double  y1,
bool  extrapolate 
)
noexcept

Linear interpolation on a segment

Definition at line 153 of file interpolation.cpp.

◆ solveSquare()

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

Returns
A pair with the two (or one) possible solution
Exceptions
Elements::ExceptionIf a == b == 0. (can not be solved)

Definition at line 25 of file Solvers.cpp.

References std::make_pair(), and std::sqrt().

Here is the call graph for this function:

◆ splineInterpolation()

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().

Here is the call graph for this function:

Variable Documentation

◆ multiplySpecificGenericMap

std::map< std::type_index, MultiplyFunction > Euclid::MathUtils::multiplySpecificGenericMap
Initial value:
{
{typeid(Piecewise), &multiplyPiecewiseWithGeneric}}

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().

◆ multiplySpecificSpecificMap

std::map< std::pair< std::type_index, std::type_index >, MultiplyFunction > Euclid::MathUtils::multiplySpecificSpecificMap
Initial value:
{
{std::pair<std::type_index, std::type_index>(typeid(Polynomial), typeid(Polynomial)), &multiplyPolynomials},
Represents a piecewise function.
Definition Piecewise.h:87
std::unique_ptr< Function > multiplyPolynomials(const Function &f1, const Function &f2)
Function for multiplying two Polynomials. It multiplies their coefficients.
std::unique_ptr< Function > multiplyPiecewises(const Function &f1, const Function &f2)

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().