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-2009 Soeren Sonnenburg
00008  * Copyright (C) 2007-2009 Fraunhofer Institute FIRST and Max-Planck-Society
00009  */
00010 
00011 #ifndef _HIERARCHICAL_H__
00012 #define _HIERARCHICAL_H__
00013 
00014 #include <stdio.h>
00015 #include <shogun/lib/common.h>
00016 #include <shogun/io/SGIO.h>
00017 #include <shogun/distance/Distance.h>
00018 #include <shogun/machine/DistanceMachine.h>
00019 
00020 namespace shogun
00021 {
00022 class CDistanceMachine;
00023 
00037 class CHierarchical : public CDistanceMachine
00038 {
00039     public:
00041         CHierarchical();
00042 
00048         CHierarchical(int32_t merges, CDistance* d);
00049         virtual ~CHierarchical();
00050 
00055         virtual inline EClassifierType get_classifier_type() { return CT_HIERARCHICAL; }
00056 
00062         virtual bool load(FILE* srcfile);
00063 
00069         virtual bool save(FILE* dstfile);
00070 
00075         inline void set_merges(int32_t m)
00076         {
00077             ASSERT(m>0);
00078             merges=m;
00079         }
00080 
00085         inline int32_t get_merges()
00086         {
00087             return merges;
00088         }
00089 
00093         SGVector<int32_t> get_assignment()
00094         {
00095             return SGVector<int32_t>(assignment,table_size);
00096         }
00097 
00101         SGVector<float64_t> get_merge_distances()
00102         {
00103             return SGVector<float64_t>(merge_distance,merges);
00104         }
00105 
00109         SGMatrix<int32_t> get_cluster_pairs()
00110         {
00111             return SGMatrix<int32_t>(pairs,2,merges);
00112         }
00113 
00115         inline virtual const char* get_name() const { return "Hierarchical"; }
00116 
00117     protected:
00126         virtual bool train_machine(CFeatures* data=NULL);
00127 
00131         virtual void store_model_features();
00132 
00134         virtual CLabels* apply();
00135 
00137         virtual CLabels* apply(CFeatures* data);
00138 
00140         virtual float64_t apply(int32_t num);
00141 
00142     protected:
00144         int32_t merges;
00145 
00147         int32_t dimensions;
00148 
00150         int32_t assignment_size;
00151 
00153         int32_t* assignment;
00154 
00156         int32_t table_size;
00157 
00159         int32_t* pairs;
00160 
00162         float64_t* merge_distance;
00163 };
00164 }
00165 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation