8 #ifndef IMPSTATISTICS_HISTOGRAM_D_H
9 #define IMPSTATISTICS_HISTOGRAM_D_H
10 #include <IMP/statistics/statistics_config.h>
11 #include "internal/histogram.h"
20 IMPSTATISTICS_BEGIN_NAMESPACE
22 template <
int D,
class Grid = algebra::GridD<
23 D,
typename algebra::DenseGridStorageD<D, double>, double,
24 typename algebra::DefaultEmbeddingD<D> > >
27 typedef Grid CountGrid;
28 HistogramD() : count_(std::numeric_limits<double>::max()) {}
30 : grid_(voxel_size, bb, 0), count_(0) {}
35 "Using uninitialized histogram");
36 typename CountGrid::ExtendedIndex ei = grid_.get_nearest_extended_index(x);
37 if (grid_.get_has_index(ei)) {
38 grid_[grid_.get_index(ei)] += weight;
47 grid_.apply(internal::Frequency<D, Grid>(grid, 1.0 / count_));
56 grid_.apply(internal::Frequency<D, Grid>(grid, 1.0 / (count_ * volume)));
59 const CountGrid &get_counts()
const {
return grid_; }
62 std::fill(zeros.coordinates_begin(), zeros.coordinates_end(), 0.0);
63 return grid_.apply(internal::Mean<D>(zeros)).mn / count_;
65 unsigned int get_dimension()
const {
return grid_.get_dimension(); }
66 algebra::VectorD<D> get_standard_deviation(
67 const algebra::VectorD<D> &mean)
const {
68 algebra::VectorD<D> zeros(grid_.get_bounding_box().get_corner(0));
69 std::fill(zeros.coordinates_begin(), zeros.coordinates_end(), 0.0);
70 algebra::VectorD<D> s2 =
71 grid_.apply(internal::Sigma2<D>(mean, zeros)).sigma2;
73 for (
unsigned int i = 0; i < get_dimension(); ++i) {
74 s2[i] = std::sqrt(s2[i]);
81 FloatPair get_minimum_and_maximum()
const {
82 return grid_.apply(internal::MinMax<D>()).minmax;
88 HistogramD(
const CountGrid &g) : grid_(g), count_(1) {}
94 typedef HistogramD<1> Histogram1D;
96 typedef HistogramD<2> Histogram2D;
98 typedef HistogramD<3> Histogram3D;
100 typedef HistogramD<4> Histogram4D;
102 typedef HistogramD<5> Histogram5D;
104 typedef HistogramD<6> Histogram6D;
106 typedef HistogramD<-1> HistogramKD;
113 IMPSTATISTICSEXPORT
double get_quantile(
const Histogram1D &h,
double fraction);
115 IMPSTATISTICS_END_NAMESPACE
double get_mean(const cv::Mat &mat, const cvIntMat &mask)
Import IMP/kernel/base_types.h in the namespace.
A class to represent a voxel grid.
std::pair< double, double > FloatPair
A generic pair of floats.
#define IMP_VALUES(Name, PluralName)
Define the type for storing sets of values.
double get_quantile(const Histogram1D &h, double fraction)
#define IMP_SHOWABLE_INLINE(Name, how_to_show)
Declare the methods needed by an object that can be printed.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
double get_volume(const BoundingBoxD< D > &bb)
A Cartesian vector in D-dimensions.
A bounding box in D dimensions.
An axis-aligned bounding box.
HistogramD< D > get_probability_distribution_function() const
All grids that are in the python API should be defined here.
void add(const algebra::VectorD< D > &x, double weight=1)
double get_total_count() const
Get the sum of all counts in the histogram.
BoundingBoxD< D > get_bounding_box(const BoundingBoxD< D > &g)