tesseract
5.0.0-alpha-619-ge9db
|
#include <cfloat>
#include <cmath>
#include <vector>
#include "cluster.h"
#include "emalloc.h"
#include "genericheap.h"
#include <tesseract/helpers.h>
#include "kdpair.h"
#include "matrix.h"
#include "tprintf.h"
Go to the source code of this file.
Classes | |
struct | TEMPCLUSTER |
struct | STATISTICS |
struct | BUCKETS |
struct | CHISTRUCT |
struct | ClusteringContext |
Macros | |
#define | _USE_MATH_DEFINES |
#define | HOTELLING 1 |
#define | FTABLE_X 10 |
#define | FTABLE_Y 100 |
#define | MINVARIANCE 0.0004 |
#define | MINSAMPLESPERBUCKET 5 |
#define | MINSAMPLES (MINBUCKETS * MINSAMPLESPERBUCKET) |
#define | MINSAMPLESNEEDED 1 |
#define | BUCKETTABLESIZE 1024 |
#define | NORMALEXTENT 3.0 |
#define | Odd(N) ((N)%2) |
#define | Mirror(N, R) ((R) - (N) - 1) |
#define | Abs(N) (((N) < 0) ? (-(N)) : (N)) |
#define | SqrtOf2Pi 2.506628275 |
#define | LOOKUPTABLESIZE 8 |
#define | MAXDEGREESOFFREEDOM MAXBUCKETS |
#define | MAXNEIGHBORS 2 |
#define | MAXDISTANCE FLT_MAX |
#define | CHIACCURACY 0.01 |
#define | MINALPHA (1e-200) |
#define | INITIALDELTA 0.1 |
#define | DELTARATIO 0.1 |
#define | ILLEGAL_CHAR 2 |
Typedefs | |
using | ClusterPair = tesseract::KDPairInc< float, TEMPCLUSTER * > |
using | ClusterHeap = tesseract::GenericHeap< ClusterPair > |
using | DENSITYFUNC = double(*)(int32_t) |
using | SOLVEFUNC = double(*)(CHISTRUCT *, double) |
Functions | |
CLUSTERER * | MakeClusterer (int16_t SampleSize, const PARAM_DESC ParamDesc[]) |
SAMPLE * | MakeSample (CLUSTERER *Clusterer, const float *Feature, int32_t CharID) |
LIST | ClusterSamples (CLUSTERER *Clusterer, CLUSTERCONFIG *Config) |
void | FreeClusterer (CLUSTERER *Clusterer) |
void | FreeProtoList (LIST *ProtoList) |
void | FreePrototype (void *arg) |
CLUSTER * | NextSample (LIST *SearchState) |
float | Mean (PROTOTYPE *Proto, uint16_t Dimension) |
float | StandardDeviation (PROTOTYPE *Proto, uint16_t Dimension) |
int32_t | MergeClusters (int16_t N, PARAM_DESC ParamDesc[], int32_t n1, int32_t n2, float m[], float m1[], float m2[]) |
Variables | |
const double | FTable [FTABLE_Y][FTABLE_X] |
#define _USE_MATH_DEFINES |
Definition at line 17 of file cluster.cpp.
#define Abs | ( | N | ) | (((N) < 0) ? (-(N)) : (N)) |
Definition at line 209 of file cluster.cpp.
#define BUCKETTABLESIZE 1024 |
define the size of the table which maps normalized samples to histogram buckets. Also define the number of standard deviations in a normal distribution which are considered to be significant. The mapping table will be defined in such a way that it covers the specified number of standard deviations on either side of the mean. BUCKETTABLESIZE should always be even.
Definition at line 161 of file cluster.cpp.
#define CHIACCURACY 0.01 |
#define DELTARATIO 0.1 |
#define FTABLE_X 10 |
Definition at line 32 of file cluster.cpp.
#define FTABLE_Y 100 |
Definition at line 33 of file cluster.cpp.
#define HOTELLING 1 |
Definition at line 31 of file cluster.cpp.
#define ILLEGAL_CHAR 2 |
#define INITIALDELTA 0.1 |
#define LOOKUPTABLESIZE 8 |
define lookup tables used to compute the number of histogram buckets that should be used for a given number of samples.
Definition at line 229 of file cluster.cpp.
#define MAXDEGREESOFFREEDOM MAXBUCKETS |
Definition at line 230 of file cluster.cpp.
#define MAXDISTANCE FLT_MAX |
#define MAXNEIGHBORS 2 |
#define MINALPHA (1e-200) |
#define MINSAMPLES (MINBUCKETS * MINSAMPLESPERBUCKET) |
Definition at line 152 of file cluster.cpp.
#define MINSAMPLESNEEDED 1 |
Definition at line 153 of file cluster.cpp.
#define MINSAMPLESPERBUCKET 5 |
define the absolute minimum number of samples which must be present in order to accurately test hypotheses about underlying probability distributions. Define separately the minimum samples that are needed before a statistical analysis is attempted; this number should be equal to MINSAMPLES but can be set to a lower number for early testing when very few samples are available.
Definition at line 151 of file cluster.cpp.
#define MINVARIANCE 0.0004 |
define the variance which will be used as a minimum variance for any dimension of any feature. Since most features are calculated from numbers with a precision no better than 1 in 128, the variance should never be less than the square of this number for parameters whose range is 1.
Definition at line 143 of file cluster.cpp.
#define Mirror | ( | N, | |
R | |||
) | ((R) - (N) - 1) |
Definition at line 208 of file cluster.cpp.
#define NORMALEXTENT 3.0 |
Definition at line 162 of file cluster.cpp.
#define Odd | ( | N | ) | ((N)%2) |
Definition at line 207 of file cluster.cpp.
#define SqrtOf2Pi 2.506628275 |
the following variables describe a discrete normal distribution which is used by NormalDensity() and NormalBucket(). The constant NORMALEXTENT determines how many standard deviations of the distribution are mapped onto the fixed discrete range of x. x=0 is mapped to -NORMALEXTENT standard deviations and x=BUCKETTABLESIZE is mapped to +NORMALEXTENT standard deviations.
Definition at line 219 of file cluster.cpp.
using ClusterHeap = tesseract::GenericHeap<ClusterPair> |
Definition at line 170 of file cluster.cpp.
using ClusterPair = tesseract::KDPairInc<float, TEMPCLUSTER*> |
Definition at line 169 of file cluster.cpp.
using DENSITYFUNC = double (*)(int32_t) |
Definition at line 204 of file cluster.cpp.
Definition at line 205 of file cluster.cpp.
LIST ClusterSamples | ( | CLUSTERER * | Clusterer, |
CLUSTERCONFIG * | Config | ||
) |
This routine first checks to see if the samples in this clusterer have already been clustered before; if so, it does not bother to recreate the cluster tree. It simply recomputes the prototypes based on the new Config info.
If the samples have not been clustered before, the samples in the KD tree are formed into a cluster tree and then the prototypes are computed from the cluster tree.
In either case this routine returns a pointer to a list of prototypes that best represent the samples given the constraints specified in Config.
Clusterer | data struct containing samples to be clustered |
Config | parameters which control clustering process |
Definition at line 483 of file cluster.cpp.
void FreeClusterer | ( | CLUSTERER * | Clusterer | ) |
This routine frees all of the memory allocated to the specified data structure. It will not, however, free the memory used by the prototype list. The pointers to the clusters for each prototype in the list will be set to nullptr to indicate that the cluster data structures no longer exist. Any sample lists that have been obtained via calls to GetSamples are no longer valid.
Clusterer | pointer to data structure to be freed |
Definition at line 514 of file cluster.cpp.
void FreeProtoList | ( | LIST * | ProtoList | ) |
This routine frees all of the memory allocated to the specified list of prototypes. The clusters which are pointed to by the prototypes are not freed.
ProtoList | pointer to list of prototypes to be freed |
Definition at line 538 of file cluster.cpp.
void FreePrototype | ( | void * | arg | ) |
This routine deallocates the memory consumed by the specified prototype and modifies the corresponding cluster so that it is no longer marked as a prototype. The cluster is NOT deallocated by this routine.
arg | prototype data structure to be deallocated |
Definition at line 549 of file cluster.cpp.
CLUSTERER* MakeClusterer | ( | int16_t | SampleSize, |
const PARAM_DESC | ParamDesc[] | ||
) |
This routine creates a new clusterer data structure, initializes it, and returns a pointer to it.
SampleSize | number of dimensions in feature space |
ParamDesc | description of each dimension |
Definition at line 376 of file cluster.cpp.
This routine creates a new sample data structure to hold the specified feature. This sample is added to the clusterer data structure (so that it knows which samples are to be clustered later), and a pointer to the sample is returned to the caller.
Clusterer | clusterer data structure to add sample to |
Feature | feature to be added to clusterer |
CharID | unique ident. of char that sample came from |
Definition at line 429 of file cluster.cpp.
float Mean | ( | PROTOTYPE * | Proto, |
uint16_t | Dimension | ||
) |
This routine returns the mean of the specified prototype in the indicated dimension.
Proto | prototype to return mean of |
Dimension | dimension whose mean is to be returned |
Definition at line 602 of file cluster.cpp.
int32_t MergeClusters | ( | int16_t | N, |
PARAM_DESC | ParamDesc[], | ||
int32_t | n1, | ||
int32_t | n2, | ||
float | m[], | ||
float | m1[], | ||
float | m2[] | ||
) |
This routine merges two clusters into one larger cluster. To do this it computes the number of samples in the new cluster and the mean of the new cluster. The ParamDesc information is used to ensure that circular dimensions are handled correctly.
N | # of dimensions (size of arrays) |
ParamDesc | array of dimension descriptions |
n1,n2 | number of samples in each old cluster |
m | array to hold mean of new cluster |
m1,m2 | arrays containing means of old clusters |
Definition at line 824 of file cluster.cpp.
This routine is used to find all of the samples which belong to a cluster. It starts by removing the top cluster on the cluster list (SearchState). If this cluster is a leaf it is returned. Otherwise, the right subcluster is pushed on the list and we continue the search in the left subcluster. This continues until a leaf is found. If all samples have been found, nullptr is returned. InitSampleSearch() must be called before NextSample() to initialize the search.
SearchState | ptr to list containing clusters to be searched |
Definition at line 580 of file cluster.cpp.
float StandardDeviation | ( | PROTOTYPE * | Proto, |
uint16_t | Dimension | ||
) |
This routine returns the standard deviation of the prototype in the indicated dimension.
Proto | prototype to return standard deviation of |
Dimension | dimension whose stddev is to be returned |
Definition at line 613 of file cluster.cpp.
Definition at line 36 of file cluster.cpp.