FormalContext | R Documentation |
This class implements the data structure and methods for formal contexts.
I
The table of the formal context as a matrix.
attributes
The attributes of the formal context.
objects
The objects of the formal context.
grades_set
The set of degrees (in [0, 1]) the whole set of attributes can take.
expanded_grades_set
The set of degrees (in [0, 1]) each attribute can take.
concepts
The concept lattice associated to the formal context as a ConceptLattice
.
implications
A set of implications on the formal context as an ImplicationSet
.
new()
Creator for the Formal Context class
FormalContext$new(I, filename, remove_const = FALSE)
I
(numeric matrix) The table of the formal context.
filename
(character) Path of a file to import.
remove_const
(logical) If TRUE
, remove constant columns. The default is FALSE
.
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. In this case, one can provide a filename
to import. Only RDS, CSV and CXT files are currently supported.
An object of the FormalContext
class.
is_empty()
Check if the FormalContext
is empty
FormalContext$is_empty()
TRUE
if the FormalContext
is empty, that is, has not been provided with a matrix, and FALSE
otherwise.
scale()
Scale the context
FormalContext$scale(attributes, type, ...)
attributes
The attributes to scale
type
Type of scaling.
...
The types of scaling are implemented in a registry,
so that scalingRegistry$get_entries()
returns
all types.
In the dots argument, the user can supply the value for bg
(logical), which, if set to TRUE
, indicates to compute background knowledge as implications on the scales; if FALSE
, no implications will be computed on the scales.
The scaled formal context
filename <- system.file("contexts", "aromatic.csv", package = "fcaR") fc <- FormalContext$new(filename) fc$scale("nitro", "ordinal", comparison = `>=`, values = 1:3) fc$scale("OS", "nominal", c("O", "S")) fc$scale(attributes = "ring", type = "nominal")
get_scales()
Scales applied to the formal context
FormalContext$get_scales(attributes = names(private$scales))
attributes
(character) Name of the attributes for which scales (if applied) are returned.
The scales that have been applied to the specified attributes
of the formal context. If no attributes
are passed,
then all applied scales are returned.
filename <- system.file("contexts", "aromatic.csv", package = "fcaR") fc <- FormalContext$new(filename) fc$scale("nitro", "ordinal", comparison = `>=`, values = 1:3) fc$scale("OS", "nominal", c("O", "S")) fc$scale(attributes = "ring", type = "nominal") fc$get_scales()
background_knowledge()
Background knowledge of a scaled formal context
FormalContext$background_knowledge()
An ImplicationSet
with the implications
extracted from the application of scales.
filename <- system.file("contexts", "aromatic.csv", package = "fcaR") fc <- FormalContext$new(filename) fc$scale("nitro", "ordinal", comparison = `>=`, values = 1:3) fc$scale("OS", "nominal", c("O", "S")) fc$scale(attributes = "ring", type = "nominal") fc$background_knowledge()
dual()
Get the dual formal context
FormalContext$dual()
A FormalContext
where objects and attributes have interchanged their roles.
intent()
Get the intent of a fuzzy set of objects
FormalContext$intent(S)
S
(Set
) The set of objects to compute the intent for.
A Set
with the intent.
uparrow()
Get the intent of a fuzzy set of objects
FormalContext$uparrow(S)
S
(Set
) The set of objects to compute the intent for.
A Set
with the intent.
extent()
Get the extent of a fuzzy set of attributes
FormalContext$extent(S)
S
(Set
) The set of attributes to compute the extent for.
A Set
with the intent.
downarrow()
Get the extent of a fuzzy set of attributes
FormalContext$downarrow(S)
S
(Set
) The set of attributes to compute the extent for.
A Set
with the intent.
closure()
Get the closure of a fuzzy set of attributes
FormalContext$closure(S)
S
(Set
) The set of attributes to compute the closure for.
A Set
with the closure.
obj_concept()
Object Concept
FormalContext$obj_concept(object)
object
(character) Name of the object to compute its associated concept
The object concept associated to the object given.
att_concept()
Attribute Concept
FormalContext$att_concept(attribute)
attribute
(character) Name of the attribute to compute its associated concept
The attribute concept associated to the attribute given.
is_concept()
Is a Concept?
FormalContext$is_concept(C)
C
A Concept
object
TRUE
if C
is a concept.
is_closed()
Testing closure of attribute sets
FormalContext$is_closed(S)
S
A Set
of attributes
TRUE
if the set S
is closed in this formal context.
clarify()
Clarify a formal context
FormalContext$clarify(copy = FALSE)
copy
(logical) If TRUE
, a new FormalContext
object is created with the clarified context, otherwise the current one is overwritten.
The clarified FormalContext
.
reduce()
Reduce a formal context
FormalContext$reduce(copy = FALSE)
copy
(logical) If TRUE
, a new FormalContext
object is created with the clarified and reduced context, otherwise the current one is overwritten.
The clarified and reduced FormalContext
.
standardize()
Build the Standard Context
FormalContext$standardize()
All concepts must be previously computed.
The standard context using the join- and meet- irreducible elements.
find_concepts()
Use Ganter Algorithm to compute concepts
FormalContext$find_concepts(verbose = FALSE)
verbose
(logical) TRUE will provide a verbose output.
A list with all the concepts in the formal context.
find_implications()
Use modified Ganter algorithm to compute both concepts and implications
FormalContext$find_implications(save_concepts = TRUE, verbose = FALSE)
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.
Nothing, just updates the internal fields concepts
and implications
.
to_transactions()
Convert the formal context to object of class transactions
from the arules
package
FormalContext$to_transactions()
A transactions
object.
save()
Save a FormalContext
to RDS or CXT format
FormalContext$save(filename = tempfile(fileext = ".rds"))
filename
(character) Path of the file where to store the FormalContext
.
The format is inferred from the extension of the filename.
Invisibly the current FormalContext
.
load()
Load a FormalContext
from a file
FormalContext$load(filename)
filename
(character) Path of the file to load the FormalContext
from.
Currently, only RDS, CSV and CXT files are supported.
The loaded FormalContext
.
dim()
Dimensions of the formal context
FormalContext$dim()
A vector with (number of objects, number of attributes).
print()
Prints the formal context
FormalContext$print()
Prints information regarding the formal context.
to_latex()
Write the context in LaTeX format
FormalContext$to_latex(table = TRUE, label = "", caption = "")
table
(logical) If TRUE
, surrounds everything between \begin{table}
and \end{table}
.
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.
A table environment in LaTeX.
incidence()
Incidence matrix of the formal context
FormalContext$incidence()
The incidence matrix of the formal context
fc <- FormalContext$new(planets) fc$incidence()
subcontext()
Subcontext of the formal context
FormalContext$subcontext(objects, attributes)
objects
(character array) Name of the objects to keep.
attributes
(character array) Names of the attributes to keep.
A warning will be issued if any of the names is not present in the list of objects or attributes of the formal context.
If objects
or attributes
is empty, then it is
assumed to represent the whole set of objects or attributes
of the original formal context.
Another FormalContext
that is a subcontext
of the original one, with only the objects and attributes
selected.
fc <- FormalContext$new(planets) fc$subcontext(attributes = c("moon", "no_moon"))
[()
Subcontext of the formal context
FormalContext$[(objects, attributes)
objects
(character array) Name of the objects to keep.
attributes
(character array) Names of the attributes to keep.
A warning will be issued if any of the names is not present in the list of objects or attributes of the formal context.
If objects
or attributes
is empty, then it is
assumed to represent the whole set of objects or attributes
of the original formal context.
Another FormalContext
that is a subcontext
of the original one, with only the objects and attributes
selected.
fc <- FormalContext$new(planets) fc[, c("moon", "no_moon")]
plot()
Plot the formal context table
FormalContext$plot(to_latex = FALSE, ...)
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
.
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.
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.
use_logic()
Sets the logic to use
FormalContext$use_logic(name = available_logics())
name
The name of the logic to use. To see the available names, run available_logics()
.
get_logic()
Gets the logic used
FormalContext$get_logic()
A string with the name of the logic.
use_connection()
Sets the name of the Galois connection to use
FormalContext$use_connection(connection)
connection
The name of the Galois connection. Available connections are "standard" (antitone), "benevolent1" and "benevolent2" (isotone)
get_connection()
Gets the name of the Galois connection
FormalContext$get_connection()
A string with the name of the Galois connection
clone()
The objects of this class are cloneable with this method.
FormalContext$clone(deep = FALSE)
deep
Whether to make a deep clone.
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.
# Build and print the formal context
fc_planets <- FormalContext$new(planets)
print(fc_planets)
# Define a set of attributes
S <- Set$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()
# Read a formal context from CSV
filename <- system.file("contexts", "airlines.csv", package = "fcaR")
fc <- FormalContext$new(filename)
# Read a formal context from a CXT file
filename <- system.file("contexts", "lives_in_water.cxt", package = "fcaR")
fc <- FormalContext$new(filename)
## ------------------------------------------------
## Method `FormalContext$scale`
## ------------------------------------------------
filename <- system.file("contexts", "aromatic.csv", package = "fcaR")
fc <- FormalContext$new(filename)
fc$scale("nitro", "ordinal", comparison = `>=`, values = 1:3)
fc$scale("OS", "nominal", c("O", "S"))
fc$scale(attributes = "ring", type = "nominal")
## ------------------------------------------------
## Method `FormalContext$get_scales`
## ------------------------------------------------
filename <- system.file("contexts", "aromatic.csv", package = "fcaR")
fc <- FormalContext$new(filename)
fc$scale("nitro", "ordinal", comparison = `>=`, values = 1:3)
fc$scale("OS", "nominal", c("O", "S"))
fc$scale(attributes = "ring", type = "nominal")
fc$get_scales()
## ------------------------------------------------
## Method `FormalContext$background_knowledge`
## ------------------------------------------------
filename <- system.file("contexts", "aromatic.csv", package = "fcaR")
fc <- FormalContext$new(filename)
fc$scale("nitro", "ordinal", comparison = `>=`, values = 1:3)
fc$scale("OS", "nominal", c("O", "S"))
fc$scale(attributes = "ring", type = "nominal")
fc$background_knowledge()
## ------------------------------------------------
## Method `FormalContext$incidence`
## ------------------------------------------------
fc <- FormalContext$new(planets)
fc$incidence()
## ------------------------------------------------
## Method `FormalContext$subcontext`
## ------------------------------------------------
fc <- FormalContext$new(planets)
fc$subcontext(attributes = c("moon", "no_moon"))
## ------------------------------------------------
## Method `FormalContext$[`
## ------------------------------------------------
fc <- FormalContext$new(planets)
fc[, c("moon", "no_moon")]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.