GPUMLib  0.2.2
GPU Machine Learning Library
KMeans.h
1 /*
2  Ricardo Quintas is an MSc Student at the University of Coimbra, Portugal
3  Copyright (C) 2009, 2010 Ricardo Quintas
4 
5  This file is part of GPUMLib.
6 
7  GPUMLib is free software: you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation, either version 3 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #ifndef KMeans_h
22 #define KMeans_h
23 
24 #include <stdio.h>
25 #include <string.h>
26 #include <vector>
27 #include <algorithm>
28 
29 #include <cuda.h>
30 #include <cuda_runtime.h>
31 
32 #include "../common/CudaDefinitions.h"
33 #include "../common/CudaStreams.h"
34 #include "../memory/HostMatrix.h"
35 #include "../memory/DeviceMatrix.h"
36 #include "../memory/DeviceAccessibleVariable.h"
37 
38 #include <iostream>
39 #include <ctime>
40 
41 #include <cula.h>
42 #include <cublas.h>
43 
44 #define imax(X, Y) ((X) > (Y) ? (X) : (Y))
45 #define imin(X, Y) ((X) < (Y) ? (X) : (Y))
46 #define round(x) (x<0?ceil((x)-0.5):floor((x)+0.5))
47 
48 using namespace std;
49 
50 typedef std::pair<int, float> my_pair;
51 
52 namespace GPUMLib {
53 
56 
58 class KMeans{
59 
60 private:
61 
62  void arrayShuffle(int *array, int length);
63  int randint(int lowest, int highest);
64 
65  CudaStream streamChanged;
67  DeviceAccessibleVariable<bool> changed_bool;
68 
69  unsigned int seed;
70 
71 public:
72 
74  KMeans();
75  ~KMeans();
76 
81  DeviceMatrix<float> Execute_TI(DeviceMatrix<float> &Input, int kneighbours);
82 
87  DeviceMatrix<float> Execute(DeviceMatrix<float> &Input, int kneighbours);
88 
89  void SetSeed(unsigned int seed){
90  this->seed = seed;
91  }
92 
93  unsigned int GetSeed(){
94  return seed;
95  }
96 };
97 
99 
100 }
101 
102 #endif
void arrayShuffle(int *array, int length)
Definition: rbf.h:55
int randint(int lowest, int highest)
Generates a random Integer between lowest and highest values.
Definition: rbf.h:72
Represents a CUDA stream.
Definition: CudaStreams.h:32
Represents a clustering algorithm using the K-Means technique, implemented in CUDA.
Definition: KMeans.h:58