Initial commit.
[clueless-kmeans.git] / clusterer.h
1 /*
2  *  clueless-kmean is a variant of k-mean which enforces balanced
3  *  distribution of classes in every cluster
4  *
5  *  Copyright (c) 2013 Idiap Research Institute, http://www.idiap.ch/
6  *  Written by Francois Fleuret <francois.fleuret@idiap.ch>
7  *
8  *  This file is part of clueless-kmean.
9  *
10  *  clueless-kmean is free software: you can redistribute it and/or
11  *  modify it under the terms of the GNU General Public License
12  *  version 3 as published by the Free Software Foundation.
13  *
14  *  clueless-kmean is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  *  General Public License for more details.
18  *
19  *  You should have received a copy of the GNU General Public License
20  *  along with selector.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  */
23
24 #ifndef CLUSTERER_H
25 #define CLUSTERER_H
26
27 #include "misc.h"
28 #include "arrays.h"
29
30 class Clusterer {
31 public:
32   const static int max_nb_iterations = 10;
33   const static scalar_t min_iteration_improvement = 0.999;
34
35   int _nb_clusters;
36   int _dim;
37   scalar_t **_cluster_means, **_cluster_var;
38
39   void initialize_clusters(int nb_points, scalar_t **points);
40
41   scalar_t baseline_cluster_association(int nb_points, scalar_t **points,
42                                         int nb_classes, int *labels,
43                                         scalar_t **gamma);
44
45   scalar_t baseline_lp_cluster_association(int nb_points, scalar_t **points,
46                                            int nb_classes, int *labels,
47                                            scalar_t **gamma);
48
49   scalar_t uninformative_lp_cluster_association(int nb_points, scalar_t **points,
50                                                 int nb_classes, int *labels,
51                                                 scalar_t **gamma);
52
53   void baseline_update_clusters(int nb_points, scalar_t **points, scalar_t **gamma);
54
55 public:
56   Clusterer();
57   ~Clusterer();
58   void train(int nb_clusters, int dim,
59              int nb_points, scalar_t **points,
60              int nb_classes, int *labels,
61              int *cluster_associations);
62
63   int cluster(scalar_t *point);
64 };
65
66 #endif