Hierarchical.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef _HIERARCHICAL_H__
00012 #define _HIERARCHICAL_H__
00013
00014 #include <stdio.h>
00015 #include "lib/common.h"
00016 #include "lib/io.h"
00017 #include "features/RealFeatures.h"
00018 #include "distance/Distance.h"
00019 #include "distance/DistanceMachine.h"
00020
00021 class CDistanceMachine;
00022
00035 class CHierarchical : public CDistanceMachine
00036 {
00037 public:
00039 CHierarchical();
00040
00046 CHierarchical(int32_t merges, CDistance* d);
00047 virtual ~CHierarchical();
00048
00053 virtual inline EClassifierType get_classifier_type() { return CT_HIERARCHICAL; }
00054
00059 virtual bool train();
00060
00066 virtual bool load(FILE* srcfile);
00067
00073 virtual bool save(FILE* dstfile);
00074
00079 inline void set_merges(int32_t m)
00080 {
00081 ASSERT(m>0);
00082 merges=m;
00083 }
00084
00089 inline int32_t get_merges()
00090 {
00091 return merges;
00092 }
00093
00099 inline void get_assignment(int32_t*& assign, int32_t& num)
00100 {
00101 assign=assignment;
00102 num=table_size;
00103 }
00104
00110 inline void get_merge_distance(float64_t*& dist, int32_t& num)
00111 {
00112 dist=merge_distance;
00113 num=merges;
00114 }
00115
00121 inline void get_merge_distances(float64_t** dist, int32_t* num)
00122 {
00123 size_t sz=sizeof(*merge_distance)*merges;
00124 *dist=(float64_t*) malloc(sz);
00125 ASSERT(*dist);
00126
00127 memcpy(*dist, merge_distance, sz);
00128 *num=merges;
00129 }
00130
00137 inline void get_pairs(int32_t*& tuples, int32_t& rows, int32_t& num)
00138 {
00139 tuples=pairs;
00140 rows=2;
00141 num=merges;
00142 }
00143
00150 inline void get_cluster_pairs(
00151 int32_t** tuples, int32_t* rows, int32_t* num)
00152 {
00153 *rows=2;
00154 size_t sz=sizeof(*pairs)*(*rows)*merges;
00155 *tuples=(int32_t*) malloc(sz);
00156 ASSERT(*tuples);
00157
00158 memcpy(*tuples, pairs, sz);
00159 *num=merges;
00160 }
00161
00162 protected:
00164 int32_t merges;
00165
00167 int32_t dimensions;
00168
00170 int32_t assignment_size;
00171
00173 int32_t* assignment;
00174
00176 int32_t table_size;
00177
00179 int32_t* pairs;
00180
00182 float64_t* merge_distance;
00183 };
00184 #endif