Advanced usage

The following utilities often involve performing some combinatoric trick between Itemsets and ARules, and might be useful to avoid reinventing the wheel.

Items and Itemsets

ModalAssociationRules.combine_itemsFunction
combine_items(itemsets::AbstractVector{<:Itemset}, newlength::Integer)

Return a generator which combines Itemsets from itemsets into new itemsets of length newlength by taking all combinations of two itemsets and joining them.

See also Itemset.

source
combine_items(variable::AbstractVector{<:Item}, fixed::AbstractVector{<:Item})

Return a generator of Itemset, which iterates the combinations of Items in variable and prepend them to fixed vector.

See also Item, Itemset.

source
ModalAssociationRules.grow_pruneFunction
grow_prune(
    candidates::AbstractVector{Itemset},
    frequents::AbstractVector{Itemset},
    k::Integer
)

Return a generator, which yields only the candidates for which every (k-1)-length subset is in frequents.

See also Itemset.

source

Association rules

ModalAssociationRules.generaterulesMethod

generaterules(itemsets::AbstractVector{Itemset}, miner::AbstractMiner)

Raw subroutine of generaterules!(miner::AbstractMiner; kwargs...).

Generates ARule from the given collection of itemsets and miner.

The strategy followed is described here at section 2.2.

To establish the meaningfulness of each association rule, check if it meets the global constraints specified in arulemeasures(miner), and yields the rule if so.

See also AbstractMiner, ARule, Itemset, arulemeasures.

source
generaterules(itemsets::AbstractVector{Itemset}, miner::Miner)

Return a generator for the ARules that can be generated starting from the itemsets in itemsets, using the mining state saved within the miner structure.

See Itemset, Miner.

source

Mining Policies

It is possible to limit the action of the mining, to force an AbstractMiner to only consider a subset of the available data.

We can also constrain the generation of new itemsets and rules, by defining a vector of policies. For what regards itemsets, the following dispatches are available:

ModalAssociationRules.itemset_policiesFunction
function itemset_policies(::AbstractMiner)

Return the mining policies vector wrapped within an AbstractMiner. Each mining policies is a meta-rule describing which Itemset are accepted during the mining phase and which are discarded.

Warning

These policies often require to be tailored ad-hoc for a specific mining algorithm, and have the role of pruning unwanted explorations of the search space as early as possible.

Keep in mind that you may need to modify some existing policies to make them correct and effective for your custom algorithm.

As far as the algorithms already implemented in this package are concerned, generation policies are applied before saving an itemset inside the miner: thus, they reduce the waste of memory, but not necessarily of computational time.

See also AbstractMiner, generaterules, arule_policies.

source
function itemset_policies(miner::Miner)

See itemset_policies(::AbstractMiner).

source
itemset_policies(bulldozer::Bulldozer)

See also itemset_policies(::AbstractMiner).

source
ModalAssociationRules.islimited_length_itemsetFunction
function islimited_length_itemset(; maxlength::Union{Nothing,Integer}=nothing)::Function

Closure returning a boolean function F with one argument itemset::Itemset.

F is true if the length of the given itemset does not exceed the given thresholds.

Arguments

  • maxlength::Union{Nothing,Integer}=nothing: maximum itemset's length; when nothing, defaults to typemax(Int16).

See also Itemset, itemset_policies.

source
ModalAssociationRules.isanchored_itemsetFunction
function isanchored_itemset(;
    npropositions::Integer=1,
    ignoreuntillength::Integer=1
)::Function

Closure returning a boolean function F with one argument rule::Itemset.

F is true if the given itemset contains atleast npropositions propositional anchors (that is, propositions without modal operators).

Arguments

  • npropositions::Integer=1: minimum number of propositional anchors (propositions with no modal operators) in the antecedent of the given rule.
  • ignoreuntillength::Integer=1: avoid applying the policy to isolated Items, or Itemset short enough.

See Item, Itemset, itemset_policies, isanchored_arule.

source
ModalAssociationRules.isdimensionally_coherent_itemsetFunction
function isdimensionally_coherent_itemset(;)::Function

Closure returning a boolean function F with one argument itemset::Itemset.

This is needed to ensure the Itemset is coherent with the dimensional definition of local support. All the propositions (or anchors) in an itemset must be VariableDistances wrapping references of the same size.

See also Itemset, itemset_policies, SoleData.VariableDistance.

source

The following are referred to association rules:

ModalAssociationRules.islimited_length_aruleFunction
function islimited_length_arule(;
    antecedent_maxlength::Union{Nothing,Integer}=nothing,
    consequent_maxlength::Union{Nothing,Integer}=1
)::Function

Closure returning a boolean function F with one argument rule::ARule.

F is true if the length of rule's antecedent (and consequent) does not exceed the given thresholds.

Arguments

  • antecedent_maxlength::Union{Nothing,Integer}=nothing: maximum antecedent length of the given rule; when nothing, defaults to typemax(Int16);
  • consequent_maxlength::Union{Nothing,Integer}=1: maximum consequent length of the given rule; when nothing, defaults to typemax(Int16).

See also antecedent, ARule, arule_policies, consequent.

source
ModalAssociationRules.isanchored_aruleFunction
function isanchored_arule(; npropositions::Integer=1)::Function

Closure returning a boolean function F with one argument rule::ARule.

F is true if the given rule contains atleast npropositions propositional anchors (that is, propositions without modal operators).

Arguments

  • npropositions::Integer=1: minimum number of propositional anchors (propositions with no modal operators) in the antecedent of the given rule.

See antecedent, ARule, arule_policies, generaterules, Item, Miner.

source
ModalAssociationRules.isheterogeneous_aruleFunction
function isheterogeneous_arule(;
    antecedent_nrepetitions::Integer=1,
    consequent_nrepetitions::Integer=0,
    consider_thresholds::Bool=false
)::Function

Closure returning a boolean function F with one argument rule::ARule.

F is true if the given rule is heterogeneous, that is, across all the Item in rule antecedent and consequent, the number of identical variables V is at most nrepetitions.

Arguments

  • antecedent_nrepetitions::Integer=1: maximum allowed number of identical variables in the antecedent of the given rule.
  • consequent_nrepetitions::Integer=0: maximum allowed number of identical variables between the antecedent and the consequent of the given rule.
  • consider_thresholds::Bool=false: if true, both identical variables and thresholds are considered in the counting.

See antecedent, ARule, consequent, generaterules, Item, Miner.

source