-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
69 lines (49 loc) · 2.23 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
#include <iostream>
#include <ctime>
#include <fstream>
#include "attributesData/attributeData.h"
#include "dataReaders/textDataReader.h"
#include "dataParsers/textDataParser.h"
#include "groupingAlgorithms/classicalAHCAlgorithm.h"
#include "objectSimilarityMeasures/customObjectSimilarityMeasure.h"
#include "objectSimilarityMeasures/attributesSimilarityMeasures/numerical/smcNumericalAttributesSimilarityMeasure.h"
#include "objectSimilarityMeasures/attributesSimilarityMeasures/categorical/smcCategoricalAttributesSimilarityMeasure.h"
#include "clustersSimilarityMeasures/singleLinkClusterSimilarityMeasure.h"
#include "clustersSimilarityMeasures/completeLinkClusterSimilarityMeasure.h"
#include "clustersSimilarityMeasures/averageLinkClusterSimilarityMeasure.h"
int main()
{
// Initialize time-dependent random seed
srand (time(NULL));
// Get source file
ifstream sourceFile("D:\\Dysk Google\\Data Streams\\sensor.arff");
// Initialize timer
clock_t begin = clock();
// Generate samples and gather attributes data
unordered_map<string, attributeData*> attributesData;
dataReader* dr = new textDataReader(&sourceFile);
dataParser* dp = new textDataParser(&attributesData);
dr->gatherAttributesData(&attributesData);
dp->setAttributesOrder(dr->getAttributesOrder());
vector<sample*> samples;
vector<cluster> clusters;
for(int i = 0; i < 1000; ++i)
{
dr->getNextRawDatum(dp->buffer);
dp->addDatumToContainer(&samples);
dp->parseData(samples.back());
}
// Group objects
int numberOfClusters = 10;
attributesSimilarityMeasure* nAttrSimMeasure = new smcNumericalAttributesSimilarityMeasure();
attributesSimilarityMeasure* cAttrSimMeasure = new smcCategoricalAttributesSimilarityMeasure();
objectsSimilarityMeasure *oSimMeasure =
new customObjectSimilarityMeasure(&attributesData, nAttrSimMeasure, cAttrSimMeasure);
clustersSimilarityMeasure* cSimMeasure = new singleLinkClusterSimilarityMeasure(oSimMeasure);
groupingAlgorithm* a = new classicalAHCAlgorithm(numberOfClusters, cSimMeasure);
a->groupObjects(&samples, &clusters);
clock_t end = clock();
double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
cout << "Objects clustered in in " << elapsed_secs << " seconds.\n";
return 0;
}