IMP logo
IMP Reference Guide  2.20.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,
75  double resolution, const double window_size = 1.0);
76 
77 //! Compute a normalized cross-correlation coefficient
78 IMPEMEXPORT double bayesem3d_get_cross_correlation_coefficient(const DensityMap *em1,
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 */
105 IMPEMEXPORT std::pair<double, algebra::Vector3Ds>
106 bayesem3d_get_score_and_derivative(DensityMap *em,
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.
112 IMPEMEXPORT void bayesem3d_get_normalized_intensities(
113  DensityMap *em, const IMP::ParticlesTemp &ps, double resolution);
114 
115 IMPEM_END_NAMESPACE
116 #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.
DensityMap * bayesem3d_get_density_from_particle(DensityMap *em, const IMP::ParticlesTemp &ps, double resolution, const double window_size=1.0)
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.
IMP::Vector< Float > Floats
Standard way to pass a bunch of Float values.
Definition: types.h:46
std::pair< double, double > FloatPair
A generic pair of floats.
Definition: types.h:26
Calculates and stores Gaussian kernel parameters.
FloatPair bayesem3d_get_logabssumexp(double x, double y, double sx, double sy)
Numerically stable logabssumexp.
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...
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:425
FloatPair bayesem3d_get_logabssumprodexp(double x, double y, double wx, double wy)
Numerically stable logabssumprodexp.