-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.cpp
103 lines (78 loc) · 2.42 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <iostream>
#include <unordered_map>
#include "HashFunction.h"
//#include "LSH.h"
#include <random>
#include <algorithm>
#include <math.h>
#include "SignedRandomProjection.h"
//#include "L2LSH.h"
#include "MCMC.h"
#include "Gaussian.h"
//#pragma once
/* Author: Chen Luo
* COPYRIGHT PROTECTION
* Free for research use.
* For commercial use, contact: RICE UNIVERSITY INVENTION & PATENT or the Author.
*/
using namespace std;
//using namespace concurrency;
int main (int argc, char *argv[])
{
// Generate a sample data here to do experiment.
// With 0,1 one cluster, 3,4 one cluster
int K = 3;
int L = 1;
int dim = 3;
int N = 100; // Datasize
int clusnum = 10;
double ** data = new double*[N];
int * label = new int[N];
for (int i=0;i<N;i++)
{
data[i] = new double[dim];
Gaussian * gaussian = new Gaussian((double)(i % clusnum), 2, dim);
data[i] = gaussian->getData();
//cout << data[i][0] << endl;
}
/*
MCMC * mcmc = new MCMC(data, label, N, dim, clusnum, K, L);
clock_t t1, t2;
t1 = clock();
//mcmc->EM_GMM(clusnum);
//mcmc->SM_GMM();
//mcmc->SDDSSM_GMM();
mcmc->LSHSM_GMM();
t2 = clock();
printf ("It took me %f seconds.\n",((float)t2 - (float)t1)/CLOCKS_PER_SEC);
return 0;
*/
LSH* lsh = new LSH(K,L);
L2LSH * l2lsh = new L2LSH(dim, K*L) ;
for (int j=0; j<N; j++ )
{
lsh->add(l2lsh->getHash(data[j], dim), j);
}
for (int i=0; i<N; i++ )
{
cout << "Data Number: " << i << endl;
// What happened with the hashing here!
int * candidates = lsh->retrieve(l2lsh->getHash(data[i], dim));
for (int j=0; j< candidates[0]; j++)
{
cout <<candidates[j+2] << " "; // the top 2 value is nothing!
}
cout << endl;
}
/*
int* sample = lsh->sample(srp->getHash(data[2], 3)) ;
printf("%d, %d, %d\n", sample[0], sample[1], sample[2]);
int range = 1<<lsh->_rangePow;
cout << "range" << range << endl;
cout << "collision" << srp->getProb(data[2],data[sample[0]], 3) << endl;
double cp = (1.0 - 1.0/(range))*srp->getProb(data[2],data[sample[0]], 3) + 1.0/(range);
cout << "cp:" << (1.0 - pow((1.0 - pow(cp,K)),sample[2])) << endl;
double p = (1.0 - pow((1.0 - pow(cp,K)),sample[2]+1))*(1.0/sample[1]);
cout << "Hello World!, p=" <<p<< "\n" ;
*/
}