IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
BayesEM3D.h
Go to the documentation of this file.
1/**
2 * \file IMP/em/BayesEM3D.h
3 * \brief Compute a Bayesian formalism score and its derivatives
4 * to assess degree of match between a tested model and a density object.
5 *
6 * Copyright 2007-2020 IMP Inventors. All rights reserved.
7 *
8 */
9
10#ifndef IMPEM_BAYES_EM3D_H
11#define IMPEM_BAYES_EM3D_H
12
13#include <IMP/Refiner.h>
17#include <IMP/em/em_config.h>
18
19#include <vector>
20
21#include "DensityMap.h"
22#include "def.h"
23
24IMPEM_BEGIN_NAMESPACE
25
26//! Get histogram of density in EM map.
27IMPEMEXPORT std::map<double, int> bayesem3d_get_distinct_and_counts(
28 DensityMap *em);
29
30//! Compute the cumulative sum of the histogram computed from EM map
32
33//! Compute the cumulative sum of the histogram given a reference
34IMPEMEXPORT std::map<double, double>
36
37//! Basic linear interpolation given vectors of values
38IMPEMEXPORT double bayesem3d_linear_interpolate(const Floats &x_data,
39 const Floats &y_data, double x,
40 bool extrapolate);
41
42//! Numerically stable logabssumexp
43IMPEMEXPORT FloatPair bayesem3d_get_logabssumexp(double x, double y, double sx,
44 double sy);
45
46//! Numerically stable logabssumprodexp
47IMPEMEXPORT FloatPair bayesem3d_get_logabssumprodexp(double x, double y,
48 double wx, double wy);
49
50//! Numerically stable logsumexp
51IMPEMEXPORT double bayesem3d_get_logsumexp(double x, double y);
52
53//! Numerically stable logsumexpprod
54IMPEMEXPORT double bayesem3d_get_logsumprodexp(double x, double y, double wx,
55 double wy);
56
57//! Compute the sum of the density and the sum of the squares of the density
59 long number_of_voxels);
60
61//! Compute the score and derivatives for a particle at a given voxel
62IMPEMEXPORT std::vector<double> bayesem3d_get_value(
63 Particle *p, const algebra::Vector3D &pt, double mass_ii,
64 const IMP::em::KernelParameters &kps);
65
66//! Compute the score without its derivative
67IMPEMEXPORT std::vector<double> bayesem3d_get_value_no_deriv(
68 Particle *p, const algebra::Vector3D &pt, double mass_ii,
69 const IMP::em::KernelParameters &kps);
70
71//! Compute a generated EM density map given particles.
72//! Header and box size is copied from reference EM density map
74 DensityMap *em, const IMP::ParticlesTemp &ps,
75 double resolution, const double window_size = 1.0);
76
77//! Compute a normalized cross-correlation coefficient
79 const DensityMap *em2);
80
81/** \brief The function returns the negative log of the Normal distributed
82 difference between a normalized EM density map and a tested model.
83 To support sampling and optimization, the derivative of the score
84 is also returned.
85
86 \param[in] em DensityMap class containing the EM map.
87 Note: the EM density map must be normalized by
88 the histogram matching routine.
89
90 \param[in] ps ParticlesTemp class containing the particles of the tested
91 model.
92
93 \param[in] resolution the resolution of the input EM density map.
94 Note: Usually is contained in the header but this is for safety.
95
96 \param[in] sigma The expected variance of the difference between
97 the normalized EM density map and the tested model.
98
99 \param[in] window_size The size of the window to extend
100 the blur of the model
101
102 \return a numerically stable value for the score and its derivatives.
103
104*/
105IMPEMEXPORT std::pair<double, algebra::Vector3Ds>
107 const IMP::ParticlesTemp &ps, double resolution,
108 double sigma, const double window_size = 1.0);
109
110//! Normalization of an EM map by histogram matching against
111//! the CDF of the EM map generated from a set of particles.
113 DensityMap *em, const IMP::ParticlesTemp &ps, double resolution);
114
115IMPEM_END_NAMESPACE
116#endif /* IMPEM_BAYES_EM3D_H */
Class for handling density maps.
Calculates and stores Gaussian kernel parameters.
Classes to read or write MRC files.
Refine a particle into a list of particles.
Class to handle individual particles of a Model object.
Definition Particle.h:45
Class for handling density maps.
Definition DensityMap.h:95
Calculates and stores Gaussian kernel parameters.
Definitions for EMBED.
Basic utilities for handling cryo-electron microscopy 3D density maps.
std::map< double, int > bayesem3d_get_distinct_and_counts(DensityMap *em)
Get histogram of density in EM map.
FloatPair bayesem3d_get_em_density_squared(DensityMap *em, long number_of_voxels)
Compute the sum of the density and the sum of the squares of the density.
double bayesem3d_get_logsumprodexp(double x, double y, double wx, double wy)
Numerically stable logsumexpprod.
FloatPair bayesem3d_get_logabssumprodexp(double x, double y, double wx, double wy)
Numerically stable logabssumprodexp.
FloatPair bayesem3d_get_logabssumexp(double x, double y, double sx, double sy)
Numerically stable logabssumexp.
Floats bayesem3d_get_cumulative_sum(DensityMap *em)
Compute the cumulative sum of the histogram computed from EM map.
double bayesem3d_linear_interpolate(const Floats &x_data, const Floats &y_data, double x, bool extrapolate)
Basic linear interpolation given vectors of values.
std::map< double, double > bayesem3d_get_cumulative_sum_with_reference(DensityMap *em)
Compute the cumulative sum of the histogram given a reference.
double bayesem3d_get_cross_correlation_coefficient(const DensityMap *em1, const DensityMap *em2)
Compute a normalized cross-correlation coefficient.
double bayesem3d_get_logsumexp(double x, double y)
Numerically stable logsumexp.
std::vector< double > bayesem3d_get_value_no_deriv(Particle *p, const algebra::Vector3D &pt, double mass_ii, const IMP::em::KernelParameters &kps)
Compute the score without its derivative.
std::pair< double, algebra::Vector3Ds > bayesem3d_get_score_and_derivative(DensityMap *em, const IMP::ParticlesTemp &ps, double resolution, double sigma, const double window_size=1.0)
The function returns the negative log of the Normal distributed difference between a normalized EM de...
DensityMap * bayesem3d_get_density_from_particle(DensityMap *em, const IMP::ParticlesTemp &ps, double resolution, const double window_size=1.0)
void bayesem3d_get_normalized_intensities(DensityMap *em, const IMP::ParticlesTemp &ps, double resolution)
std::vector< double > bayesem3d_get_value(Particle *p, const algebra::Vector3D &pt, double mass_ii, const IMP::em::KernelParameters &kps)
Compute the score and derivatives for a particle at a given voxel.
VectorD< 3 > Vector3D
Definition VectorD.h:407
std::pair< double, double > FloatPair
A generic pair of floats.
Definition types.h:26
IMP::Vector< Float > Floats
Standard way to pass a bunch of Float values.
Definition types.h:46
functionality for defining rigid bodies