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 EClassifierType get_classifier_type(); 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 int32_t get_merges(); 00086 00090 SGVector<int32_t> get_assignment(); 00091 00095 SGVector<float64_t> get_merge_distances(); 00096 00100 SGMatrix<int32_t> get_cluster_pairs(); 00101 00103 inline virtual const char* get_name() const { return "Hierarchical"; } 00104 00105 protected: 00114 virtual bool train_machine(CFeatures* data=NULL); 00115 00119 virtual void store_model_features(); 00120 00122 virtual CLabels* apply(); 00123 00125 virtual CLabels* apply(CFeatures* data); 00126 00128 virtual float64_t apply(int32_t num); 00129 00130 protected: 00132 int32_t merges; 00133 00135 int32_t dimensions; 00136 00138 int32_t assignment_size; 00139 00141 int32_t* assignment; 00142 00144 int32_t table_size; 00145 00147 int32_t* pairs; 00148 00150 float64_t* merge_distance; 00151 }; 00152 } 00153 #endif