This class implements the structure needed to store implications and the methods associated.
Ganter B, Obiedkov S (2016). Conceptual Exploration. Springer. https://doi.org/10.1007/978-3-662-49291-8
Hahsler M, Grun B, Hornik K (2005). “arules - a computational environment for mining association rules and frequent item sets.” J Stat Softw, 14, 1-25.
Belohlavek R, Cordero P, Enciso M, Mora Á, Vychodil V (2016). “Automated prover for attribute dependencies in data with grades.” International Journal of Approximate Reasoning, 70, 51-67.
Mora A, Cordero P, Enciso M, Fortes I, Aguilera G (2012). “Closure via functional dependence simplification.” International Journal of Computer Mathematics, 89(4), 510-526.
new()
Initialize with an optional name
ImplicationSet$new(...)
Creates and initialize a new ImplicationSet
object. It can be done in two ways:
initialize(name, attributes, lhs, rhs)
or initialize(rules)
In the first way, the only mandatory argument is attributes
, (character vector) which is a vector of names of the attributes on which we define the implications. Optional arguments are: name
(character string), name of the implication set, lhs
(a dgCMatrix
), initial LHS of the implications stored and the analogous rhs
.
The other way is used to initialize the ImplicationSet
object from a rules
object from package arules
.
[()
Get a subset of the implication set
add()
Add a precomputed implication set
closure()
Compute the semantic closure of a fuzzy set with respect to the implication set
recommend()
Generate a recommendation for a subset of the attributes
apply_rules()
Apply rules to remove redundancies
ImplicationSet$apply_rules(
rules = c("composition", "generalization"),
batch_size = 25000L,
parallelize = FALSE,
reorder = FALSE
)
rules
(character vector) Names of the rules to use. See details
.
batch_size
(integer) If the number of rules is large, apply the rules by batches of this size.
parallelize
(logical) If possible, should we parallelize the computation among different batches?
reorder
(logical) Should the rules be randomly reordered previous to the computation?
print()
Print all implications to text
to_latex()
Export to LaTeX
ImplicationSet$to_latex(
print = TRUE,
ncols = 1,
numbered = TRUE,
numbers = seq(self$cardinality())
)
print
(logical) Print to output?
ncols
(integer) Number of columns for the output.
numbered
(logical) If TRUE
(default), implications will be numbered in the output.
numbers
(vector) If numbered
, use these elements to enumerate the implications. The default is to enumerate 1, 2, ..., but can be changed.
filter()
Filter implications by attributes in LHS and RHS
lhs
(character vector) Names of the attributes to filter the LHS by. If NULL
, no filtering is done on the LHS.
not_lhs
(character vector) Names of the attributes to not include in the LHS. If NULL
(the default), it is not considered at all.
rhs
(character vector) Names of the attributes to filter the RHS by. If NULL
, no filtering is done on the RHS.
not_rhs
(character vector) Names of the attributes to not include in the RHS. If NULL
(the default), it is not considered at all.
drop
(logical) Remove the rest of attributes in RHS?
# Build a formal context
fc_planets <- FormalContext$new(planets)
# Find its implication basis
fc_planets$find_implications()
# Print implications
fc_planets$implications
#> Implication set with 10 implications.
#> Rule 1: {no_moon} -> {small, near}
#> Rule 2: {far} -> {moon}
#> Rule 3: {near} -> {small}
#> Rule 4: {large} -> {far, moon}
#> Rule 5: {medium} -> {far, moon}
#> Rule 6: {medium, large, far, moon} -> {small, near, no_moon}
#> Rule 7: {small, near, moon, no_moon} -> {medium, large, far}
#> Rule 8: {small, near, far, moon} -> {medium, large, no_moon}
#> Rule 9: {small, large, far, moon} -> {medium, near, no_moon}
#> Rule 10: {small, medium, far, moon} -> {large, near, no_moon}
# Cardinality and mean size in the ruleset
fc_planets$implications$cardinality()
#> [1] 10
sizes <- fc_planets$implications$size()
colMeans(sizes)
#> LHS RHS
#> 2.5 2.3
# Simplify the implication set
fc_planets$implications$apply_rules("simplification")
#> Processing batch
#> --> Simplification: from 10 to 10 in 0.05 secs.
#> Batch took 0.053 secs.