24#include "pybind11/pybind11.h"
25#include "pybind11/eigen.h"
26#include "pybind11/stl.h"
28#include "ndarray/pybind11.h"
33using namespace pybind11::literals;
40using Sampler = TruncatedGaussianSampler;
41using Evaluator = TruncatedGaussianEvaluator;
42using LogEvaluator = TruncatedGaussianLogEvaluator;
44using PyTruncatedGaussian = py::class_<TruncatedGaussian, std::shared_ptr<TruncatedGaussian>>;
45using PySampler = py::class_<Sampler, std::shared_ptr<Sampler>>;
46using PyEvaluator = py::class_<Evaluator, std::shared_ptr<Evaluator>>;
47using PyLogEvaluator = py::class_<LogEvaluator, std::shared_ptr<LogEvaluator>>;
52template <
typename Class,
typename PyClass>
54 PyClass cls(mod, (
"TruncatedGaussian" +
name).c_str());
55 cls.def(py::init<TruncatedGaussian const &>(),
"parent"_a);
57 (
Scalar (Class::*)(ndarray::Array<Scalar const, 1, 1>
const &)
const) & Class::operator(),
59 cls.def(
"__call__", (
void (Class::*)(ndarray::Array<Scalar const, 2, 1>
const &,
60 ndarray::Array<Scalar, 1, 1>
const &)
const) &
62 "alpha"_a,
"output"_a);
69 py::module::import(
"lsst.afw.math");
71 PyTruncatedGaussian cls(mod,
"TruncatedGaussian");
72 py::enum_<TruncatedGaussian::SampleStrategy>(cls,
"SampleStrategy")
84 "minRejectionEfficiency"_a = 0.1);
93 cls.attr(
"LogEvaluator") = declareEvaluator<LogEvaluator, PyLogEvaluator>(mod,
"LogEvaluator");
94 cls.attr(
"Evaluator") = declareEvaluator<Evaluator, PyEvaluator>(mod,
"Evaluator");
96 PySampler clsSampler(mod,
"TruncatedGaussianSampler");
97 clsSampler.def(py::init<TruncatedGaussian const &, TruncatedGaussian::SampleStrategy>(),
"parent"_a,
99 clsSampler.def(
"__call__",
100 (
Scalar (Sampler::*)(afw::math::Random &, ndarray::Array<Scalar, 1, 1>
const &)
const) &
103 clsSampler.def(
"__call__", (
void (Sampler::*)(afw::math::Random &, ndarray::Array<Scalar, 2, 1>
const &,
104 ndarray::Array<Scalar, 1, 1>
const &,
bool)
const) &
106 "rng"_a,
"alpha"_a,
"weights"_a,
"multiplyWeights"_a =
false);
108 cls.attr(
"Sampler") = clsSampler;
table::Key< std::string > name
LogEvaluator evaluateLog() const
Create a LogEvaluator object that can be used to efficiently evaluate the -log of the function.
Scalar getLogIntegral() const
Return the -log of the integral of the truncated function.
Scalar getLogPeakAmplitude() const
Return the -log of the peak amplitude of the untruncated function.
Vector maximize() const
Return the location of the maximum of the truncated Gaussian.
int getDim() const
Return the dimensionality of the function.
static TruncatedGaussian fromStandardParameters(Vector const &mean, Matrix const &covariance)
Create from the "standard" mean and covariance parameters of the normal distribution.
SampleStrategy
Enum that describes different ways of sampling from a multidimensional TruncatedGaussian.
@ ALIGN_AND_WEIGHT
Create a similar Gaussian with no x-y covariance, and importance sample by drawing from the independe...
@ DIRECT_WITH_REJECTION
Draw from the untruncated Gaussian, and discard negative draws.
Scalar getUntruncatedFraction() const
Return the fraction of the Gaussian integral that was truncated by the bounds.
static TruncatedGaussian fromSeriesParameters(Scalar q0, Vector const &gradient, Matrix const &hessian)
Create from the first and second logarithmic derivatives of the Gaussian.
Evaluator evaluate() const
Create an Evaluator object that can be used to efficiently evaluate the function.
Sampler sample(SampleStrategy strategy) const
Create a Sampler object that uses the given strategy.
PYBIND11_MODULE(_cameraGeom, mod)
py::class_< PixelAreaBoundedField, std::shared_ptr< PixelAreaBoundedField >, BoundedField > PyClass
double Scalar
Typedefs to be used for probability and parameter values.
A base class for image defects.