SHOGUN
3.2.1
Main Page
Related Pages
Modules
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
src
shogun
clustering
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
>
18
#include <
shogun/features/DenseFeatures.h
>
19
#include <
shogun/distance/Distance.h
>
20
#include <
shogun/machine/DistanceMachine.h
>
21
22
namespace
shogun
23
{
24
class
CDistanceMachine;
25
27
enum
EKMeansMethod
28
{
29
KMM_MINI_BATCH
,
30
KMM_LLOYD
31
};
32
48
class
CKMeans
:
public
CDistanceMachine
49
{
50
public
:
52
CKMeans
();
53
60
CKMeans
(int32_t k,
CDistance
* d,
EKMeansMethod
f);
61
69
CKMeans
(int32_t k,
CDistance
* d,
bool
kmeanspp=
false
,
EKMeansMethod
f=
KMM_LLOYD
);
70
77
CKMeans
(int32_t k_i,
CDistance
* d_i,
SGMatrix<float64_t>
centers_i,
EKMeansMethod
f=
KMM_LLOYD
);
78
virtual
~CKMeans
();
79
80
81
MACHINE_PROBLEM_TYPE
(
PT_MULTICLASS
)
82
83
87
virtual
EMachineType
get_classifier_type
() {
return
CT_KMEANS
; }
88
94
virtual
bool
load
(FILE* srcfile);
95
101
virtual
bool
save
(FILE* dstfile);
102
107
void
set_k
(int32_t p_k);
108
113
int32_t
get_k
();
114
119
void
set_use_kmeanspp
(
bool
kmpp);
120
125
bool
get_use_kmeanspp
()
const
;
126
131
void
set_fixed_centers
(
bool
fixed);
132
137
bool
get_fixed_centers
();
138
143
void
set_max_iter
(int32_t iter);
144
149
float64_t
get_max_iter
();
150
155
SGVector<float64_t>
get_radiuses
();
156
161
SGMatrix<float64_t>
get_cluster_centers
();
162
167
int32_t
get_dimensions
();
168
170
virtual
const
char
*
get_name
()
const
{
return
"KMeans"
; }
171
176
virtual
void
set_initial_centers
(
SGMatrix<float64_t>
centers);
177
182
void
set_train_method
(
EKMeansMethod
f);
183
188
EKMeansMethod
get_train_method
()
const
;
189
194
void
set_mbKMeans_batch_size
(int32_t b);
195
200
int32_t
get_mbKMeans_batch_size
()
const
;
201
206
void
set_mbKMeans_iter
(int32_t t);
207
212
int32_t
get_mbKMeans_iter
()
const
;
213
219
void
set_mbKMeans_params
(int32_t b, int32_t t);
220
221
private
:
230
virtual
bool
train_machine(
CFeatures
* data=NULL);
231
233
virtual
void
store_model_features();
234
235
virtual
bool
train_require_labels()
const
{
return
false
; }
236
241
SGMatrix<float64_t> kmeanspp();
242
void
init();
243
248
void
set_random_centers(SGVector<float64_t> weights_set, SGVector<int32_t> ClList, int32_t XSize);
249
void
set_initial_centers
(SGVector<float64_t> weights_set,
250
SGVector<int32_t> ClList, int32_t XSize);
251
void
compute_cluster_variances();
252
253
private
:
255
int32_t max_iter;
256
258
bool
fixed_centers;
259
261
int32_t k;
262
264
int32_t dimensions;
265
267
SGVector<float64_t> R;
268
270
SGMatrix<float64_t> mus_initial;
271
273
bool
use_kmeanspp;
274
276
int32_t batch_size;
277
279
int32_t minib_iter;
280
282
SGMatrix<float64_t> mus;
283
285
EKMeansMethod
train_method;
286
};
287
}
288
#endif
289
SHOGUN
Machine Learning Toolbox - Documentation