1 #ifndef NPSTAT_DENSITYSCANND_HH_
2 #define NPSTAT_DENSITYSCANND_HH_
30 template<
class IndexMapper>
44 const std::vector<IndexMapper>& maps,
45 double normfactor=1.0)
46 : fcn_(fcn), mapping_(new std::vector<IndexMapper>(maps)),
47 normfactor_(normfactor), dim_(fcn.dim())
49 if (!(dim_ && dim_ == mapping_->size()))
throw std::invalid_argument(
50 "In npstat::DensityScanND constructor: incompatible arguments");
51 if (dim_ > CHAR_BIT*
sizeof(
unsigned long))
throw std::invalid_argument(
52 "In npstat::DensityScanND constructor: dimensionality is too high");
55 inline void getCoords(
const unsigned* index,
const unsigned indexLen,
58 if (dim_ != indexLen)
throw std::invalid_argument(
59 "In npstat::DensityScanND::getCoords: "
60 "incompatible index dimensionality");
63 const IndexMapper* mappers = &(*mapping_)[0];
64 for (
unsigned i=0; i<indexLen; ++i)
65 coords[i] = mappers[i](
static_cast<double>(index[i]));
68 inline double operator()(
const unsigned* index,
unsigned indexLen)
const
70 double x[CHAR_BIT*
sizeof(
unsigned long)];
71 getCoords(index, indexLen, x);
72 return normfactor_*fcn_.
density(x, indexLen);
81 const AbsDistributionND& fcn_;
82 std::shared_ptr<std::vector<IndexMapper> > mapping_;
88 inline void mapIndex(
const unsigned* index,
unsigned indexLen,
89 double* coords,
unsigned lenCoords)
91 if (dim_ != lenCoords)
throw std::invalid_argument(
92 "In npstat::DensityScanND::mapIndex: "
93 "incompatible coordinate dimensionality");
94 this->getCoords(index, indexLen, coords);
100 template<
class IndexMapper>
101 inline DensityScanND<IndexMapper> makeDensityScanND(
102 const AbsDistributionND& fcn,
const std::vector<IndexMapper>& axes,
103 double normfactor=1.0)
105 return DensityScanND<IndexMapper>(fcn, axes, normfactor);
Interface definition for multivariate continuous statistical distributions.
Definition: AbsDistributionND.hh:26
virtual double density(const double *x, unsigned dim) const =0
Definition: DensityScanND.hh:32
DensityScanND(const AbsDistributionND &fcn, const std::vector< IndexMapper > &maps, double normfactor=1.0)
Definition: DensityScanND.hh:43
Definition: AbsArrayProjector.hh:14