-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpattern.h
49 lines (41 loc) · 1.33 KB
/
pattern.h
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
//
// Created by 陈玄 on 2022/4/10.
// Modified by 陈玄 on 2022/4/12.
//
#ifndef UNTITLED121_PATTERN_H
#define UNTITLED121_PATTERN_H
#include <iostream>
#include <vector>
#include "apriori.h"
using namespace std;
void get_subset(vector<vector<int>> *, vector<vector<int>> *, vector<int> *, int);
vector<vector<int>> pattern(vector<vector<int>> *, vector<vector<int>> *, double);
void get_subset(vector<vector<int>> *data, vector<vector<int>> *loop, vector<int> *dataset, double need) {
vector<int> ind;
int dim = int(dataset->size());
for (int i = 0; i < dataset->size(); i++) {
if (*(dataset->data() + i)) { ind.push_back(i); }
}
int n = int(ind.size());
for (int i = 1; i < (1 << n) - 1; i++) {
vector<int> tmp(dim);
for (int j = 0; j < n; j++) {
if (i & (1 << j)) { tmp[ind[j]] = 1; }
}
if (!count(loop->begin(), loop->end(), tmp)) {
if (support(data, &tmp) <= need) {
loop->push_back(tmp);
}
}
}
}
vector<vector<int>> pattern(vector<vector<int>> *data, vector<vector<int>> *fp_set, double conf) {
vector<vector<int>> res;
for (auto i: *fp_set) {
int sup = support(data, &i);
double need = sup / conf;
get_subset(data, &res, &i, need);
}
return res;
}
#endif // UNTITLED121_PATTERN_H