ImplicationSet | R Documentation |
This class implements the structure needed to store implications and the methods associated.
new()
Initialize with an optional name
ImplicationSet$new(...)
...
See Details.
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
.
A new ImplicationSet
object.
get_attributes()
Get the names of the attributes
ImplicationSet$get_attributes()
A character vector with the names of the attributes used in the implications.
[()
Get a subset of the implication set
ImplicationSet$[(idx)
idx
(integer or logical vector) Indices of the implications to extract or remove. If logical vector, only TRUE
elements are retained and the rest discarded.
A new ImplicationSet
with only the rules given by the idx
indices (if all idx > 0
and all but idx
if all idx < 0
.
to_arules()
Convert to arules format
ImplicationSet$to_arules(quality = TRUE)
quality
(logical) Compute the interest measures for each rule?
A rules
object as used by package arules
.
add()
Add a precomputed implication set
ImplicationSet$add(...)
...
An ImplicationSet
object, a rules
object, or a pair lhs
, rhs
of Set
objects or dgCMatrix
. The implications to add to this formal context.
Nothing, just updates the internal implications
field.
cardinality()
Cardinality: Number of implications in the set
ImplicationSet$cardinality()
The cardinality of the implication set.
is_empty()
Empty set
ImplicationSet$is_empty()
TRUE
if the set of implications is empty, FALSE
otherwise.
size()
Size: number of attributes in each of LHS and RHS
ImplicationSet$size()
A vector with two components: the number of attributes present in each of the LHS and RHS of each implication in the set.
closure()
Compute the semantic closure of a fuzzy set with respect to the implication set
ImplicationSet$closure(S, reduce = FALSE, verbose = FALSE)
S
(a Set
object) Fuzzy set to compute its closure. Use class Set
to build it.
reduce
(logical) Reduce the implications using simplification logic?
verbose
(logical) Show verbose output?
If reduce == FALSE
, the output is a fuzzy set corresponding to the closure of S
. If reduce == TRUE
, a list with two components: closure
, with the closure as above, and implications
, the reduced set of implications.
recommend()
Generate a recommendation for a subset of the attributes
ImplicationSet$recommend(S, attribute_filter)
S
(a vector) Vector with the grades of each attribute (a fuzzy set).
attribute_filter
(character vector) Names of the attributes to get recommendation for.
A fuzzy set describing the values of the attributes in attribute_filter
within the closure of S
.
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?
Currently, the implemented rules are "generalization"
, "simplification"
, "reduction"
and "composition"
.
Nothing, just updates the internal matrices for LHS and RHS.
to_basis()
Convert Implications to Canonical Basis
ImplicationSet$to_basis()
The canonical basis of implications obtained from the current ImplicationSet
print()
Print all implications to text
ImplicationSet$print()
A string with all the implications in the set.
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.
A string in LaTeX format that prints nicely all the implications.
get_LHS_matrix()
Get internal LHS matrix
ImplicationSet$get_LHS_matrix()
A sparse matrix representing the LHS of the implications in the set.
get_RHS_matrix()
Get internal RHS matrix
ImplicationSet$get_RHS_matrix()
A sparse matrix representing the RHS of the implications in the set.
filter()
Filter implications by attributes in LHS and RHS
ImplicationSet$filter( lhs = NULL, not_lhs = NULL, rhs = NULL, not_rhs = NULL, drop = FALSE )
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?
An ImplicationSet
that is a subset of the current set, only with those rules which has the attributes in lhs
and rhs
in their LHS and RHS, respectively.
support()
Compute support of each implication
ImplicationSet$support()
A vector with the support of each implication
clone()
The objects of this class are cloneable with this method.
ImplicationSet$clone(deep = FALSE)
deep
Whether to make a deep clone.
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.
# Build a formal context
fc_planets <- FormalContext$new(planets)
# Find its implication basis
fc_planets$find_implications()
# Print implications
fc_planets$implications
# Cardinality and mean size in the ruleset
fc_planets$implications$cardinality()
sizes <- fc_planets$implications$size()
colMeans(sizes)
# Simplify the implication set
fc_planets$implications$apply_rules("simplification")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.