API Reference¶
Context¶
-
class
fca.
Context
(data_frame)[source]¶ Implements Formal Context.
Formal context can be understand as triplet \(<A,B,I>\) where A are objects, \(B\) are attributes and \(I\) is relation \(A\) x \(B\). If \(<x1, y2>\) is from \(I\), that means that object x1 has attribute y2.
Parameters: data_frames ( pandas.DataFrame
) – Context is usingpandas.DataFrame
as inner representation of relation \(I\). Thanpandas.Index
are used for \(A\) and \(B\) representation and they are include inpandas.DataFrame
as index and columns. Data should included only True/False values or in can be scaled withpandas.DataFrame.get_dummies()
to multiple columns with 0/1 values.-
data_frame
¶ pandas.DataFrame
– Complete dataset related to formal context.
-
objects
¶ pandas.Index
– All objects from context.
-
attributes
¶ pandas.Index
– All attributes from context.
-
all_attributes
()[source]¶ Return bool numpy array filled by True values. Lenght of this array is equals to number of attribute
-
all_objects
()[source]¶ Return bool numpy array filled by True values. Lenght of this array is equals to number of objects
-
clarificate
()[source]¶ Inplace operation which clarify the context. Clarificated context is context which does not have duplicate columns/rows. Only one of these columns/rows is included.
-
down
(attributes, out=None)[source]¶ Find all objects covered by the attributes.
Parameters: - attributes (
numpy.array
) – Numpy bool array, if index contains True value, attributes with this index is included in selection. - out (
numpy.array
) – If value is None (default) output is outputed to newly allocated array, otherwise provided array is used.
Returns: objects – NumPy array with boolean values representing if object on index is part of the result.
Return type: numpy.array
- attributes (
-
empty_attributes
()[source]¶ Return bool numpy array filled by False values. Lenght of this array is equals to number of attributes
-
empty_objects
()[source]¶ Return bool numpy array filled by False values. Lenght of this array is equals to number of objects
-
up
(objects, out=None)[source]¶ Find all attributes covered by the objects.
Parameters: - objects (
numpy.array
) – Numpy bool array, if index contains True value, objects with this index is included in selection. - out (
numpy.array
) – If value is None (default) output is outputed to newly allocated array, otherwise provided array is used.
Returns: attributes – NumPy array with boolean values representing if attribute on index is part of the result.
Return type: numpy.array
- objects (
-
Concept¶
-
class
fca.
Concept
(extent, intent)[source]¶ Implements Formal Concept.
Formal concept in Context \(c\) is pair \(<A,B>\), where \(A\) is subset of \(X\), \(B\) is subset of \(Y\) such that \(c.up(A) = B\) and \(c.down(B) = A\).
This formal definition is not required, but you have to include extent (objects) and intent (attributes) to create concept.
Parameters: - extent (
numpy.array
) – All object (covered by attributes) in concept, empty list is allowed. Represented asnumpy.array
of bool values. - intent (
numpy.array
) – All attributes (covered by objects) in concept, empty list is allowed. Represented asnumpy.array
of bool values.
-
extent
¶ numpy.array
– All object (covered by attributes) in concept. Represented asnumpy.array
of bool values.
-
intent
¶ numpy.array
– All attributes (covered by objects) in concept. Represented asnumpy.array
of bool values.
- extent (
CloseByOne Algorithm¶
-
class
fca.algorithms.
CloseByOne
[source]¶ Implements algorithm CloseByOne from Sergei O. Kuznetsov
CbO lists all formal concepts by a systematic search in the space of all formal concepts, avoiding to list the same concept multiple times by performing a canonicity test.
(cite: https://www.sciencedirect.com/science/article/pii/S0020025511004804)
More information about the algorithm can be found here: https://link.springer.com/chapter/10.1007/978-3-540-48247-5_47
-
static
generate_concepts
(context)[source]¶ Lists all formal concepts by a systematic search in the space of all formal concepts, avoiding to list the same concept multiple times by performing a canonicity test.
Parameters: context ( fca.Context
) – Context where the concepts should be found.Returns: output – List of concepts. Return type: list
-
static
generate_from
(context, concept, y, n, Yj, intent, output)[source]¶ Recursively descends through the space of formal concepts, beginning with \(<A,B>\).
Parameters: - context (
fca.Context
) – Context where the concepts should be find. - concept (
fca.Concept
) – Initial formal concept. - y – Index of first attribute to be processed.
- n – Number of columns in context.
- Yj – Preallocated
numpy.array
for better performance. - intent – Preallocated intent for better performance.
- output (list) – Output list for formal concepts.
- context (
-
static
FastCloseByOne Algorithm¶
-
class
fca.algorithms.
FastCloseByOne
[source]¶ Implements algorithm FastCloseByOne from Jan Outrata, Vilem Vychodil
FCbO lists all formal concepts by a systematic search in the space of all formal concepts, avoiding to list the same concept multiple times by performing a canonicity test. The algorithm uses set of already computed intents which fails canonicity test.
(cite: https://www.sciencedirect.com/science/article/pii/S0020025511004804)
More information about the algorithm can be found here: https://www.sciencedirect.com/science/article/pii/S0020025511004804
-
static
fast_generate_from
(context, concept, y, n, Yj, Nj, intent, output)[source]¶ Recursively descends through the space of formal concepts, beginning with \(<A,B>\).
Parameters: - context (
fca.Context
) – Context where the concepts should be find. - concept (
fca.Concept
) – Initial formal concept. - y – Index of first attribute to be processed.
- n – Number of columns in context.
- Yj – Preallocated
numpy.array
for better performance. - Nj – Already computed intents which failed the canonical test.
- intent – Preallocated intent for better performance.
- output (list) – Output list for formal concepts.
- context (
-
static
generate_concepts
(context)[source]¶ Lists all formal concepts by a systematic search in the space of all formal concepts, avoiding to list the same concept multiple times by performing a canonicity test.
Parameters: context ( fca.Context
) – Context where the concepts should be found.Returns: output – List of concepts. Return type: list
-
static