ImplicationSet: R6 Class for Set of implications

Description Methods References Examples

Description

This class implements the structure needed to store implications and the methods associated.

Methods

Public methods


Method new()

Initialize with an optional name

Usage
ImplicationSet$new(...)
Arguments
...

See Details.

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.

Returns

A new ImplicationSet object.


Method get_attributes()

Get the names of the attributes

Usage
ImplicationSet$get_attributes()
Returns

A character vector with the names of the attributes used in the implications.


Method [()

Get a subset of the implication set

Usage
ImplicationSet$[(idx)
Arguments
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.

Returns

A new ImplicationSet with only the rules given by the idx indices (if all idx > 0 and all but idx if all idx < 0.


Method to_arules()

Convert to arules format

Usage
ImplicationSet$to_arules(quality = TRUE)
Arguments
quality

(logical) Compute the interest measures for each rule?

Returns

A rules object as used by package arules.


Method add()

Add a precomputed implication set

Usage
ImplicationSet$add(...)
Arguments
...

An ImplicationSet object, a rules object, or a pair lhs, rhs of SparseSet objects or dgCMatrix. The implications to add to this formal context.

Returns

Nothing, just updates the internal implications field.


Method cardinality()

Cardinality: Number of implications in the set

Usage
ImplicationSet$cardinality()
Returns

The cardinality of the implication set.


Method is_empty()

Empty set

Usage
ImplicationSet$is_empty()
Returns

TRUE if the set of implications is empty, FALSE otherwise.


Method size()

Size: number of attributes in each of LHS and RHS

Usage
ImplicationSet$size()
Returns

A vector with two components: the number of attributes present in each of the LHS and RHS of each implication in the set.


Method closure()

Compute the semantic closure of a fuzzy set with respect to the implication set

Usage
ImplicationSet$closure(S, reduce = FALSE, verbose = FALSE)
Arguments
S

(a SparseSet object) Fuzzy set to compute its closure. Use class SparseSet to build it.

reduce

(logical) Reduce the implications using simplification logic?

verbose

(logical) Show verbose output?

Returns

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.


Method recommend()

Generate a recommendation for a subset of the attributes

Usage
ImplicationSet$recommend(S, attribute_filter)
Arguments
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.

Returns

A fuzzy set describing the values of the attributes in attribute_filter within the closure of S.


Method apply_rules()

Apply rules to remove redundancies

Usage
ImplicationSet$apply_rules(
  rules = c("composition", "generalization"),
  batch_size = 25000L,
  parallelize = FALSE,
  reorder = FALSE
)
Arguments
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?

Details

Currently, the implemented rules are "generalization", "simplification", "reduction" and "composition".

Returns

Nothing, just updates the internal matrices for LHS and RHS.


Method to_basis()

Convert Implications to Canonical Basis

Usage
ImplicationSet$to_basis()
Returns

The canonical basis of implications obtained from the current ImplicationSet


Method print()

Print all implications to text

Usage
ImplicationSet$print()
Returns

A string with all the implications in the set.


Method to_latex()

Export to LaTeX

Usage
ImplicationSet$to_latex(
  print = TRUE,
  ncols = 1,
  numbered = TRUE,
  numbers = seq(self$cardinality())
)
Arguments
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.

Returns

A string in LaTeX format that prints nicely all the implications.


Method get_LHS_matrix()

Get internal LHS matrix

Usage
ImplicationSet$get_LHS_matrix()
Returns

A sparse matrix representing the LHS of the implications in the set.


Method get_RHS_matrix()

Get internal RHS matrix

Usage
ImplicationSet$get_RHS_matrix()
Returns

A sparse matrix representing the RHS of the implications in the set.


Method filter()

Filter implications by attributes in LHS and RHS

Usage
ImplicationSet$filter(lhs = NULL, rhs = NULL, drop = FALSE)
Arguments
lhs

(character vector) Names of the attributes to filter the LHS by. If NULL, no filtering is done on the LHS.

rhs

(character vector) Names of the attributes to filter the RHS by. If NULL, no filtering is done on the RHS.

drop

(logical) Remove the rest of attributes in RHS?

Returns

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.


Method support()

Compute support of each implication

Usage
ImplicationSet$support()
Returns

A vector with the support of each implication


Method clone()

The objects of this class are cloneable with this method.

Usage
ImplicationSet$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

References

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.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# 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")

neuroimaginador/fcaR documentation built on Dec. 9, 2020, 5:42 a.m.