26 void (*callback)(
void *stateptr,
int nitems,
int *itemids,
int ntrans,
int *transids);
39 int preflen,
int *prefix);
48 int minfreq,
int maxfreq,
int minlen,
int maxlen,
49 void (*process_itemset)(
void *stateptr,
int nitems,
int *itemids,
50 int ntrans,
int *transids),
61 mat->ncols = tranind[gk_iargmax(tranptr[ntrans], tranind)]+1;
62 mat->rowptr = gk_zcopy(ntrans+1, tranptr, gk_zmalloc(ntrans+1,
"gk_find_frequent_itemsets: mat.rowptr"));
63 mat->rowind = gk_icopy(tranptr[ntrans], tranind, gk_imalloc(tranptr[ntrans],
"gk_find_frequent_itemsets: mat.rowind"));
64 mat->colids = gk_iincset(
mat->ncols, 0, gk_imalloc(
mat->ncols,
"gk_find_frequent_itemsets: mat.colids"));
68 params.maxfreq = (maxfreq == -1 ?
mat->nrows : maxfreq);
70 params.maxlen = (maxlen == -1 ?
mat->ncols : maxlen);
72 params.callback = process_itemset;
73 params.stateptr = stateptr;
74 params.rmarker = gk_ismalloc(
mat->nrows, 0,
"gk_find_frequent_itemsets: rmarker");
75 params.cand = gk_ikvmalloc(
mat->ncols,
"gk_find_frequent_itemsets: cand");
82 pattern = gk_imalloc(pmat->
ncols,
"gk_find_frequent_itemsets: pattern");
96 int preflen,
int *prefix)
102 for (
i=0;
i<
mat->ncols;
i++) {
103 prefix[preflen] =
mat->colids[
i];
105 if (preflen+1 >=
params->minlen)
106 (*
params->callback)(
params->stateptr, preflen+1, prefix,
109 if (preflen+1 <
params->maxlen) {
131 int nrows, ncols, pnrows, pncols;
133 int *colind, *colids, *pcolind, *pcolids, *rmarker;
139 colptr =
mat->colptr;
140 colind =
mat->colind;
141 colids =
mat->colids;
143 rmarker =
params->rmarker;
149 pmat->
nrows = pnrows = (cid == -1 ? nrows : colptr[cid+1]-colptr[cid]);
154 gk_iset(nrows, 1, rmarker);
157 for (
i=colptr[cid];
i<colptr[cid+1];
i++)
158 rmarker[colind[
i]] = 1;
163 for (pncols=0, pnnz=0,
i=cid+1;
i<ncols;
i++) {
164 for (k=0,
j=colptr[
i];
j<colptr[
i+1];
j++) {
165 k += rmarker[colind[
j]];
167 if (k >=
params->minfreq && k <= params->maxfreq) {
168 cand[pncols].val =
i;
169 cand[pncols++].key = k;
179 pmat->
ncols = pncols;
180 pmat->
colids = pcolids = gk_imalloc(pncols,
"itemsets_project_matrix: pcolids");
181 pmat->
colptr = pcolptr = gk_zmalloc(pncols+1,
"itemsets_project_matrix: pcolptr");
182 pmat->
colind = pcolind = gk_imalloc(pnnz,
"itemsets_project_matrix: pcolind");
187 for (pnnz=0, ii=0; ii<pncols; ii++) {
189 for (
j=colptr[
i];
j<colptr[
i+1];
j++) {
190 if (rmarker[colind[
j]])
191 pcolind[pnnz++] = colind[
j];
194 pcolids[ii] = colids[
i];
195 pcolptr[ii+1] = pnnz;
201 gk_iset(nrows, 0, rmarker);
204 for (
i=colptr[cid];
i<colptr[cid+1];
i++)
205 rmarker[colind[
i]] = 0;