#include "kdtree.h"
#include "oldlist.h"
Go to the source code of this file.
|
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[]) |
|
◆ InitSampleSearch
◆ MAXBUCKETS
◆ MINBUCKETS
◆ CLUSTER
◆ SAMPLE
◆ DISTRIBUTION
Enumerator |
---|
normal | |
uniform | |
D_random | |
DISTRIBUTION_COUNT | |
Definition at line 58 of file cluster.h.
◆ PROTOSTYLE
Enumerator |
---|
spherical | |
elliptical | |
mixed | |
automatic | |
Definition at line 44 of file cluster.h.
◆ ClusterSamples()
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.
- Parameters
-
Clusterer | data struct containing samples to be clustered |
Config | parameters which control clustering process |
- Returns
- Pointer to a list of prototypes
Definition at line 506 of file cluster.cpp.
508 if (Clusterer->
Root ==
nullptr)
void ComputePrototypes(CLUSTERER *Clusterer, CLUSTERCONFIG *Config)
void CreateClusterTree(CLUSTERER *Clusterer)
void FreeProtoList(LIST *ProtoList)
◆ FreeClusterer()
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.
- Parameters
-
Clusterer | pointer to data structure to be freed |
- Returns
- None
Definition at line 538 of file cluster.cpp.
539 if (Clusterer !=
nullptr) {
541 if (Clusterer->
KDTree !=
nullptr)
543 if (Clusterer->
Root !=
nullptr)
void FreeKDTree(KDTREE *Tree)
void FreeBuckets(BUCKETS *Buckets)
BUCKETS * bucket_cache[DISTRIBUTION_COUNT][MAXBUCKETS+1 - MINBUCKETS]
void FreeCluster(CLUSTER *Cluster)
◆ FreeProtoList()
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.
- Parameters
-
ProtoList | pointer to list of prototypes to be freed |
- Returns
- None
Definition at line 563 of file cluster.cpp.
void FreePrototype(void *arg)
void destroy_nodes(LIST list, void_dest destructor)
◆ FreePrototype()
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.
- Parameters
-
arg | prototype data structure to be deallocated |
- Returns
- None
Definition at line 575 of file cluster.cpp.
579 if (Prototype->
Cluster !=
nullptr)
584 free(Prototype->
Mean);
◆ MakeClusterer()
This routine creates a new clusterer data structure, initializes it, and returns a pointer to it.
- Parameters
-
SampleSize | number of dimensions in feature space |
ParamDesc | description of each dimension |
- Returns
- pointer to the new clusterer data structure
Definition at line 399 of file cluster.cpp.
410 Clusterer->
Root =
nullptr;
416 for (i = 0; i < SampleSize; i++) {
424 (ParamDesc[i].
Max + ParamDesc[i].
Min) / 2;
KDTREE * MakeKDTree(int16_t KeySize, const PARAM_DESC KeyDesc[])
BUCKETS * bucket_cache[DISTRIBUTION_COUNT][MAXBUCKETS+1 - MINBUCKETS]
◆ MakeSample()
SAMPLE* MakeSample |
( |
CLUSTERER * |
Clusterer, |
|
|
const float * |
Feature, |
|
|
int32_t |
CharID |
|
) |
| |
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.
- Parameters
-
Clusterer | clusterer data structure to add sample to |
Feature | feature to be added to clusterer |
CharID | unique ident. of char that sample came from |
- Returns
- Pointer to the new sample data structure
Definition at line 452 of file cluster.cpp.
464 1) *
sizeof (
float));
468 Sample->
Left =
nullptr;
469 Sample->
Right =
nullptr;
473 Sample->
Mean[i] = Feature[i];
478 if (CharID >= Clusterer->
NumChar)
479 Clusterer->
NumChar = CharID + 1;
void KDStore(KDTREE *Tree, float *Key, void *Data)
◆ Mean()
float Mean |
( |
PROTOTYPE * |
Proto, |
|
|
uint16_t |
Dimension |
|
) |
| |
This routine returns the mean of the specified prototype in the indicated dimension.
- Parameters
-
Proto | prototype to return mean of |
Dimension | dimension whose mean is to be returned |
- Returns
- Mean of Prototype in Dimension
Definition at line 628 of file cluster.cpp.
629 return (Proto->
Mean[Dimension]);
◆ MergeClusters()
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.
- Parameters
-
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 |
- Returns
- The number of samples in the new cluster.
Definition at line 852 of file cluster.cpp.
861 for (i = N; i > 0; i--, ParamDesc++, m++, m1++, m2++) {
862 if (ParamDesc->Circular) {
866 if ((*m2 - *m1) > ParamDesc->HalfRange) {
867 *m = (n1 * *m1 + n2 * (*m2 - ParamDesc->Range)) / n;
868 if (*m < ParamDesc->Min)
869 *m += ParamDesc->Range;
871 else if ((*m1 - *m2) > ParamDesc->HalfRange) {
872 *m = (n1 * (*m1 - ParamDesc->Range) + n2 * *m2) / n;
873 if (*m < ParamDesc->Min)
874 *m += ParamDesc->Range;
877 *m = (n1 * *m1 + n2 * *m2) / n;
880 *m = (n1 * *m1 + n2 * *m2) / n;
◆ NextSample()
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.
- Parameters
-
SearchState | ptr to list containing clusters to be searched |
- Returns
- Pointer to the next leaf cluster (sample) or nullptr.
Definition at line 606 of file cluster.cpp.
612 *SearchState =
pop (*SearchState);
614 if (Cluster->
Left ==
nullptr)
616 *SearchState =
push (*SearchState, Cluster->
Right);
617 Cluster = Cluster->
Left;
LIST push(LIST list, void *element)
◆ StandardDeviation()
float StandardDeviation |
( |
PROTOTYPE * |
Proto, |
|
|
uint16_t |
Dimension |
|
) |
| |
This routine returns the standard deviation of the prototype in the indicated dimension.
- Parameters
-
Proto | prototype to return standard deviation of |
Dimension | dimension whose stddev is to be returned |
- Returns
- Standard deviation of Prototype in Dimension
Definition at line 639 of file cluster.cpp.
640 switch (Proto->
Style) {
647 switch (Proto->
Distrib[Dimension]) {