void GLCM::GLCMloop(ItemSet P, BinaryMatrix& res, vector< vector< pair<int,int> > > G1Item, const vector<BinaryMatrix *> & vBM, string freType, string so , std::ostream &output, int & resFre, bool printTSsFlag) { if ((P.size() != 0) && (resFre < _threshold)) { return; } if (P.size() != 0) { if (resFre != G1Item[0].size()){ dumpItemset(output,P,resFre); nbIS++; if (printTSsFlag){ list<TransactionSequence> TSl; TSl.clear(); TSl = buildTSList(res); dumpTSs(output,TSl); } } } int k = 0; int core_i = -1; if (P.size() != 0) core_i = P.getCore_i(); if ((core_i % 2 != 0) || core_i == -1) k = core_i; else k = core_i + 1; BinaryMatrix calGBM(vBM[0]->getSize()); int G1ItemSize = G1Item.size(); for (int i = k + 1; i < G1ItemSize; i++) { ItemSet P1 = P.addItemwCore_i(i); if (P != P1) { calGBM = (*vBM[i]); if (res.getSize() != 0) calGBM &= res; int resourceFre = 0; ItemSet Q = calF(&calGBM,G1Item,vBM,freType,resourceFre); if (Q.size() != 0) { Q.setCore_i(P1.getCore_i()); if (Q.prefixEqual(P1)) { GLCMloop(Q, calGBM, G1Item, vBM, freType, so, output, resourceFre, printTSsFlag); } } } } }
void GLCM::Print_An_Itemset(ItemSet IS) { list<ItemSet>::iterator it; cout << " ["; for (int i = 0; i < IS.size(); i++) { if ((IS.getItemAt(i) % 2) == 0) cout << IS.getItemAt(i)/2 +1 << "+"; else cout << IS.getItemAt(i)/2 +1 << "-"; } cout << "]" << endl; }
void GLCM::dumpItemset(std::ostream &os, ItemSet itemset, int freq){ //os << "[ "; for (int i = 0 ; i < itemset.size() ; i++) { if ((itemset.getItemAt(i) % 2) == 0) os << itemset.getItemAt(i)/2 +1 << "+ "; else os << itemset.getItemAt(i)/2 +1 << "- "; } //os << "] "; os<<" ("<<freq<<")\n"; }
void GLCM::calG(ItemSet is, const vector<BinaryMatrix *> & vBM, BinaryMatrix& res) { int isSize = is.size(); if (isSize == 0) return; res = *vBM[is.getItemAt(0)]; for (int i = 1; i < isSize; i++) res &= *vBM[is.getItemAt(i)]; }
void GLCM::Print_All_Closed_Pattern() { list<ItemSet>::iterator it; cout << "Print all Closed Item set" << endl; for (it = ClosedItemSetList.begin (); it != ClosedItemSetList.end (); it++) { ItemSet itSet = *it; for (int i = 0 ; i < itSet.size() ; i++) { if ((itSet.getItemAt(i) % 2) == 0) cout << itSet.getItemAt(i)/2 +1 << "+ "; else cout << itSet.getItemAt(i)/2 +1 << "- "; } cout << endl; } }
void GLCM::write_to_file(string freType)//const char * filename { TimeTracker tt2; tt2.Start(); //print to file string st = "OUT/out"; time_t tim=time(NULL); tm *now=localtime(&tim); stringstream ssm,ssd,ssh,ssmi,sss;//create a stringstream ssm << now->tm_mon + 1;//add number to the stream ssd << now->tm_mday; ssh << now->tm_hour; ssmi << now->tm_min; sss << now->tm_sec; st = st + ssm.str() + ssd.str() + ssh.str() + ssmi.str() + sss.str(); char * filename = (char*) st.c_str(); ofstream outf(filename); outf << ClosedItemSetList.size() <<" closed gradual frequent Item sets" << endl; list<ItemSet>::iterator it; for (it = ClosedItemSetList.begin (); it != ClosedItemSetList.end (); it++) { outf << "[ "; ItemSet itSet = *it; for (int i = 0 ; i < itSet.size() ; i++) { if ((itSet.getItemAt(i) % 2) == 0) outf << itSet.getItemAt(i)/2 +1 << "+ "; else outf << itSet.getItemAt(i)/2 +1 << "- "; } outf << "]" << endl; } outf.close(); cout << "All Item sets have been written to file: " << st << endl; double ts2 = tt2.Stop(); cout << endl << "Writing took " << setw(5) << ts2 << " sec" << endl; ostringstream ost1; ost1 << getpid (); string cmd1="ps -p "+ost1.str ()+" -o rss"; cout << "Memory usage at writing step: " << endl; //system(cmd1.c_str()); cout << endl; }