Association rule mining with modal logic
New building blocks
ModalAssociationRules.WorldMask
— Typeconst WorldMask = BitVector
Vector whose i-th position stores how many times a certain MeaningfulnessMeasure
applied on a specific Itemset
s is true on the i-th world of multiple instances.
If a single instance is considered, then this acts as a bit mask.
For example, if we consider 5 Kripke structures of a modal dataset, each of which containing 3 worlds, then the WorldMask
of an itemset could be [5,2,0], meaning that the itemset is always true on the first world of every instance. In the second world, the same itemset is true on it only for two instances. Considering the third world, then the itemset is never true.
See also Itemset
, MeaningfulnessMeasure
.
ModalAssociationRules.EnhancedItemset
— Typeconst EnhancedItemset = Tuple{Itemset,UInt32}
Compressed representation of multiple, identical Itemset
s.
See also Itemset
.
ModalAssociationRules.ConditionalPatternBase
— Typeconst ConditionalPatternBase = Vector{EnhancedItemset}
Collection of EnhancedItemset
.
This plays a central role in the state-of-the-art algorithm fpgrowth
, where a ConditionalPatternBase
embodies all the information needed to build an FPTree
data structure in the algorithm.
See also EnhancedItemset
, fpgrowth
, FPTree
.
Modal logic in action
Missing docstring for initminingstate(::typeof(fpgrowth), ::MineableData)
. Check Documenter's build log for details.
Meaningfulness measures
In general, we can define new meaningfulness measures by leveraging the following macros.
ModalAssociationRules.@localmeasure
— Macromacro localmeasure(measname, measlogic)
Build a generic local meaningfulness measure, levering the optimizations provided by any AbstractMiner
.
Arguments
measname
: the name of the local measure you are defining (e.g., lsupport);measlogic
: a lambda function whose arguments are (itemset, data, ith_instance, miner) -
see the note below to know more about this.
When defining a new local measure, you only need to write its essential logic through a lambda function (itemset, X, ith_instance, miner).
In particular, itemset
is an Itemset
, X
is a reference to the dataset, ith_instance
is an integer defining on which instance you want to compute the measure, and miner
is the AbstractMiner
in which you want to save the measure.
Also, miner
argument can be used to leverage its miningstate
structure. A complete example of the logic behind local support is shown below:
_lsupport_logic = (itemset, X, ith_instance, miner) -> begin
# vector representing on which world an Itemset holds
wmask = [
check(formula(itemset), X, ith_instance, w) for w in allworlds(X, ith_instance)]
# return the result enriched with more informations, that will eventually will be
# used if miner's miningstate has specific fields (e.g., :instance_item_toworlds).
return Dict(
:measure => count(wmask) / length(wmask),
:instance_item_toworlds => wmask,
)
end
See also AbstractMiner
, hasminingstate
, lsupport
, miningstate
.
ModalAssociationRules.@globalmeasure
— Macromacro globalmeasure(measname, measlogic)
Build a generic global meaningfulness measure, levering the optimizations provided by any AbstractMiner
.
Arguments
measname
: the name of the global measure you are defining (e.g., gsupport);measlogic
: a lambda function whose arguments are (rule, X, threshold, miner) - see the
note below to know more about this.
When defining a new global measure, you only need to write its essential logic through a lambda function (itemset, X, ith_instance, miner).
In particular, itemset
is an Itemset
, X
is a reference to the dataset and miner
is the AbstractMiner
in which you want to save the measure.
Also, miner
argument can be used to leverage its miningstate
structure. A complete example of the logic behind global support is shown below:
_gsupport_logic = (itemset, X, threshold, miner) -> begin
_measure = sum([
lsupport(itemset, getinstance(X, ith_instance), miner) >= threshold
for ith_instance in 1:ninstances(X)
]) / ninstances(X)
# at the moment, no `miningstate` fields in miner are leveraged
return Dict(:measure => _measure)
end
See also AbstractMiner
, hasminingstate
, gsupport
, miningstate
.
ModalAssociationRules.@linkmeas
— Macromacro linkmeas(gmeasname, lmeasname)
Link together two MeaningfulnessMeasure
, automatically defining globalof
/localof
and isglobalof
/islocalof
traits.
See also globalof
, isglobalof
, islocalof
, localof
, MeaningfulnessMeasure
.
We already introduced lsupport
, gsupport
, lconfidence
and gconfidence
in the Getting started
section. Other measures that are already built into the package, are the following; note how they are always organized in both local and global versions.
ModalAssociationRules.llift
— Functionfunction llift(
rule::ARule,
ith_instance::LogicalInstance;
miner::Union{Nothing,AbstractMiner}=nothing
)::Float64
Compute the local lift for the given rule
.
Local lift measures how far from independence are rule
's antecedent
and consequent
on a modal logic instance.
Given an ARule
X ⇒ Y
, if local lift value is around 1, then this means that P(X ⋃ Y) = P(X)P(Y)
, and hence, the two Itemset
s X
and Y
are independant. If value is greater than (lower than) 1, then this means that X
and Y
are dependant and positively (negatively) correlated Itemset
s.
If a miner is provided, then its internal state is updated and used to leverage memoization.
See also AbstractMiner
, antecedent
, ARule
, glift
, LogicalInstance
, llift
, Threshold
.
ModalAssociationRules.glift
— Functionfunction glift(
rule::ARule,
X::SupportedLogiset,
threshold::Threshold;
miner::Union{Nothing,AbstractMiner}=nothing
)::Float64
See also llift
.
ModalAssociationRules.lconviction
— Functionfunction lconviction(
rule::ARule,
ith_instance::LogicalInstance;
miner::Union{Nothing,AbstractMiner}=nothing
)::Float64
Compute the local conviction for the given rule
.
Conviction attempts to measure the degree of implication of a rule. It's value ranges from 0 to +∞. Unlike lift, conviction is sensitive to rule direction; like lift, values far from 1 indicate interesting rules.
If a miner is provided, then its internal state is updated and used to leverage memoization.
See also AbstractMiner
, antecedent
, ARule
, LogicalInstance
, llift
, Threshold
.
ModalAssociationRules.gconviction
— Functionfunction gconviction(
rule::ARule,
X::SupportedLogiset,
threshold::Threshold;
miner::Union{Nothing,AbstractMiner}=nothing
)::Float64
See also lconviction
.
ModalAssociationRules.lleverage
— Functionfunction lleverage(
rule::ARule,
X::SupportedLogiset,
threshold::Threshold;
miner::Union{Nothing,AbstractMiner}=nothing
)::Float64
Compute the local leverage for the given rule
.
Measures how much more counting is obtained from the co-occurrence of the antecedent
and consequent
from the expected (from independence).
This value ranges between [-0.25,0.25].
See also AbstractMiner
, antecedent
, ARule
, consequent
, LogicalInstance
, Threshold
.
ModalAssociationRules.gleverage
— Functionfunction gleverage(
rule::ARule,
X::SupportedLogiset,
threshold::Threshold;
miner::Union{Nothing,AbstractMiner}=nothing
)::Float64
See also lleverage
.