![]() |
Project
|
#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() | |
![]() | |
FlatObject ()=default | |
_____________ Constructors / destructors __________________________ | |
~FlatObject () | |
FlatObject (const FlatObject &)=delete | |
FlatObject & | operator= (const FlatObject &)=delete |
void | destroy () |
_______________ Utilities _______________________________________________ | |
size_t | getFlatBufferSize () const |
Gives size of the flat buffer. | |
const char * | getFlatBufferPtr () 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 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. | |
![]() | |
enum | ConstructionState : uint32_t { NotConstructed = 0x0 , Constructed = 0x1 , InProgress = 0x2 } |
GPUCA_GPUCODE. More... | |
![]() | |
void | startConstruction () |
_____________ Construction _________ | |
void | finishConstruction (int32_t flatBufferSize) |
void | cloneFromObject (const FlatObject &obj, char *newFlatBufferPtr) |
char * | releaseInternalBuffer () |
_____________ 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 constexpr size_t | getClassAlignmentBytes () |
_____________ Memory alignment __________________________ | |
static constexpr size_t | getBufferAlignmentBytes () |
Gives minimal alignment in bytes required for the flat buffer. | |
![]() | |
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 | |
char * | mFlatBufferContainer = nullptr |
char * | mFlatBufferPtr = nullptr |
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
Dim | number of dimensions |
Degree | degree of the polynomials |
InteractionOnly | consider 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.
|
inline |
constructor
min | minimum coordinates of the grid |
max | maximum coordinates of the grid (note: the resulting polynomials can NOT be evaluated at the maximum coordinates: only at min <= X < max) |
n | number 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.
|
inline |
constructor construct and object by initializing it from an object stored in a Root file
fileName | name of the file |
name | name of the object |
Definition at line 89 of file NDPiecewisePolynomials.h.
|
default |
default constructor
|
default |
default destructor
|
inline |
Copy constructor.
Definition at line 101 of file NDPiecewisePolynomials.h.
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.
void o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly >::destroy | ( | ) |
destroy the object (release internal flat buffer)
Definition at line 410 of file NDPiecewisePolynomials.h.
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
nSamplingPoints | number of sampling points per dimension |
outName | name of the output file |
treeName | name of the tree |
recreateFile | create new output file or update the output file |
|
inline |
converts the class to a container which can be written to a root file
Definition at line 210 of file NDPiecewisePolynomials.h.
|
inline |
Definition at line 218 of file NDPiecewisePolynomials.h.
uint32_t o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly >::getNPolynomials | ( | ) | const |
Definition at line 338 of file NDPiecewisePolynomials.h.
|
inline |
Definition at line 162 of file NDPiecewisePolynomials.h.
|
inline |
evalute at given coordinate with boundary check (note: input values will be changed/clamped to the grid)
x | coordinates where to interpolate |
Definition at line 124 of file NDPiecewisePolynomials.h.
o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly >::GPUd | ( | ) | const |
evaluate specific polynomial at given index for given coordinate
x | coordinates where to interpolate |
index | index of the polynomial |
|
inline |
evalute at given coordinate (note: A boundary check for the provided coordinates is not performed!)
x | coordinates 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.
|
inline |
Definition at line 153 of file NDPiecewisePolynomials.h.
|
inline |
Definition at line 150 of file NDPiecewisePolynomials.h.
|
inline |
Definition at line 147 of file NDPiecewisePolynomials.h.
|
inline |
Definition at line 227 of file NDPiecewisePolynomials.h.
|
inline |
Definition at line 224 of file NDPiecewisePolynomials.h.
|
inline |
Definition at line 221 of file NDPiecewisePolynomials.h.
|
inline |
Definition at line 159 of file NDPiecewisePolynomials.h.
|
inline |
Definition at line 156 of file NDPiecewisePolynomials.h.
void o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly >::init | ( | const float | min[], |
const float | max[], | ||
const uint32_t | n[] | ||
) |
initalize the members
min | minimum coordinates of the grid |
max | maximum coordinates of the grid (note: the resulting polynomials can NOT be evaluated at the maximum coordinates: only at min <= X < max) |
n | number 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.
void o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly >::loadFromFile | ( | const char * | fileName, |
const char * | name | ||
) |
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)
inpf | input file |
name | name of the object in the file |
void o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly >::moveBufferTo | ( | char * | newBufferPtr | ) |
move flat buffer to new location
newBufferPtr | new buffer location |
Definition at line 378 of file NDPiecewisePolynomials.h.
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
func | function which returns for every input x on the defined grid the true value |
nAuxiliaryPoints | number of points which will be used for the fits (should be at least 2) |
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
x | scatter points used to make the fits of size 'y.size() * Dim' as in TLinearFitter |
y | response values |
void o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly >::setActualBufferAddress | ( | char * | actualFlatBufferPtr | ) |
set location of external flat buffer
Definition at line 417 of file NDPiecewisePolynomials.h.
void o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly >::setDefault | ( | ) |
setting default polynomials which just returns 1
Definition at line 326 of file NDPiecewisePolynomials.h.
void o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly >::setFromContainer | ( | const NDPiecewisePolynomialContainer & | container | ) |
set the parameters from NDPiecewisePolynomialContainer
container | container for the parameters |
Definition at line 307 of file NDPiecewisePolynomials.h.
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.
|
inline |
Setting directly the parameters of the polynomials.
Definition at line 172 of file NDPiecewisePolynomials.h.
void o2::gpu::NDPiecewisePolynomials< Dim, Degree, InteractionOnly >::writeToFile | ( | TFile & | outf, |
const char * | name | ||
) | const |
write parameters to file
outf | output file |
name | name of the output object |
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.