We post two constraints, **CoverSize** to compute the frequency of the pattern and **AdequateClosure** to ensure that `x` is closed w.r.t. the set of measures `{freq(x),max(x.freq)}`.
We post two constraints, **CoverSize** to compute the frequency of the pattern and **AdequateClosure** to ensure that `x` is closed w.r.t. the set of measures `{freq(x),max(x.freq)}`. Note that in this example we use the Domain Consistency version of **AdequateClosure**. If you want to use the Weak Consistency version, just replace AdequateClosureDC by AdequateClosureWC in the code.
```java
List<Pattern>closedPatterns=newLinkedList<>();
...
...
@@ -228,4 +228,103 @@ for (Pattern closed : closedPatterns) {
}
```
Finally, we solve our model and find all the closed patterns.
\ No newline at end of file
Finally, we solve our model and find all the closed patterns with a frequency and length >= 1.
**ExampleCoverClosure**
In this example, we want to mine the set of closed patterns w.r.t. the set of measures `{freq}`. The code is similar to ExampleAdequateClosure.
**ExampleGenerator**
In this example, we want to mine the set of generators (a generator is an itemset which has no subset with the same frequency). We can analyse the code of the main method:
First, we create the data structures to build our model. We create two integer variables `freq` and `length` which represent the frequency and the length of the pattern, and a boolean variables array `x` where `x[i] = 1` means that item `i` belongs to the pattern.
Finally, we solve our model and we find all the generators with a frequency and length >= 1.
**MFI_MII_Mining**
In this example, we want to mine **Maximal Frequent Itemsets** (MFIs) and **Minimal Infrequent Itemsets** (MIIs). First, we can analyse the code of the method createModel, that takes three arguments:
- dataPath: a String which represents the path of the dataset
- mfi: a Boolean which is true if we want to find MFIs, else MIIs
- s: an integer that represents the threshold for the mining
Now, we have to compute the bounds of the freq variable that represents the frequency of the pattern `x`. If `x` is an MFI, then its bounds are `[s,database.getNbTransactions()]`. If `x` is an MII, then its bounds are `[0,s-1]`.
Then we post all the necessary constraints (see the paper of Belaid et al. for more information). Interestingly, if `x` is an MFI, then we have the guarantee that `x` is closed w.r.t. the frequency (since `x` is frequent and its supersets are not frequent) and we can post **CoverClosure** constraint. If `x` is an MII, then we have the guarantee that `x` is a generator (since `x` is infrequent and its subsets are frequent) and we can post **Generator** constraint.
```java
int[]itemFreq=database.computeItemFreq();
BoolVar[]xSorted=IntStream
.range(0,database.getNbItems())
.boxed()
.sorted(Comparator.comparingInt(i->itemFreq[i]))
.map(i->x[i])
.toArray(BoolVar[]::new);
Solversolver=model.getSolver();
solver.setSearch(Search.intVarSearch(
newInputOrder<>(model),
newIntDomainMax(),
xSorted
));
```
As heuristic, we order items by increasing frequency and we instantiate them first to 1.