#include <statistc.h>
|
| STATS (int32_t min_bucket_value, int32_t max_bucket_value_plus_1) |
|
| STATS ()=default |
|
| ~STATS () |
|
bool | set_range (int32_t min_bucket_value, int32_t max_bucket_value_plus_1) |
|
void | clear () |
|
void | add (int32_t value, int32_t count) |
|
int32_t | mode () const |
|
double | mean () const |
|
double | sd () const |
|
double | ile (double frac) const |
|
int32_t | min_bucket () const |
|
int32_t | max_bucket () const |
|
double | median () const |
|
int32_t | pile_count (int32_t value) const |
|
int32_t | get_total () const |
|
bool | local_min (int32_t x) const |
|
void | smooth (int32_t factor) |
|
int32_t | cluster (float lower, float upper, float multiple, int32_t max_clusters, STATS *clusters) |
|
int | top_n_modes (int max_modes, GenericVector< tesseract::KDPairInc< float, int > > *modes) const |
|
void | print () const |
|
void | print_summary () const |
|
void | plot (ScrollView *window, float xorigin, float yorigin, float xscale, float yscale, ScrollView::Color colour) const |
|
void | plotline (ScrollView *window, float xorigin, float yorigin, float xscale, float yscale, ScrollView::Color colour) const |
|
Definition at line 30 of file statistc.h.
◆ STATS() [1/2]
STATS::STATS |
( |
int32_t |
min_bucket_value, |
|
|
int32_t |
max_bucket_value_plus_1 |
|
) |
| |
Definition at line 38 of file statistc.cpp.
41 if (max_bucket_value_plus_1 <= min_bucket_value) {
43 max_bucket_value_plus_1 = 1;
45 rangemin_ = min_bucket_value;
46 rangemax_ = max_bucket_value_plus_1;
47 buckets_ =
new int32_t[rangemax_ - rangemin_];
◆ STATS() [2/2]
◆ ~STATS()
◆ add()
void STATS::add |
( |
int32_t |
value, |
|
|
int32_t |
count |
|
) |
| |
Definition at line 87 of file statistc.cpp.
94 if (buckets_ ==
nullptr) {
◆ clear()
◆ cluster()
int32_t STATS::cluster |
( |
float |
lower, |
|
|
float |
upper, |
|
|
float |
multiple, |
|
|
int32_t |
max_clusters, |
|
|
STATS * |
clusters |
|
) |
| |
Definition at line 296 of file statistc.cpp.
321 int32_t best_cluster;
322 int32_t new_centre = 0;
327 int32_t cluster_count;
329 if (buckets_ ==
nullptr || max_clusters < 1)
331 centres =
new float[max_clusters + 1];
332 for (cluster_count = 1; cluster_count <= max_clusters
333 && clusters[cluster_count].buckets_ !=
nullptr
334 && clusters[cluster_count].total_count_ > 0;
336 centres[cluster_count] =
337 static_cast<float>(clusters[cluster_count].
ile(0.5));
338 new_centre = clusters[cluster_count].
mode();
339 for (entry = new_centre - 1; centres[cluster_count] - entry < lower
340 && entry >= rangemin_
345 clusters[cluster_count].
add(entry,
count);
349 for (entry = new_centre + 1; entry - centres[cluster_count] < lower
355 clusters[cluster_count].
add(entry,
count);
362 if (cluster_count == 0) {
363 clusters[0].
set_range(rangemin_, rangemax_);
368 for (entry = 0; entry < rangemax_ - rangemin_; entry++) {
369 count = buckets_[entry] - clusters[0].buckets_[entry];
372 min_dist = static_cast<float>(INT32_MAX);
375 dist = entry + rangemin_ - centres[
cluster];
379 if (dist < min_dist) {
385 && (best_cluster == 0
386 || entry + rangemin_ > centres[best_cluster] * multiple
387 || entry + rangemin_ < centres[best_cluster] / multiple)) {
388 if (
count > new_mode) {
390 new_centre = entry + rangemin_;
396 if (new_mode > 0 && cluster_count < max_clusters) {
399 if (!clusters[cluster_count].
set_range(rangemin_, rangemax_)) {
403 centres[cluster_count] = static_cast<float>(new_centre);
404 clusters[cluster_count].
add(new_centre, new_mode);
405 clusters[0].
add(new_centre, new_mode);
406 for (entry = new_centre - 1; centres[cluster_count] - entry < lower
407 && entry >= rangemin_
411 clusters[cluster_count].
add(entry,
count);
◆ get_total()
int32_t STATS::get_total |
( |
| ) |
const |
|
inline |
◆ ile()
double STATS::ile |
( |
double |
frac | ) |
const |
Definition at line 156 of file statistc.cpp.
167 if (buckets_ ==
nullptr || total_count_ == 0) {
168 return static_cast<double>(rangemin_);
177 double target = frac * total_count_;
178 target =
ClipToRange(target, 1.0, static_cast<double>(total_count_));
◆ local_min()
bool STATS::local_min |
( |
int32_t |
x | ) |
const |
Definition at line 240 of file statistc.cpp.
255 if (buckets_ ==
nullptr) {
◆ max_bucket()
int32_t STATS::max_bucket |
( |
| ) |
const |
◆ mean()
double STATS::mean |
( |
| ) |
const |
Definition at line 119 of file statistc.cpp.
128 if (buckets_ ==
nullptr || total_count_ <= 0) {
◆ median()
double STATS::median |
( |
| ) |
const |
Definition at line 218 of file statistc.cpp.
232 if (buckets_ ==
nullptr) {
233 return static_cast<double>(rangemin_);
◆ min_bucket()
int32_t STATS::min_bucket |
( |
| ) |
const |
Definition at line 187 of file statistc.cpp.
189 return static_cast<double>(rangemin_);
◆ mode()
int32_t STATS::mode |
( |
| ) |
const |
Definition at line 100 of file statistc.cpp.
108 if (buckets_ ==
nullptr) {
111 int32_t max = buckets_[0];
112 int32_t maxindex = 0;
113 for (
int index = rangemax_ - rangemin_ - 1; index > 0; --index) {
◆ pile_count()
int32_t STATS::pile_count |
( |
int32_t |
value | ) |
const |
|
inline |
Definition at line 75 of file statistc.h.
77 if (value <= rangemin_)
79 if (value >= rangemax_ - 1)
80 return buckets_[rangemax_ - rangemin_ - 1];
81 return buckets_[value - rangemin_];
◆ plot()
◆ plotline()
Definition at line 584 of file statistc.cpp.
589 window->
Rectangle(xorigin + xscale * index, yorigin,
590 xorigin + xscale * (index + 1),
591 yorigin + yscale * buckets_[index]);
◆ print()
void STATS::print |
( |
| ) |
const |
◆ print_summary()
void STATS::print_summary |
( |
| ) |
const |
Definition at line 534 of file statistc.cpp.
535 if (buckets_[index] != 0) {
536 tprintf(
"%4d:%-3d ", rangemin_ + index, buckets_[index]);
537 if (++num_printed % 8 == 0)
◆ sd()
double STATS::sd |
( |
| ) |
const |
Definition at line 134 of file statistc.cpp.
144 if (buckets_ ==
nullptr || total_count_ <= 0) {
149 for (
int index = rangemax_ - rangemin_ - 1; index >= 0; --index) {
◆ set_range()
bool STATS::set_range |
( |
int32_t |
min_bucket_value, |
|
|
int32_t |
max_bucket_value_plus_1 |
|
) |
| |
Definition at line 53 of file statistc.cpp.
57 if (max_bucket_value_plus_1 <= min_bucket_value) {
60 if (rangemax_ - rangemin_ != max_bucket_value_plus_1 - min_bucket_value) {
62 buckets_ =
new int32_t[max_bucket_value_plus_1 - min_bucket_value];
64 rangemin_ = min_bucket_value;
65 rangemax_ = max_bucket_value_plus_1;
◆ smooth()
void STATS::smooth |
( |
int32_t |
factor | ) |
|
Definition at line 266 of file statistc.cpp.
282 if (buckets_ ==
nullptr || factor < 2) {
285 STATS result(rangemin_, rangemax_);
◆ top_n_modes()
Definition at line 445 of file statistc.cpp.
463 if (max_modes <= 0)
return 0;
464 int src_count = rangemax_ - rangemin_;
466 STATS used(rangemin_, rangemax_);
476 for (
int src_index = 0; src_index < src_count; src_index++) {
477 int pile_count = buckets_[src_index] - used.buckets_[src_index];
480 max_index = src_index;
485 used.buckets_[max_index] = max_count;
487 double total_value = max_index * max_count;
488 int total_count = max_count;
489 int prev_pile = max_count;
490 for (
int offset = 1; max_index + offset < src_count; ++offset) {
491 if (!GatherPeak(max_index + offset, buckets_, used.buckets_,
492 &prev_pile, &total_count, &total_value))
495 prev_pile = buckets_[max_index];
496 for (
int offset = 1; max_index - offset >= 0; ++offset) {
497 if (!GatherPeak(max_index - offset, buckets_, used.buckets_,
498 &prev_pile, &total_count, &total_value))
501 if (total_count > least_count || modes->
size() < max_modes) {
503 if (modes->
size() == max_modes)
The documentation for this class was generated from the following files: