SHOGUN  v1.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
KMeans.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 1999-2008 Gunnar Raetsch
8  * Written (W) 2007-2009 Soeren Sonnenburg
9  * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
10  */
11 
12 #ifndef _KMEANS_H__
13 #define _KMEANS_H__
14 
15 #include <stdio.h>
16 #include <shogun/lib/common.h>
17 #include <shogun/io/SGIO.h>
21 
22 namespace shogun
23 {
24 class CDistanceMachine;
25 
39 class CKMeans : public CDistanceMachine
40 {
41  public:
43  CKMeans();
44 
50  CKMeans(int32_t k, CDistance* d);
51  virtual ~CKMeans();
52 
57  virtual inline EClassifierType get_classifier_type() { return CT_KMEANS; }
58 
64  virtual bool load(FILE* srcfile);
65 
71  virtual bool save(FILE* dstfile);
72 
77  void set_k(int32_t p_k);
78 
83  int32_t get_k();
84 
89  void set_max_iter(int32_t iter);
90 
96 
102 
108 
113  int32_t get_dimensions();
114 
116  inline virtual const char* get_name() const { return "KMeans"; }
117 
118  protected:
124  void clustknb(bool use_old_mus, float64_t *mus_start);
125 
134  virtual bool train_machine(CFeatures* data=NULL);
135 
137  virtual void store_model_features();
138 
139  private:
140  void init();
141 
142  protected:
144  int32_t max_iter;
145 
147  int32_t k;
148 
150  int32_t dimensions;
151 
154 
155  private:
156  /* temporary variable for weighting over the train data */
157  SGVector<float64_t> Weights;
158 
159  /* temp variable for cluster centers */
161 
162 };
163 }
164 #endif
165 

SHOGUN Machine Learning Toolbox - Documentation