Hierarchical.h

Go to the documentation of this file.
00001 /*
00002  * This program is free software; you can redistribute it and/or modify
00003  * it under the terms of the GNU General Public License as published by
00004  * the Free Software Foundation; either version 3 of the License, or
00005  * (at your option) any later version.
00006  *
00007  * Written (W) 2007-2008 Soeren Sonnenburg
00008  * Copyright (C) 2007-2008 Fraunhofer Institute FIRST and Max-Planck-Society
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 
00024 class CHierarchical : public CDistanceMachine
00025 {
00026     public:
00028         CHierarchical();
00029 
00035         CHierarchical(INT merges, CDistance* d);
00036         virtual ~CHierarchical();
00037 
00042         virtual inline EClassifierType get_classifier_type() { return CT_HIERARCHICAL; }
00043 
00048         virtual bool train();
00049 
00055         virtual bool load(FILE* srcfile);
00056 
00062         virtual bool save(FILE* dstfile);
00063 
00068         inline void set_merges(INT m)
00069         {
00070             ASSERT(m>0);
00071             merges=m;
00072         }
00073 
00078         inline INT get_merges()
00079         {
00080             return merges;
00081         }
00082 
00088         inline void get_assignment(INT*& assign, INT& num)
00089         {
00090             assign=assignment;
00091             num=table_size;
00092         }
00093 
00099         inline void get_merge_distance(DREAL*& dist, INT& num)
00100         {
00101             dist=merge_distance;
00102             num=table_size;
00103         }
00104 
00110         inline void get_merge_distances(DREAL** dist, INT* num)
00111         {
00112             size_t sz=sizeof(*merge_distance)*merges;
00113             *dist=(DREAL*) malloc(sz);
00114             ASSERT(*dist);
00115 
00116             memcpy(*dist, merge_distance, sz);
00117             *num=merges;
00118         }
00119 
00126         inline void get_pairs(INT*& tuples, INT& rows, INT& num)
00127         {
00128             tuples=pairs;
00129             rows=2;
00130             num=table_size;
00131         }
00132 
00139         inline void get_cluster_pairs(INT** tuples, INT* rows, INT* num)
00140         {
00141             *rows=2;
00142             size_t sz=sizeof(*pairs)*(*rows)*merges;
00143             *tuples=(INT*) malloc(sz);
00144             ASSERT(*tuples);
00145 
00146             memcpy(*tuples, pairs, sz);
00147             *num=merges;
00148         }
00149 
00150     protected:
00152         INT merges;
00153 
00155         INT dimensions;
00156 
00158         INT assignment_size;
00159 
00161         INT* assignment;
00162 
00164         INT table_size;
00165 
00167         INT* pairs;
00168 
00170         DREAL* merge_distance;
00171 };
00172 #endif

SHOGUN Machine Learning Toolbox - Documentation