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 00052 MACHINE_PROBLEM_TYPE(PT_MULTICLASS); 00053 00058 virtual EMachineType get_classifier_type(); 00059 00065 virtual bool load(FILE* srcfile); 00066 00072 virtual bool save(FILE* dstfile); 00073 00078 inline void set_merges(int32_t m) 00079 { 00080 ASSERT(m>0); 00081 merges=m; 00082 } 00083 00088 int32_t get_merges(); 00089 00093 SGVector<int32_t> get_assignment(); 00094 00098 SGVector<float64_t> get_merge_distances(); 00099 00103 SGMatrix<int32_t> get_cluster_pairs(); 00104 00106 virtual const char* get_name() const { return "Hierarchical"; } 00107 00108 protected: 00117 virtual bool train_machine(CFeatures* data=NULL); 00118 00122 virtual void store_model_features(); 00123 00124 virtual bool train_require_labels() const { return false; } 00125 00126 protected: 00128 int32_t merges; 00129 00131 int32_t dimensions; 00132 00134 int32_t assignment_size; 00135 00137 int32_t* assignment; 00138 00140 int32_t table_size; 00141 00143 int32_t* pairs; 00144 00146 float64_t* merge_distance; 00147 }; 00148 } 00149 #endif