IMP logo
IMP Reference Guide  2.15.0
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>
14 #include <IMP/core/rigid_bodies.h>
16 #include <IMP/em/MRCReaderWriter.h>
17 #include <IMP/em/em_config.h>
18 
19 #include <vector>
20 
21 #include "DensityMap.h"
22 #include "def.h"
23 
24 IMPEM_BEGIN_NAMESPACE
25 
26 //! Get histogram of density in EM map.
27 IMPEMEXPORT 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
31 IMPEMEXPORT Floats bayesem3d_get_cumulative_sum(DensityMap *em);
32 
33 //! Compute the cumulative sum of the histogram given a reference
34 IMPEMEXPORT std::map<double, double>
36 
37 //! Basic linear interpolation given vectors of values
38 IMPEMEXPORT double bayesem3d_linear_interpolate(const Floats &x_data,
39  const Floats &y_data, double x,
40  bool extrapolate);
41 
42 //! Numerically stable logabssumexp
43 IMPEMEXPORT FloatPair bayesem3d_get_logabssumexp(double x, double y, double sx,
44  double sy);
45 
46 //! Numerically stable logabssumprodexp
47 IMPEMEXPORT FloatPair bayesem3d_get_logabssumprodexp(double x, double y,
48  double wx, double wy);
49 
50 //! Numerically stable logsumexp
51 IMPEMEXPORT double bayesem3d_get_logsumexp(double x, double y);
52 
53 //! Numerically stable logsumexpprod
54 IMPEMEXPORT 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
58 IMPEMEXPORT FloatPair bayesem3d_get_em_density_squared(DensityMap *em,
59  long number_of_voxels);
60 
61 //! Compute the score and derivatives for a particle at a given voxel
62 IMPEMEXPORT 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
67 IMPEMEXPORT 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
73 IMPEMEXPORT DensityMap *bayesem3d_get_density_from_particle(
74  DensityMap *em, const IMP::ParticlesTemp &ps, double resolution);
75 
76 //! Compute a normalized cross-correlation coefficient
77 IMPEMEXPORT double bayesem3d_get_cross_correlation_coefficient(const DensityMap *em1,
78  const DensityMap *em2);
79 
80 /** \brief The function returns the negative log of the Normal distributed
81  difference between a normalized EM density map and a tested model.
82  To support sampling and optimization, the derivative of the score
83  is also returned.
84 
85  \param[in] em DensityMap class containing the EM map.
86  Note: the EM density map must be normalized by
87  the histogram matching routine.
88 
89  \param[in] ps ParticlesTemp class containing the particles of the tested
90  model.
91 
92  \param[in] resolution the resolution of the input EM density map.
93  Note: Usually is contained in the header but this is for safety.
94 
95  \param[in] sigma The expected variance of the difference between
96  the normalized EM density map and the tested model.
97 
98  \return a numerically stable value for the score and its derivatives.
99 
100 */
101 IMPEMEXPORT std::pair<double, algebra::Vector3Ds>
103  double resolution, double sigma);
104 
105 //! Normalization of an EM map by histogram matching against
106 //! the CDF of the EM map generated from a set of particles.
107 IMPEMEXPORT void bayesem3d_get_normalized_intensities(
108  DensityMap *em, const IMP::ParticlesTemp &ps, double resolution);
109 
110 IMPEM_END_NAMESPACE
111 #endif /* IMPEM_BAYES_EM3D_H */
double bayesem3d_linear_interpolate(const Floats &x_data, const Floats &y_data, double x, bool extrapolate)
Basic linear interpolation given vectors of values.
Definitions for EMBED.
double bayesem3d_get_logsumexp(double x, double y)
Numerically stable logsumexp.
Calculates and stores Gaussian kernel parameters.
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.
DensityMap * bayesem3d_get_density_from_particle(DensityMap *em, const IMP::ParticlesTemp &ps, double resolution)
IMP::Vector< Float > Floats
Standard way to pass a bunch of Float values.
Definition: types.h:47
std::pair< double, algebra::Vector3Ds > bayesem3d_get_score_and_derivative(DensityMap *em, const IMP::ParticlesTemp &ps, double resolution, double sigma)
The function returns the negative log of the Normal distributed difference between a normalized EM de...
std::pair< double, double > FloatPair
A generic pair of floats.
Definition: types.h:27
Calculates and stores Gaussian kernel parameters.
FloatPair bayesem3d_get_logabssumexp(double x, double y, double sx, double sy)
Numerically stable logabssumexp.
void bayesem3d_get_normalized_intensities(DensityMap *em, const IMP::ParticlesTemp &ps, double resolution)
Class for handling density maps.
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.
Refine a particle into a list of particles.
std::map< double, int > bayesem3d_get_distinct_and_counts(DensityMap *em)
Get histogram of density in EM map.
functionality for defining rigid bodies
double bayesem3d_get_cross_correlation_coefficient(const DensityMap *em1, const DensityMap *em2)
Compute a normalized cross-correlation coefficient.
Floats bayesem3d_get_cumulative_sum(DensityMap *em)
Compute the cumulative sum of the histogram computed from EM map.
double bayesem3d_get_logsumprodexp(double x, double y, double wx, double wy)
Numerically stable logsumexpprod.
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.
Classes to read or write MRC files.
std::map< double, double > bayesem3d_get_cumulative_sum_with_reference(DensityMap *em)
Compute the cumulative sum of the histogram given a reference.
VectorD< 3 > Vector3D
Definition: VectorD.h:421
FloatPair bayesem3d_get_logabssumprodexp(double x, double y, double wx, double wy)
Numerically stable logabssumprodexp.