FormalContext: R6 class for a formal context

Description Public fields Methods References Examples

Description

This class implements the data structure and methods for formal contexts.

Public fields

Methods

Public methods


Method new()

Creator for the Formal Context class

Usage
FormalContext$new(I, remove_const = FALSE)
Arguments
I

(numeric matrix) The table of the formal context.

remove_const

(logical) If TRUE, remove constant columns. The default is FALSE.

Details

Columns of I should be named, since they are the names of the attributes of the formal context.

If no I is used, the resulting FormalContext will be empty and not usable unless for loading a previously saved one.

Returns

An object of the FormalContext class.


Method is_empty()

Check if the FormalContext is empty

Usage
FormalContext$is_empty()
Returns

TRUE if the FormalContext is empty, that is, has not been provided with a matrix, and FALSE otherwise.


Method intent()

Get the intent of a fuzzy set of objects

Usage
FormalContext$intent(S)
Arguments
S

(SparseSet) The set of objects to compute the intent for.

Returns

A SparseSet with the intent.


Method extent()

Get the extent of a fuzzy set of attributes

Usage
FormalContext$extent(S)
Arguments
S

(SparseSet) The set of attributes to compute the extent for.

Returns

A SparseSet with the intent.


Method closure()

Get the closure of a fuzzy set of attributes

Usage
FormalContext$closure(S)
Arguments
S

(SparseSet) The set of attributes to compute the closure for.

Returns

A SparseSet with the closure.


Method obj_concept()

Object Concept

Usage
FormalContext$obj_concept(object)
Arguments
object

(character) Name of the object to compute its associated concept

Returns

The object concept associated to the object given.


Method att_concept()

Attribute Concept

Usage
FormalContext$att_concept(attribute)
Arguments
attribute

(character) Name of the attribute to compute its associated concept

Returns

The attribute concept associated to the attribute given.


Method is_concept()

Is a Concept?

Usage
FormalContext$is_concept(C)
Arguments
C

A SparseConcept object

Returns

TRUE if C is a concept.


Method is_closed()

Testing closure of attribute sets

Usage
FormalContext$is_closed(S)
Arguments
S

A SparseSet of attributes

Returns

TRUE if the set S is closed in this formal context.


Method clarify()

Clarify a formal context

Usage
FormalContext$clarify(copy = FALSE)
Arguments
copy

(logical) If TRUE, a new FormalContext object is created with the clarified context, otherwise the current one is overwritten.

Returns

The clarified FormalContext.


Method reduce()

Reduce a formal context

Usage
FormalContext$reduce(copy = FALSE)
Arguments
copy

(logical) If TRUE, a new FormalContext object is created with the clarified and reduced context, otherwise the current one is overwritten.

Returns

The clarified and reduced FormalContext.


Method standardize()

Build the Standard Context

Usage
FormalContext$standardize()
Details

All concepts must be previously computed.

Returns

The standard context using the join- and meet- irreducible elements.


Method find_concepts()

Use Ganter Algorithm to compute concepts

Usage
FormalContext$find_concepts(verbose = FALSE)
Arguments
verbose

(logical) TRUE will provide a verbose output.

Returns

A list with all the concepts in the formal context.


Method find_implications()

Use modified Ganter algorithm to compute both concepts and implications

Usage
FormalContext$find_implications(save_concepts = TRUE, verbose = FALSE)
Arguments
save_concepts

(logical) TRUE will also compute and save the concept lattice. FALSE is usually faster, since it only computes implications.

verbose

(logical) TRUE will provide a verbose output.

Returns

Nothing, just updates the internal fields concepts and implications.


Method to_transactions()

Convert the formal context to object of class transactions from the arules package

Usage
FormalContext$to_transactions()
Returns

A transactions object.


Method save()

Save a FormalContext to RDS format

Usage
FormalContext$save(filename = tempfile(fileext = ".rds"))
Arguments
filename

(character) Path of the RDS file where to store the FormalContext.

Returns

Invisibly the current FormalContext.


Method load()

Load a FormalContext from a RDS file

Usage
FormalContext$load(filename)
Arguments
filename

(character) Path of the RDS file to load the FormalContext from.

Returns

The loaded FormalContext.


Method dim()

Dimensions of the formal context

Usage
FormalContext$dim()
Returns

A vector with (number of objects, number of attributes).


Method print()

Prints the formal context

Usage
FormalContext$print()
Returns

Prints information regarding the formal context.


Method to_latex()

Write the context in LaTeX format

Usage
FormalContext$to_latex(
  label = "",
  caption = "",
  fraction = c("none", "frac", "dfrac", "sfrac")
)
Arguments
label

(character) The label for the table environment.

caption

(character) The caption of the table.

fraction

(character) If none, no fractions are produced. Otherwise, if it is frac, dfrac or sfrac, decimal numbers are represented as fractions with the corresponding LaTeX typesetting.

Returns

A table environment in LaTeX.


Method plot()

Plot the formal context table

Usage
FormalContext$plot(to_latex = FALSE, ...)
Arguments
to_latex

(logical) If TRUE, export the plot as a tikzpicture environment that can be included in a LaTeX file.

...

Other parameters to be passed to the tikzDevice that renders the lattice in LaTeX, or for the figure caption. See Details.

Details

Particular parameters that control the size of the tikz output are: width, height (both in inches), and pointsize (in points), that should be set to the font size used in the documentclass header in the LaTeX file where the code is to be inserted.

If a caption is provided, the whole tikz picture will be wrapped by a figure environment and the caption set.

Returns

If to_latex is FALSE, it returns nothing, just plots the graph of the formal context. Otherwise, this function returns the LaTeX code to reproduce the formal context plot.


Method clone()

The objects of this class are cloneable with this method.

Usage
FormalContext$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

References

Guigues J, Duquenne V (1986). “Familles minimales d'implications informatives résultant d'un tableau de données binaires.” Mathématiques et Sciences humaines, 95, 5-18.

Ganter B, Wille R (1999). Formal concept analysis : mathematical foundations. Springer. ISBN 3540627715.

Belohlavek R (2002). “Algorithms for fuzzy concept lattices.” In Proc. Fourth Int. Conf. on Recent Advances in Soft Computing. Nottingham, United Kingdom, 200-205.

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.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# Build and print the formal context
fc_planets <- FormalContext$new(planets)
print(fc_planets)

# Define a set of attributes
S <- SparseSet$new(attributes = fc_planets$attributes)
S$assign(moon = 1, large = 1)

# Compute the closure of S
Sc <- fc_planets$closure(S)
# Is Sc a closed set?
fc_planets$is_closed(Sc)

# Clarify and reduce the formal context
fc2 <- fc_planets$reduce(TRUE)

# Find implications
fc_planets$find_implications()

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