SHOGUN  v3.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 
53 
55 
56 
61 
67  virtual bool load(FILE* srcfile);
68 
74  virtual bool save(FILE* dstfile);
75 
80  void set_k(int32_t p_k);
81 
86  int32_t get_k();
87 
92  void set_max_iter(int32_t iter);
93 
99 
105 
111 
116  int32_t get_dimensions();
117 
119  virtual const char* get_name() const { return "KMeans"; }
120 
121  protected:
127  void clustknb(bool use_old_mus, float64_t *mus_start);
128 
137  virtual bool train_machine(CFeatures* data=NULL);
138 
140  virtual void store_model_features();
141 
142  virtual bool train_require_labels() const { return false; }
143 
144  private:
145  void init();
146 
147  protected:
149  int32_t max_iter;
150 
152  int32_t k;
153 
155  int32_t dimensions;
156 
159 
160  private:
161  /* temporary variable for weighting over the train data */
162  SGVector<float64_t> Weights;
163 
164  /* temp variable for cluster centers */
166 
167 };
168 }
169 #endif
170 

SHOGUN Machine Learning Toolbox - Documentation