-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtid_methods.dart
151 lines (145 loc) · 3.23 KB
/
tid_methods.dart
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import 'apriori_methods.dart';
import 'utilities.dart';
import 'package:collection/collection.dart';
Map<dynamic, dynamic> Ck_init(Map<dynamic, dynamic> D) {
print('Génération du premier Ckbar ...');
var result = {};
for (var e in D.entries) {
var new_inv = e.key;
var new_des = [];
for (var s in e.value) {
var elem = <dynamic>{};
elem.add(s);
new_des.add(elem);
}
result[new_inv] = new_des;
}
return result;
}
List<dynamic> itemset_1_TID(List items, Map<dynamic, dynamic> D, int sup) {
var result = [];
Function eq = const SetEquality().equals;
for (var i in items) {
var cpt = 0;
for (var d in D.values) {
for (var j = 0; j < d.length; j++) {
if (eq(i, d[j])) {
cpt += 1;
break;
}
}
}
if (cpt >= sup) {
result.add(i);
}
}
return result;
}
List<dynamic> decompose_set(var S) {
var result = [];
for (var s in S) {
var elem = <dynamic>{};
elem.add(s);
result.add(elem);
}
var temp = [];
for (var r in result) {
temp.add(r);
}
while (temp[0].length < S.length - 1) {
var C = candidate_generation(temp);
temp = C;
}
result.clear();
for (var l in temp) {
result.add(l);
}
return result;
}
Map<dynamic, dynamic> CkBar_generator(
Map<dynamic, dynamic> D, List<dynamic> CANDIDATE) {
var result = {};
for (var d in D.entries) {
var elem = [];
for (var s in CANDIDATE) {
var temp = decompose_set(s);
if (containsAllSets(d.value, temp)) {
elem.add(s);
}
}
if (elem == null) {
continue;
} else {
result[d.key] = elem;
}
}
return result;
}
List<dynamic> candidate_validation_TID(
List<dynamic> C, Map<dynamic, dynamic> datas, int suppmin) {
var result = [];
Function eq = const SetEquality().equals;
for (var i in C) {
var supp = 0.0; // support
for (var d in datas.values) {
for (var j = 0; j < d.length; j++) {
if (eq(i, d[j])) {
supp += 1;
break;
}
}
}
if (supp >= suppmin) {
result.add(i);
}
}
return result;
}
List<dynamic> apriori_TID(
List<dynamic> I, Map<dynamic, dynamic> D, int minsup) {
var result = [];
var Ck_bar1 = Ck_init(D);
print('Calcul des 1-itemsets fréquents ...');
var L1 = itemset_1_TID(I, Ck_bar1, minsup);
print('L1 calculé.');
for (var chaine in L1) {
result.add(chaine);
}
var L = [];
var Ckbar = {};
for (var e in Ck_bar1.entries) {
Ckbar[e.key] = e.value;
}
for (var l in L1) {
L.add(l);
}
var i = 2;
do {
print('Génération de Ck$i ...');
var C = candidate_generation(L);
print('Génération terminée.');
if (C == null) {
break;
}
print('Génération de Ckbar$i ...');
Ckbar = CkBar_generator(Ckbar, C);
print('Ckbar$i a été générée avec succès.');
L.clear();
print('Validations des candidats ...');
L = candidate_validation_TID(C, Ckbar, minsup);
print('L$i calculé.');
if (L.isEmpty) {
break;
} else {
for (var q in L) {
if (contains_set(result, q)) {
continue;
} else {
result.add(q);
}
}
}
i += 1;
} while (L.isNotEmpty);
return result;
}