Project
Loading...
Searching...
No Matches
o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly > Class Template Reference

#include <NDPiecewisePolynomials.h>

Inherits o2::gpu::FlatObject.

Public Member Functions

 NDPiecewisePolynomials (const float min[], const float max[], const uint32_t n[])
 
 NDPiecewisePolynomials (const char *fileName, const char *name)
 
 NDPiecewisePolynomials ()=default
 default constructor
 
 ~NDPiecewisePolynomials ()=default
 default destructor
 
 NDPiecewisePolynomials (const NDPiecewisePolynomials &obj)
 Copy constructor.
 
void cloneFromObject (const NDPiecewisePolynomials &obj, char *newFlatBufferPtr)
 ========== FlatObject functionality, see FlatObject class for description =================
 
void moveBufferTo (char *newBufferPtr)
 
void destroy ()
 destroy the object (release internal flat buffer)
 
void setActualBufferAddress (char *actualFlatBufferPtr)
 set location of external flat buffer
 
void setFutureBufferAddress (char *futureFlatBufferPtr)
 set future location of the flat buffer
 
 GPUd () float eval(float x[]) const
 
 GPUd () float evalUnsafe(const float x[]) const
 
 GPUd () float evalPol(const float x[]
 
 GPUd () float getXMin(const uint32_t dim) const
 
 GPUd () float getXMax(const uint32_t dim) const
 
 GPUd () float getInvSpacing(const uint32_t dim) const
 
 GPUd () uint32_t getNVertices(const uint32_t dim) const
 
 GPUd () uint32_t getNPolynomials(const uint32_t dim) const
 
 GPUd () const float *getParams() const
 
void init (const float min[], const float max[], const uint32_t n[])
 
void setParams (const float params[])
 Setting directly the parameters of the polynomials.
 
void performFits (const std::function< double(const double x[])> &func, const uint32_t nAuxiliaryPoints[])
 
void performFits (const std::vector< float > &x, const std::vector< float > &y)
 
void loadFromFile (TFile &inpf, const char *name)
 
void loadFromFile (const char *fileName, const char *name)
 
void writeToFile (TFile &outf, const char *name) const
 
void setDefault ()
 setting default polynomials which just returns 1
 
void dumpToTree (const uint32_t nSamplingPoints[], const char *outName="debug.root", const char *treeName="tree", const bool recreateFile=true) const
 
uint32_t getNPolynomials () const
 
NDPiecewisePolynomialContainer getContainer () const
 converts the class to a container which can be written to a root file
 
void setFromContainer (const NDPiecewisePolynomialContainer &container)
 
uint32_t getNParameters () const
 
 GPUd () static const expr uint32_t getDim()
 
 GPUd () static const expr uint32_t getDegree()
 
 GPUd () static const expr bool isInteractionOnly()
 
- Public Member Functions inherited from o2::gpu::FlatObject
 FlatObject ()=default
 _____________ Constructors / destructors __________________________
 
 ~FlatObject ()
 
 FlatObject (const FlatObject &)=delete
 
FlatObjectoperator= (const FlatObject &)=delete
 
void destroy ()
 _______________ Utilities _______________________________________________
 
size_t getFlatBufferSize () const
 Gives size of the flat buffer.
 
const chargetFlatBufferPtr () const
 Gives pointer to the flat buffer.
 
bool isConstructed () const
 Tells if the object is constructed.
 
bool isBufferInternal () const
 Tells if the buffer is internal.
 
void adoptInternalBuffer (char *buf)
 
void clearInternalBufferPtr ()
 
void printC () const
 Print the content of the flat buffer.
 

Public Attributes

const int32_t index[] const { return MultivariatePolynomialHelper<Dim, Degree, InteractionOnly>::evalPol(getParameters(index), x)
 

Additional Inherited Members

- Static Public Member Functions inherited from o2::gpu::FlatObject
static size_t alignSize (size_t sizeBytes, size_t alignmentBytes)
 _______________ Generic utilities _______________________________________________
 
template<class T >
static T * relocatePointer (const char *oldBase, char *newBase, const T *ptr)
 Relocates a pointer inside a buffer to the new buffer address.
 
template<class T , class TFile >
static int32_t writeToFile (T &obj, TFile &outf, const char *name)
 write a child class object to the file
 
template<class T , class TFile >
static T * readFromFile (TFile &inpf, const char *name)
 read a child class object from the file
 
template<class T >
static std::string stressTest (T &obj)
 Test the flat object functionality for a child class T.
 
- Protected Types inherited from o2::gpu::FlatObject
enum  ConstructionState : uint32_t { NotConstructed = 0x0 , Constructed = 0x1 , InProgress = 0x2 }
 GPUCA_GPUCODE. More...
 
- Protected Member Functions inherited from o2::gpu::FlatObject
void startConstruction ()
 _____________ Construction _________
 
void finishConstruction (int32_t flatBufferSize)
 
void cloneFromObject (const FlatObject &obj, char *newFlatBufferPtr)
 
charreleaseInternalBuffer ()
 _____________ Methods for making the data buffer external __________________________
 
void moveBufferTo (char *newBufferPtr)
 
void setActualBufferAddress (char *actualFlatBufferPtr)
 _____________ Methods for moving the class with its external buffer to another location __________________________
 
void setFutureBufferAddress (char *futureFlatBufferPtr)
 
 ClassDefNV (FlatObject, 1)
 Pointer to the flat buffer.
 
- Static Protected Member Functions inherited from o2::gpu::FlatObject
static constexpr size_t getClassAlignmentBytes ()
 _____________ Memory alignment __________________________
 
static constexpr size_t getBufferAlignmentBytes ()
 Gives minimal alignment in bytes required for the flat buffer.
 
- Protected Attributes inherited from o2::gpu::FlatObject
int32_t mFlatBufferSize = 0
 size of the flat buffer
 
uint32_t mConstructionMask = ConstructionState::NotConstructed
 mask for constructed object members, first two bytes are used by this class
 
charmFlatBufferContainer = nullptr
 
charmFlatBufferPtr = nullptr
 

Detailed Description

template<uint32_t Dim, uint32_t Degree, bool InteractionOnly>
class o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly >

class for piecewise polynomial fits on a regular grid This class can be used to perform independent fits of nth-degree polynomials on a regular grid. The fitting should be performed on CPUs. The evaluation can be performed on CPU or GPU. A smooth function which can be evaluated on the full grid is expected to be provided when performing the fits. The main difference to splines is that the performed polynomial fits have no restrictions on the boundaries inside of the grid (it is not guaranteed that the resulting fits will be smooth at the grid vertices) The advantage to splines is the faster evaluation of the polynomials, which are still reasonable to use in higher dimensions, when performance is critical.

For usage see: testMultivarPolynomials.cxx

TODO: add possibillity to perform the fits with weighting of points

Template Parameters
Dimnumber of dimensions
Degreedegree of the polynomials
InteractionOnlyconsider only interaction terms: ignore x[0]*x[0]..., x[1]*x[1]*x[2]... etc. terms (same feature as 'interaction_only' in sklearn https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.PolynomialFeatures.html) can be used for N-linear interpolation (https://en.wikipedia.org/wiki/Trilinear_interpolation#Alternative_algorithm)

Definition at line 77 of file NDPiecewisePolynomials.h.

Constructor & Destructor Documentation

◆ NDPiecewisePolynomials() [1/4]

template<uint32_t Dim, uint32_t Degree, bool InteractionOnly>
o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly >::NDPiecewisePolynomials ( const float  min[],
const float  max[],
const uint32_t  n[] 
)
inline

constructor

Parameters
minminimum coordinates of the grid
maxmaximum coordinates of the grid (note: the resulting polynomials can NOT be evaluated at the maximum coordinates: only at min <= X < max)
nnumber of vertices: defines number of fits per dimension: nFits = n - 1. n should be at least 2 to perform one fit

Definition at line 85 of file NDPiecewisePolynomials.h.

◆ NDPiecewisePolynomials() [2/4]

template<uint32_t Dim, uint32_t Degree, bool InteractionOnly>
o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly >::NDPiecewisePolynomials ( const char fileName,
const char name 
)
inline

constructor construct and object by initializing it from an object stored in a Root file

Parameters
fileNamename of the file
namename of the object

Definition at line 89 of file NDPiecewisePolynomials.h.

◆ NDPiecewisePolynomials() [3/4]

template<uint32_t Dim, uint32_t Degree, bool InteractionOnly>
o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly >::NDPiecewisePolynomials ( )
default

default constructor

◆ ~NDPiecewisePolynomials()

template<uint32_t Dim, uint32_t Degree, bool InteractionOnly>
o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly >::~NDPiecewisePolynomials ( )
default

default destructor

◆ NDPiecewisePolynomials() [4/4]

template<uint32_t Dim, uint32_t Degree, bool InteractionOnly>
o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly >::NDPiecewisePolynomials ( const NDPiecewisePolynomials< Dim, Degree, InteractionOnly > &  obj)
inline

Copy constructor.

Definition at line 101 of file NDPiecewisePolynomials.h.

Member Function Documentation

◆ cloneFromObject()

template<uint32_t Dim, uint32_t Degree, bool InteractionOnly>
void o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly >::cloneFromObject ( const NDPiecewisePolynomials< Dim, Degree, InteractionOnly > &  obj,
char newFlatBufferPtr 
)

========== FlatObject functionality, see FlatObject class for description =================

cloning a container object (use newFlatBufferPtr=nullptr for simple copy)

Definition at line 362 of file NDPiecewisePolynomials.h.

◆ destroy()

template<uint32_t Dim, uint32_t Degree, bool InteractionOnly>
void o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly >::destroy ( )

destroy the object (release internal flat buffer)

Definition at line 410 of file NDPiecewisePolynomials.h.

◆ dumpToTree()

template<uint32_t Dim, uint32_t Degree, bool InteractionOnly>
void o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly >::dumpToTree ( const uint32_t  nSamplingPoints[],
const char outName = "debug.root",
const char treeName = "tree",
const bool  recreateFile = true 
) const

dump the polynomials to tree for visualisation

Parameters
nSamplingPointsnumber of sampling points per dimension
outNamename of the output file
treeNamename of the tree
recreateFilecreate new output file or update the output file

◆ getContainer()

template<uint32_t Dim, uint32_t Degree, bool InteractionOnly>
NDPiecewisePolynomialContainer o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly >::getContainer ( ) const
inline

converts the class to a container which can be written to a root file

Definition at line 210 of file NDPiecewisePolynomials.h.

◆ getNParameters()

template<uint32_t Dim, uint32_t Degree, bool InteractionOnly>
uint32_t o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly >::getNParameters ( ) const
inline
Returns
returns the total number of stored parameters

Definition at line 218 of file NDPiecewisePolynomials.h.

◆ getNPolynomials()

template<uint32_t Dim, uint32_t Degree, bool InteractionOnly>
uint32_t o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly >::getNPolynomials ( ) const
Returns
returns total number of polynomial fits

Definition at line 338 of file NDPiecewisePolynomials.h.

◆ GPUd() [1/12]

template<uint32_t Dim, uint32_t Degree, bool InteractionOnly>
o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly >::GPUd ( ) const
inline
Returns
returns the parameters of the coefficients

Definition at line 162 of file NDPiecewisePolynomials.h.

◆ GPUd() [2/12]

template<uint32_t Dim, uint32_t Degree, bool InteractionOnly>
o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly >::GPUd ( ) const
inline

evalute at given coordinate with boundary check (note: input values will be changed/clamped to the grid)

Parameters
xcoordinates where to interpolate

Definition at line 124 of file NDPiecewisePolynomials.h.

◆ GPUd() [3/12]

template<uint32_t Dim, uint32_t Degree, bool InteractionOnly>
o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly >::GPUd ( ) const

evaluate specific polynomial at given index for given coordinate

Parameters
xcoordinates where to interpolate
indexindex of the polynomial

◆ GPUd() [4/12]

template<uint32_t Dim, uint32_t Degree, bool InteractionOnly>
o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly >::GPUd ( ) const
inline

evalute at given coordinate (note: A boundary check for the provided coordinates is not performed!)

Parameters
xcoordinates where to interpolate (note: the resulting polynomials can NOT be evaluated at the maximum coordinates: only at min <= X < max)

Definition at line 134 of file NDPiecewisePolynomials.h.

◆ GPUd() [5/12]

template<uint32_t Dim, uint32_t Degree, bool InteractionOnly>
o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly >::GPUd ( ) const
inline
Returns
returns inverse spacing for given dimension

Definition at line 153 of file NDPiecewisePolynomials.h.

◆ GPUd() [6/12]

template<uint32_t Dim, uint32_t Degree, bool InteractionOnly>
o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly >::GPUd ( ) const
inline
Returns
returns max range for given dimension

Definition at line 150 of file NDPiecewisePolynomials.h.

◆ GPUd() [7/12]

template<uint32_t Dim, uint32_t Degree, bool InteractionOnly>
o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly >::GPUd ( ) const
inline
Returns
returns min range for given dimension

Definition at line 147 of file NDPiecewisePolynomials.h.

◆ GPUd() [8/12]

template<uint32_t Dim, uint32_t Degree, bool InteractionOnly>
o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly >::GPUd ( ) const
inline
Returns
returns whether only interaction terms are considered

Definition at line 227 of file NDPiecewisePolynomials.h.

◆ GPUd() [9/12]

template<uint32_t Dim, uint32_t Degree, bool InteractionOnly>
o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly >::GPUd ( ) const
inline
Returns
returns the degree of the polynomials

Definition at line 224 of file NDPiecewisePolynomials.h.

◆ GPUd() [10/12]

template<uint32_t Dim, uint32_t Degree, bool InteractionOnly>
o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly >::GPUd ( ) const
inline
Returns
returns number of dimensions of the polynomials

Definition at line 221 of file NDPiecewisePolynomials.h.

◆ GPUd() [11/12]

template<uint32_t Dim, uint32_t Degree, bool InteractionOnly>
o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly >::GPUd ( ) const
inline
Returns
returns number of polynomial fits for given dimension

Definition at line 159 of file NDPiecewisePolynomials.h.

◆ GPUd() [12/12]

template<uint32_t Dim, uint32_t Degree, bool InteractionOnly>
o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly >::GPUd ( ) const
inline
Returns
returns number of vertices for given dimension

Definition at line 156 of file NDPiecewisePolynomials.h.

◆ init()

template<uint32_t Dim, uint32_t Degree, bool InteractionOnly>
void o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly >::init ( const float  min[],
const float  max[],
const uint32_t  n[] 
)

initalize the members

Parameters
minminimum coordinates of the grid
maxmaximum coordinates of the grid (note: the resulting polynomials can NOT be evaluated at the maximum coordinates: only at min <= X < max)
nnumber of vertices: defines number of fits per dimension: nFits = n - 1. n should be at least 2 to perform one fit

Definition at line 397 of file NDPiecewisePolynomials.h.

◆ loadFromFile() [1/2]

template<uint32_t Dim, uint32_t Degree, bool InteractionOnly>
void o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly >::loadFromFile ( const char fileName,
const char name 
)

◆ loadFromFile() [2/2]

template<uint32_t Dim, uint32_t Degree, bool InteractionOnly>
void o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly >::loadFromFile ( TFile &  inpf,
const char name 
)

load parameters from input file (which were written using the writeToFile method)

Parameters
inpfinput file
namename of the object in the file

◆ moveBufferTo()

template<uint32_t Dim, uint32_t Degree, bool InteractionOnly>
void o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly >::moveBufferTo ( char newBufferPtr)

move flat buffer to new location

Parameters
newBufferPtrnew buffer location

Definition at line 378 of file NDPiecewisePolynomials.h.

◆ performFits() [1/2]

template<uint32_t Dim, uint32_t Degree, bool InteractionOnly>
void o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly >::performFits ( const std::function< double(const double x[])> &  func,
const uint32_t  nAuxiliaryPoints[] 
)

perform the polynomial fits on the grid

Parameters
funcfunction which returns for every input x on the defined grid the true value
nAuxiliaryPointsnumber of points which will be used for the fits (should be at least 2)

◆ performFits() [2/2]

template<uint32_t Dim, uint32_t Degree, bool InteractionOnly>
void o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly >::performFits ( const std::vector< float > &  x,
const std::vector< float > &  y 
)

perform the polynomial fits on scatter points

Parameters
xscatter points used to make the fits of size 'y.size() * Dim' as in TLinearFitter
yresponse values

◆ setActualBufferAddress()

template<uint32_t Dim, uint32_t Degree, bool InteractionOnly>
void o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly >::setActualBufferAddress ( char actualFlatBufferPtr)

set location of external flat buffer

Definition at line 417 of file NDPiecewisePolynomials.h.

◆ setDefault()

template<uint32_t Dim, uint32_t Degree, bool InteractionOnly>
void o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly >::setDefault ( )

setting default polynomials which just returns 1

Definition at line 326 of file NDPiecewisePolynomials.h.

◆ setFromContainer()

template<uint32_t Dim, uint32_t Degree, bool InteractionOnly>
void o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly >::setFromContainer ( const NDPiecewisePolynomialContainer container)

set the parameters from NDPiecewisePolynomialContainer

Parameters
containercontainer for the parameters

Definition at line 307 of file NDPiecewisePolynomials.h.

◆ setFutureBufferAddress()

template<uint32_t Dim, uint32_t Degree, bool InteractionOnly>
void o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly >::setFutureBufferAddress ( char futureFlatBufferPtr)

set future location of the flat buffer

Definition at line 424 of file NDPiecewisePolynomials.h.

◆ setParams()

template<uint32_t Dim, uint32_t Degree, bool InteractionOnly>
void o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly >::setParams ( const float  params[])
inline

Setting directly the parameters of the polynomials.

Definition at line 172 of file NDPiecewisePolynomials.h.

◆ writeToFile()

template<uint32_t Dim, uint32_t Degree, bool InteractionOnly>
void o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly >::writeToFile ( TFile &  outf,
const char name 
) const

write parameters to file

Parameters
outfoutput file
namename of the output object

Member Data Documentation

◆ const

template<uint32_t Dim, uint32_t Degree, bool InteractionOnly>
const int32_t index [] o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly >::const { return MultivariatePolynomialHelper<Dim, Degree, InteractionOnly>::evalPol(getParameters(index), x)

Definition at line 144 of file NDPiecewisePolynomials.h.


The documentation for this class was generated from the following file: