47 typename G::SpaceType;
49 typename G::VectorType;
50 typename G::MatrixType;
51 { G::IsInfoForm } -> std::convertible_to<bool>;
52 { G::IsSqrtForm } -> std::convertible_to<bool>;
53 { g.space() } -> std::same_as<typename G::SpaceType const &>;
54 { g.valueDimension() } -> std::same_as<Eigen::Index>;
55 { g.differenceDimension() } -> std::same_as<Eigen::Index>;
56 { g.mean() } -> std::convertible_to<std::expected<typename G::VectorType, GaussianError>>;
57 { g.covariance() } -> std::same_as<std::expected<typename G::MatrixType, GaussianError>>;
58 { g.precision() } -> std::same_as<std::expected<typename G::MatrixType, GaussianError>>;
59 { g.covarianceRoot() } -> std::same_as<std::expected<typename G::MatrixType, GaussianError>>;
60 { g.precisionRoot() } -> std::same_as<std::expected<typename G::MatrixType, GaussianError>>;
68template <GaussianForm G>
75template <GaussianForm G>
89template <GaussianForm G>
90[[nodiscard]] std::expected<GaussianParams<typename G::SpaceType, typename G::Scalar>,
GaussianError>
93 std::expected<typename G::VectorType, GaussianError> mean = form.mean();
96 return std::unexpected{mean.error()};
98 auto covariance = form.covariance();
101 return std::unexpected{covariance.error()};
105 auto const step =
Emrys::minus(form.space(), *mean, form.reference());
111 std::move(*covariance)
137template <
typename Params_>
169 return params().valueDimension();
176 return params().differenceDimension();
183 return params().space();
190 return params().densityMean();
200 return params().densityMoments();
210 template <
typename Path>
214 return internal::marginalOverPath<Path>(
space(), [&](
auto const & kept,
auto const & keptSpace) {
215 return params().densityMarginalAt(kept, keptSpace);
222 template <
typename Path>
226 return internal::marginalOverElement<Path>(
space(), element, [&](
auto const & kept,
auto const & keptSpace) {
227 return params().densityMarginalAt(kept, keptSpace);
235 return params().m_logDeterminant;
243 requires(Params_::IsSqrtForm && !Params_::IsInfoForm)
245 return params().root();
262 template <
typename Derived>
266 static_assert(Derived::IsVectorAtCompileTime,
"squaredMahalanobisDistance() expects a vector");
269 params().whitenInPlace(residual);
270 return residual.squaredNorm();
276 template <
typename Derived>
293 template <
typename Derived>
297 EMRYS_FILTER_ASSERT(probability > 0 && probability < 1 &&
"the probability must be in (0, 1)");
307 template <
typename Derived>
318 template <
typename Derived>
320 density(Eigen::MatrixBase<Derived>
const & x)
const
330 template <
typename Derived>
331 [[nodiscard]]
typename Derived::PlainObject
335 auto result =
typename Derived::PlainObject{};
336 result.resize(z.rows(), z.cols());
337 params().colorInto(result, z);
351 [[nodiscard]] Params_
const &
354 return m_check.get();
357 internal::ValuesCheck<Params_> m_check;
366template <
typename Params_, std::uniform_random_bit_generator G>
370 EMRYS_FILTER_ASSERT(n >= 0);
371 using Space =
typename Params_::SpaceType;
372 using Scalar =
typename Params_::Scalar;
374 Normals
const z = internal::standardNormal<Normals>(gaussian.
differenceDimension(), n, rng);
382template <
typename Params_, std::uniform_random_bit_generator G>
388 Normals
const z = internal::standardNormalVector<Normals>(gaussian.
differenceDimension(), rng);
401template <
typename Params_, std::uniform_random_bit_generator G>
402[[nodiscard]] SamplesWithLogDensity<typename Params_::SpaceType, typename Params_::Scalar>
405 EMRYS_FILTER_ASSERT(n >= 0);
406 using Space =
typename Params_::SpaceType;
407 using Scalar =
typename Params_::Scalar;
409 Normals
const z = internal::standardNormal<Normals>(gaussian.
differenceDimension(), n, rng);
416 result.logDensity = gaussian.
logPeak() - Scalar(0.5) * z.colwise().squaredNorm().transpose().array();
420 result.logDensity.resize(n);
421 for (Eigen::Index j = 0; j < n; ++j)
423 result.logDensity(j) = gaussian.
logDensity(result.samples.col(j));
435template <
typename Params_, std::uniform_random_bit_generator G>
436[[nodiscard]] SampleWithLogDensity<typename Params_::SpaceType, typename Params_::Scalar>
439 using Space =
typename Params_::SpaceType;
440 using Scalar =
typename Params_::Scalar;
443 Normals
const z = internal::standardNormalVector<Normals>(gaussian.
differenceDimension(), rng);
450 result.logDensity = gaussian.
logPeak() - Scalar(0.5) * z.squaredNorm();
454 result.logDensity = gaussian.
logDensity(result.sample);
The chi-squared distribution's CDF and quantile, with no dependency outside Eigen,...
The Gaussian: its parameters GaussianParams, the Gaussian that evaluates the density,...
What marginals and conditionals are built from: resolving Eigen index sets against a space; the share...
The macros every header includes first.
Mathematical constants and scalar functions that work in every scalar type the library accepts,...
The covariance reset (decisions.md [covariance-reset]): hasIdentityReset<>, resetJacobian(),...
SampleSet: a matrix whose columns are samples in a space, which the samplers return and the unscented...
Drawing samples: SamplesWithLogDensity and SampleWithLogDensity, the Gaussian draws drawSamples(),...
The Space concept and what every continuous space shares (decisions.md [sizes-and-dimensions]): the t...
What parameters and their views share (decisions.md [view-stamp], [params-and-density]): Stamp,...
A Gaussian distribution: a mean and covariance in a space.
Definition Gaussian.h:259
First and second moments (mean and covariance) of a distribution.
Definition Moments.h:55
ValueVector< Space_, Scalar > VectorType
a value, such as the mean
Definition Moments.h:74
A type usable as the space of a distribution.
Definition Space.h:186
Scalar chiSquaredQuantile(std::type_identity_t< Scalar > const &probability, std::type_identity_t< Scalar > const &dof)
Definition ChiSquared.h:148
Scalar chiSquaredCdf(std::type_identity_t< Scalar > const &x, std::type_identity_t< Scalar > const &dof)
Definition ChiSquared.h:123
Scalar log2Pi()
Definition Math.h:177
SampleWithLogDensity< Space, Scalar > drawSampleWithLogDensity(Gamma< Space, Scalar > const &gamma, G &rng)
Definition Gamma.h:546
Eigen::Matrix< Scalar, valueDimensionAtCompileTime< Space >, Eigen::Dynamic,(maxValueDimensionAtCompileTime< Space >==1 ? Eigen::RowMajor :Eigen::ColMajor), maxValueDimensionAtCompileTime< Space >, Eigen::Dynamic > SampleSet
A matrix whose columns are samples in Space (see Spaces), with the space's size and storage bound.
Definition SampleSet.h:33
NumericError GaussianError
Reasons a Gaussian, in any of its forms (decisions.md [gaussian-forms]), can fail to give a density,...
Definition NumericError.h:45
Eigen::Index drawSample(Categorical< Space, Scalar > const &distribution, G &rng)
Definition Categorical.h:1111
constexpr bool isInfoForm
Whether the GaussianForm G holds the precision, as InfoGaussianParams and SqrtInfoGaussianParams do,...
Definition GaussianForm.h:69
constexpr bool isSqrtForm
Whether the GaussianForm G holds a triangular root, as SqrtGaussianParams and SqrtInfoGaussianParams ...
Definition GaussianForm.h:76
std::expected< GaussianParams< typename G::SpaceType, typename G::Scalar >, GaussianError > toGaussian(G const &form)
Definition GaussianForm.h:91
std::vector< Eigen::Index > drawSamples(Categorical< Space, Scalar > const &distribution, Eigen::Index n, G &rng)
Definition Categorical.h:1087
SamplesWithLogDensity< Space, Scalar > drawSamplesWithLogDensity(Gamma< Space, Scalar > const &gamma, Eigen::Index n, G &rng)
Definition Gamma.h:529
auto plus(S const &space, Eigen::MatrixBase< XDerived > const &x, Eigen::MatrixBase< DDerived > const &d)
Definition Space.h:675
auto minus(S const &space, Eigen::MatrixBase< ADerived > const &a, Eigen::MatrixBase< BDerived > const &b)
Definition Space.h:715
ValueVector< DifferenceSpace< S >, Scalar > DifferenceVector
A difference in S as an Eigen column vector of Scalar, the type of minus() and of the offset plus() t...
Definition Space.h:650
constexpr bool hasIdentityReset
Whether the reset Jacobian of S is the identity, so that a covariance needs no change when its mean m...
Definition Reset.h:100
void resetCovariance(S const &space, Eigen::MatrixBase< XDerived > const &x, Eigen::MatrixBase< DDerived > const &d, Eigen::MatrixBase< CovDerived > const &cov)
Carries the covariance cov from the tangent space at x to the one at , in place: ,...
Definition Reset.h:426
constexpr bool isLinear
Whether S is linear: its values and its differences are both plain vectors.
Definition Space.h:321
One sample in Space, in a vector sized by the space, together with the log of the density it was draw...
Definition Sampling.h:50
Samples in Space together with the log of the density they were drawn from, evaluated at each.
Definition Sampling.h:36