-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
117 lines (102 loc) · 3.34 KB
/
Copy pathmain.c
File metadata and controls
117 lines (102 loc) · 3.34 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "Constants.h"
#include "Splitter.h"
#include "Data.h"
#include "Prism.h"
#include "InterfaceWriter.h"
#include "Accuracy.h"
int main(int argc, char **argv)
{
if(argc < 6)
{
printf(USAGE);
exit(-1);
}
char *fileName = argv[1];
int N = atoi(argv[2]);
int P = atoi(argv[3]);
int C = atoi(argv[4]);
int A = atoi(argv[5]);
Accuracy_t maxAccuracy;
maxAccuracy.hits = maxAccuracy.misses = 0;
maxAccuracy.id = -1;
#pragma omp parallel shared(fileName, N, P, C, A, maxAccuracy) num_threads(PROCESSORS)
{
int nthread=omp_get_num_threads();
int id =omp_get_thread_num();
char ID[100];
sprintf(ID, "%d", id);
//printf("%s\n",ID);
//printf("Splitting %d.............\n",id);
split(fileName, N, P, C, A, id, nthread);
//printf("DONE\n");
//printf("Data %d.............\n",id);
char trainsetPath[100];
trainsetPath[0] = '\0';
strcat(strcat(strcat(strcat(trainsetPath, TRAINSETPATH), fileName), ID), ".data");
//printf("%s\n",trainsetPath);
Data_t *data = getData(trainsetPath);
//printData(data);
//printf("Classifying %d.............\n",id);
Prism_t *prism = buildClassifier(data);
//printPrismRules(prism->rules);
//printf("Interface Writing %d.............\n",id);
char rulesetPath[100];
rulesetPath[0] = '\0';
strcat(strcat(strcat(strcat(rulesetPath, RULESETPATH), fileName), ID), ".data");
//printf("%s\n", rulesetPath);
iwrite(prism->rules, rulesetPath, data->attributeSize);
//printf("Accuracy %d.............\n",id);
char testsetPath[100];
testsetPath[0] = '\0';
strcat(strcat(strcat(strcat(testsetPath, TESTSETPATH), fileName), ID), ".data");
Accuracy_t accuracy = getAccuracy(rulesetPath, testsetPath, data->attributeSize + 1);
accuracy.id = id;
int diff = accuracy.hits * maxAccuracy.misses - maxAccuracy.hits * accuracy.misses;
if(maxAccuracy.id == -1 || diff > 0 || (diff == 0 && accuracy.hits > maxAccuracy.hits))
{
maxAccuracy.hits = accuracy.hits;
maxAccuracy.misses = accuracy.misses;
maxAccuracy.id = accuracy.id;
}
/*if(accuracy){
printf("accuracy not null\n");
}
if(accuracy == NULL){
printf("accuracy null\n");
}*/
//printf("accuracy %d\n", accuracy.hits);
printAccuracy(accuracy);
}
printf("\nMAX ACCURACY\n");
printAccuracy(maxAccuracy);
int id;
char ID[100], path[100];
for(id = 0;id < PROCESSORS; id++)
{
if(id != maxAccuracy.id)
{
//remove the trainset files except the one with the maximum accuracy.
ID[0] = path[0] = '\0';
sprintf(ID, "%d", id);
strcat(strcat(strcat(strcat(path, TRAINSETPATH), fileName), ID), ".data");
remove(path);
path[0] = '\0';
strcat(strcat(strcat(strcat(path, TRAINSETPATH), fileName), ID), ".arff");
remove(path);
//remove the testset files except the one with the maximum accuracy.
path[0] = '\0';
strcat(strcat(strcat(strcat(path, TESTSETPATH), fileName), ID), ".data");
remove(path);
path[0] = '\0';
strcat(strcat(strcat(strcat(path, TESTSETPATH), fileName), ID), ".arff");
//remove the ruleset files except the one with the maximum accuracy.
path[0] = '\0';
strcat(strcat(strcat(strcat(path, RULESETPATH), fileName), ID), ".data");
remove(path);
}
}
return 0;
}