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<D,
23 typename algebra::DenseGridStorageD<D,
26 typename algebra::DefaultEmbeddingD<D> > >
30 typedef Grid CountGrid;
31 HistogramD(): count_(std::numeric_limits<double>::max()){}
34 ): grid_(voxel_size, bb, 0),
40 "Using uninitialized histogram");
41 typename CountGrid::ExtendedIndex ei=grid_.get_nearest_extended_index(x);
42 if (grid_.get_has_index(ei)) {
43 grid_[grid_.get_index(ei)]+=weight;
52 CountGrid grid(grid_.get_unit_cell()[0],
53 algebra::get_bounding_box(grid_), 0);
54 grid_.apply(internal::Frequency<D, Grid>(grid, 1.0/count_));
59 CountGrid grid(grid_.get_unit_cell()[0],
60 algebra::get_bounding_box(grid_), 0);
63 grid_.apply(internal::Frequency<D, Grid>(grid, 1.0/(count_*volume)));
66 const CountGrid& get_counts()
const {
71 std::fill(zeros.coordinates_begin(), zeros.coordinates_end(), 0.0);
72 return grid_.apply(internal::Mean<D>(zeros)).mn/count_;
74 unsigned int get_dimension()
const {
75 return grid_.get_dimension();
78 get_standard_deviation(
const algebra::VectorInputD<D> &mean)
const {
79 algebra::VectorD<D> zeros(grid_.get_bounding_box().get_corner(0));
80 std::fill(zeros.coordinates_begin(), zeros.coordinates_end(), 0.0);
81 algebra::VectorD<D> s2
82 = grid_.apply(internal::Sigma2<D>(mean, zeros)).sigma2;
84 for (
unsigned int i=0; i< get_dimension(); ++i) {
85 s2[i] = std::sqrt(s2[i]);
89 algebra::BoundingBoxD<D> get_bounding_box()
const {
92 FloatPair get_minimum_and_maximum()
const {
93 return grid_.apply(internal::MinMax<D>()).minmax;
98 HistogramD(
const CountGrid &g): grid_(g), count_(1){}
104 typedef HistogramD<1> Histogram1D;
106 typedef HistogramD<2> Histogram2D;
108 typedef HistogramD<3> Histogram3D;
110 typedef HistogramD<4> Histogram4D;
112 typedef HistogramD<5> Histogram5D;
114 typedef HistogramD<6> Histogram6D;
116 typedef HistogramD<-1> HistogramKD;
123 IMPSTATISTICSEXPORT
double get_quantile(
const Histogram1D &h,
126 IMPSTATISTICS_END_NAMESPACE