Skip to content

Commit

Permalink
Completed for 3-FI
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiron7077 committed Apr 24, 2024
1 parent 8fb63a1 commit 11efc61
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Extracting `MFI (Maximum Frequent Itemset)` is one of the problem in computer science. It is famously known as `Market Basket Analysis`. In this project I am using a Data Structure known as `CLM (Completely Linked Matrix)` to find MFI more efficiently than ever requiring less time and space. The current project works for extracting `3-FI (FI with 3 itemset length)` and the MFI from them. Further work is being done to enhance the scope to finding FI of greater itemset length.

## Getting Started
To be able to have this project work on your local machine, all you need is a C++ compiler such as [MinGW](https://www.mingw-w64.org/downloads/) which you can also download through [MSYS2](https://www.msys2.org/). After installing a compiler you can download a Code Editor like [VSC](https://code.visualstudio.com/download) or an IDE like [Clion](https://www.jetbrains.com/clion/download/#section=windows) for viewing the code and editing it.
To be able to have this project work on your local machine, all you need is a C++ compiler such as [Clang](https://clang.llvm.org/) which can be downloaded through [MinGW](https://www.mingw-w64.org/downloads/); a cross compilation toolchain. If you are having difficulties downloading MinGW, it can also be downloaded through [MSYS2](https://www.msys2.org/). After installing a compiler you can download a Code Editor like [VSC](https://code.visualstudio.com/download) or an IDE like [Clion](https://www.jetbrains.com/clion/download/#section=windows) for viewing the code and editing it.

### Installing
You can simply add this project to your system using Git Clone or just downloading this project as a zip file and then extracting it.
Expand Down
78 changes: 53 additions & 25 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

using namespace std;

//Graph for storing transactions and items
// Finds the position of data within the vector
int find_position(const vector<Node *>& node_vector, char letter);

// Graph for storing transactions and items
class Graph {
private:
//Vector to store all the get_nodes
Expand All @@ -28,14 +31,15 @@ class Graph {

//Check if node is present in graph
bool is_present(const char &data) {
for (Node *node: node_vector) {
for(Node *node: node_vector) {
if (node->data == data) {
return true;
}
}
return false;
}

//Sorts graph in an ascending order of nodes
void sort_graph() {
int size = node_vector.size();

Expand Down Expand Up @@ -231,17 +235,19 @@ class CLM {

// Inputs the values of get_nodes and edge support count
void input_graph(Graph &graph) {
// Gets the node vector
vector<Node *> node_vector = graph.get_nodes();
int matrix = graph.get_size() + 1;

int node_position = 0;

// Nested for loop for input of all values
for (Node *node: node_vector) {
// Finds position of column of 1-itemsets and adds Sup
int node_position = node->data - 'A';
clm_array[node_position][(node_position * matrix)] = node->weight;
for (Edge *edge: node->edges) {
// Finds position of column of 2-itemsets and adds Sup
int to_position = edge->to->data - 'A';
int to_position = find_position(node_vector, edge->to->data);

if (clm_array[node_position][(to_position * matrix)] != 0) {
clm_array[node_position][(to_position * matrix)]++;
} else {
Expand All @@ -254,35 +260,37 @@ class CLM {
combination += edge->to->data;

// Counter for the loop
int counter = graph.get_size() - (edge->to->data - 'A') - 1;
int counter = graph.get_size() - find_position(node_vector, edge->to->data) - 1;

// Adds the Sup for 3-itemsets
for (pair<string, int> *pairs: combinations) {
if (pairs->first.size() == 3) {
for (int i = 0; i < counter; i++) {
string itemset = combination;
int third_position = (edge->to->data + i + 1) - 'A' + 1;
itemset += edge->to->data + i + 1;
int third_position = to_position + i + 2;
itemset += node_vector.at(to_position + i + 1)->data;
if (pairs->first == itemset) {
clm_array[node_position][(to_position * matrix) + third_position] = pairs->second;
}
}
}
}
}
node_position ++;
}
}

void find_FI(int minSup, int matrix) {
//Finds all the FI according to the MinSup
void find_FI(int minSup, int matrix, const vector<Node *>& node_vector) {
vector<string> FIs;
string fi;
// Loop to check all the sup
for (int i = 0; i < row; i++) {
char first = 'A' + i;
char first = node_vector.at(i)->data;
fi += first;
for (int j = 0; j < column; j++) {
if (clm_array[i][j] >= minSup) {
char second = 'A' + (j / matrix);
char second = node_vector.at(j / matrix)->data;
if (first == second) {
// Stores 1-FI
FIs.push_back(fi);
Expand All @@ -295,7 +303,7 @@ class CLM {
fi = first;
} else {
// Stores 3-FI
char third = 'A' + (j % matrix) - 1;
char third = node_vector.at((j % matrix) - 1)->data;
fi += third;
FIs.push_back(fi);
fi = first;
Expand Down Expand Up @@ -334,21 +342,29 @@ class CLM {
cout << endl;
}

void print(vector<Node *> nodes) {
//Showcases the CLM
void print(vector<Node *> node_vector) {
cout << "\n\nCLM:\n\n";
cout << " ";
for (Node *node1: nodes) {
cout << node1->data << " ";
for (Node *node2: nodes) {
for (Node *node1: node_vector) {
cout << "| " << node1->data << " | ";
for (Node *node2: node_vector) {
cout << node2->data << " ";
}

}

cout << endl;
for (int i = 0; i < row; i++) {
cout << nodes.at(i)->data << " ";
cout << node_vector.at(i)->data << " | ";
for (int j = 0; j < column; j++) {
cout << clm_array[i][j] << " ";
if(j == 0){
cout << clm_array[i][j] << " | ";
} else if(j % (node_vector.size() + 1) == 0){
cout << "| " << clm_array[i][j] << " | ";
} else {
cout << clm_array[i][j] << " ";
}
}
cout << endl;
}
Expand All @@ -358,12 +374,12 @@ class CLM {
int main() {
Graph graph;

graph.add_transaction("BCDE");
graph.add_transaction("ABDE");
graph.add_transaction("BCDE");
graph.add_transaction("ABCDE");
graph.add_transaction("DE");
graph.add_transaction("C");
graph.add_transaction("EFLY");
graph.add_transaction("CELY");
graph.add_transaction("EFLY");
graph.add_transaction("CEFLY");
graph.add_transaction("LY");
graph.add_transaction("F");

graph.displayGraph();

Expand All @@ -373,9 +389,21 @@ int main() {

clm.print(graph.get_nodes());

clm.find_FI(1, graph.get_size() + 1);
clm.find_FI(2, graph.get_size() + 1, graph.get_nodes());

cout << endl;
system("pause");
return 0;
}

// Finds the position of data in the vector
int find_position(const vector<Node *>& node_vector, char letter){
int position = 0;
for(Node* node : node_vector){
if(node->data == letter){
return position;
}
position ++;
}
return -1;
}

0 comments on commit 11efc61

Please sign in to comment.