:py:mod:`fca.api_models` ======================== .. py:module:: fca.api_models .. autoapi-nested-parse:: Interface with the basic classes to be used in the entire `fca` module. Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: fca.api_models.Context fca.api_models.Lattice fca.api_models.IncLattice .. py:class:: Context(O, A, I, solver: fca.get_lattice.FCASolver = None) Bases: :py:obj:`fca.base_models.Context` The representation of a formal context .. py:method:: __init__(O, A, I, solver: fca.get_lattice.FCASolver = None) :param O: list of object names :type O: List[str] :param A: list of attribute names :type A: List[str] :param I: :type I: List[List[int]]) incidence matrix (`1` and `0` or `True` and `False` work :param solver: the solver that should know how to calculate concepts. :type solver: FCASolver .. py:method:: from_csv(filename, format_name='one_line_per_attribute') :staticmethod: :param filename: a string representing the path pointing to the file :type filename: str :param format_name: one_line_per_attribute | table :type format_name: str :returns: A :class:`Context` .. py:method:: get_concepts() :returns: A List[:class:`Concept`] .. py:method:: get_lattice() :returns: A :class:`Lattice` .. py:method:: get_association_rules(**kwargs) :keyword min_support=0.5: a float between 0 and 1 :kwtype min_support=0.5: float :keyword min_confidence=1: a float between 0 and 1 :kwtype min_confidence=1: float :Yields: association rules with - Base Item - Appended Item - Support - Confidence - Lift see (https://pypi.org/project/apyori/) .. py:method:: generate_association_rules(filename, **kwargs) :keyword filename: a str representing where to save the file. It must be csv :kwtype filename: str :keyword min_support=0.5: a float between 0 and 1 :kwtype min_support=0.5: float :keyword min_confidence=1: a float between 0 and 1 :kwtype min_confidence=1: float :Yields: association rules with - Base Item - Appended Item - Support - Confidence - Lift see (https://pypi.org/project/apyori/) .. py:method:: graduate(relation, p, lattices) Applies graduation. Extends the formal context with more attributes with the relation `relation`, using the p18n operator, against the lattices `lattices` (a list of lattice, lattice_idx) .. py:method:: to_csv(filename: str) Args filename (str): the name of the csv to be created Creates a csv with name `csv` with one row `g,m` for each object `g` having an attribute `m` .. py:class:: Lattice(hasse, concepts, from_iteration=None) Representation of a lattice with all the concepts and the hasse diagram .. py:property:: bottom :type: fca.base_models.Concept .. py:property:: top :type: fca.base_models.Concept .. py:property:: inverted_hasse The inverse of the hasse digraph .. py:property:: concepts .. py:method:: __init__(hasse, concepts, from_iteration=None) .. py:method:: isomorph(other_lattice) This method needs the two lattices to have the concepts ordered in the same way, othetwise it'll fail - Complexity: `O(|self.concepts|), \omega(1)` .. py:method:: get_concept(i) .. py:method:: plot(**kwargs) :keyword show_plot: Whether to show the plot or not. :kwtype show_plot: bool :keyword save_plot: The path where to save the plot. If None, the plot wont be saved. :kwtype save_plot: str :keyword ax: to reuse axes from another plot. :kwtype ax: Axes | List[Axes] :keyword fig: the figure where to draw the plot. :kwtype fig: Figure :keyword print_latex: Whether to print the latex code of the plot in the standard output :kwtype print_latex: bool :keyword instance is destructed.: :returns: (fig, ax, diameter) .. py:method:: graph_str_repr() String representation of the graph .. py:class:: IncLattice(ctx_or_attributes: Optional[Union[List[str], Context]] = None) Incremenal Lattice that can receive objects on the fly. Its purpose is to be able to receive objects and update only the minimal parts of it each update takes `O(|G|²|M||L|)` where L is the Lattice we have so far, and G are the objects so far. .. py:property:: concepts .. py:property:: hasse .. py:property:: bottom .. py:property:: top .. py:method:: __init__(ctx_or_attributes: Optional[Union[List[str], Context]] = None) :param ctx_or_attributes: The list of attributes the Lattice will have or a Context. :type ctx_or_attributes: List[str] | Context .. admonition:: Example .. code-block:: python L1 = IncLattice() L2 = IncLattice(['a', 'b', 'c']) L3 = IncLattice(Context(['1', '2'], ['a', 'b', 'c'], [[1, 0, 0], [0, 1, 1]])) .. py:method:: copy(l) :staticmethod: .. py:method:: isomorph(other_lattice) This method needs the two lattices to have the concepts ordered in the same way, othetwise it'll fail - Complexity: `O(|self.concepts|), \omega(1)` .. py:method:: merge_concepts(other) .. py:method:: add_intent(object_name: str, intent: List[int]) :param object_name: the name of the object being added. :type object_name: str :param intent: The list of attribute indices the object has. :type intent: List[int] .. admonition:: Example .. code-block:: python L.add_intent('o1', [1, 3, 6]) .. py:method:: delete_instance(object_name: str) :param object_name: the name of an object to be deleted. :type object_name: str .. admonition:: Example .. code-block:: python L.delete_instance('o1') .. py:method:: add_attribute(attr_name: str) .. py:method:: add_object(object_name: str) .. py:method:: add_pair(object_name: str, attr_name: str) :param object_name: the name of an object. :type object_name: str :param attr_name: the name of an attribute corresponding to that object. :type attr_name: str .. admonition:: Example .. code-block:: python L.add_pair('o1', 'a2') .. py:method:: get_concept(i: int) -> fca_algorithms_cpp.ConceptCpp :param i: index of the concept to be returned :type i: int :returns: :class:`ConceptCpp` in `i`-th position .. py:method:: plot(**kwargs) :keyword show_plot: Whether to show the plot or not. :kwtype show_plot: bool :keyword save_plot: The path where to save the plot. If None, the plot wont be saved. :kwtype save_plot: str :keyword ax: to reuse axes from another plot. :kwtype ax: Axes | List[Axes] :keyword fig: the figure where to draw the plot. :kwtype fig: Figure :keyword print_latex: Whether to print the latex code of the plot in the standard output :kwtype print_latex: bool :keyword instance is destructed.: :returns: (fig, ax, diameter)