fcapy.algorithms.lattice_construction¶
This module contains a number of function which take a set of formal (or pattern) concepts and return its subconcepts_dict i.e. the order of given concepts in the form {parent_concept_index: child_concept_index}.
Parent_concept is a concept which is bigger (or more general) than the child concept and there is no other concept between these two.
Functions
|
Add |
|
Return a dict with subconcepts relation on given |
|
Return a dict with subconcepts relation on given |
Return a dict with subconcepts relation on given concepts from given spanning tree of the relation. |
|
Return a dict with subconcepts relation on given |
|
|
Return a spanning tree of subconcepts relation on given |
|
Remove a |
-
fcapy.algorithms.lattice_construction.add_concept(new_concept, concepts, subconcepts_dict, superconcepts_dict, top_concept_i=None, bottom_concept_i=None, inplace=True)¶ Add
new_conceptinto a set ofconceptsregarding its subconcept relation- Parameters
new_concept (FormalConcept or PatternConcept) – A concept to add
concepts (list of FormalConcept or PatternConcept) – A list of concepts to add a
new_concepttosubconcepts_dict (dict of {int: int}) – A dict of the current subconcept relation of the
conceptssuperconcepts_dict (dict of {int: int}) – A dict of the current superconcept relation of the
conceptstop_concept_i (int) – An index of the top (biggest) concept from
conceptsbottom_concept_i (int) – An index of the bottom (smallest) concept from
conceptsinplace (bool) – A flag whether to modify the
conceptslist inplace or create a new one
- Returns
concepts (list of FormalConcept or PatternConcept) – A modified list of concepts
subconcepts_dict (dict of {int: int}) – A dict of modified subconcept relation of returned
conceptssuperconcepts_dict (dict of {int: int}) – A dict of modified superconcept relation of returned
conceptstop_concept_i (int) – An index of the top (biggest) concept of returned
conceptsbottom_concept_i (int) – An index of the bottom (smallest) concept of returned
concepts
-
fcapy.algorithms.lattice_construction.complete_comparison(concepts, is_concepts_sorted=False, n_jobs=1, use_tqdm=False)¶ Return a dict with subconcepts relation on given
concepts. A slow but accurate bruteforce method- Parameters
concepts (list of FormalConcept or PatternConcept) – A list of concepts to compare
is_concepts_sorted (bool) – A flag whether the set of concepts is topologically sorted or it should be sorted inside the function
n_jobs (int) – A number of parallel jobs to run. WARNING: It is more efficient to run just one job for some reason
use_tqdm (bool) – A flag whether to visualize the progress of the algorithm with tqdm bar or not
- Returns
subconcepts_dict – A dict of indexes with subconcept relation on the given concepts (of type {parent_concept_index: child_concept_index})
- Return type
dict
-
fcapy.algorithms.lattice_construction.construct_lattice_by_spanning_tree(concepts, is_concepts_sorted=False, n_jobs=1, use_tqdm=False)¶ Return a dict with subconcepts relation on given
concepts. Uses spanning tree approach to fasten the computation- Parameters
concepts (list of FormalConcept or PatternConcept) – A list of concepts to compare
is_concepts_sorted (bool) – A flag whether the set of concepts is topologically sorted or it should be sorted inside the function
n_jobs (int) – A number of parallel jobs to run. WARNING: It is more efficient to run just one job for some reason
use_tqdm (bool) – A flag whether to visualize the progress of the algorithm with tqdm bar or not
- Returns
subconcepts_dict – A dict of indexes with subconcept relation on the given concepts (of type {parent_concept_index: child_concept_index})
- Return type
dict
-
fcapy.algorithms.lattice_construction.construct_lattice_from_spanning_tree(concepts, sptree_chains, is_concepts_sorted=False, use_tqdm=False)¶ Return a dict with subconcepts relation on given concepts from given spanning tree of the relation.
- Parameters
concepts (list of FormalConcept or PatternConcept) – A list of concepts to compare
sptree_chains (list of list of int) – A list of chains of a spanning tree of concepts subconcept relation. Can be constructed with ConceptLattice._get_chains(…) method
is_concepts_sorted (boot) – A flag whether the set of concepts is topologically sorted or it should be sorted inside the function
use_tqdm (bool) – A flag whether to visualize the progress of the algorithm with tqdm bar or not
- Returns
subconcepts_dict – A dict of indexes with subconcept relation on the given concepts (of type {parent_concept_index: child_concept_index})
- Return type
dict
-
fcapy.algorithms.lattice_construction.construct_lattice_from_spanning_tree_parallel(concepts, sptree_chains, is_concepts_sorted=False, n_jobs=1)¶ Return a dict with subconcepts relation on given
conceptsfrom given spanning tree of the relation.WARNING: This parallelized function works slower than the original
construct_lattice_from_spanning_treefunction.- Parameters
concepts (list of FormalConcept or PatternConcept) – A list of concepts to compare
sptree_chains (list of list of int) – A list of chains of a spanning tree of concepts subconcept relation. Can be constructed with
ConceptLattice._get_chains(...)methodis_concepts_sorted (boot) – A flag whether the set of concepts is topologically sorted or it should be sorted inside the function
n_jobs (int) – A number of parallel jobs to run.
- Returns
subconcepts_dict – A dict of indexes with subconcept relation on the given concepts (of type {parent_concept_index: child_concept_index})
- Return type
dict
-
fcapy.algorithms.lattice_construction.construct_spanning_tree(concepts, is_concepts_sorted=False, use_tqdm=False)¶ Return a spanning tree of subconcepts relation on given
concepts.A spanning tree means that for each concept from
conceptswe look for one parent concept only (even if there are actually many of them)- Parameters
concepts (list of FormalConcept or PatternConcept) – A list of concepts to compare
is_concepts_sorted (boot) – A flag whether the set of concepts is topologically sorted or it should be sorted inside the function
use_tqdm (bool) – A flag whether to visualize the progress of the algorithm with tqdm bar or not
- Returns
subconcepts_dict – A dict of indexes with spanning tree of subconcept relation on the given
concepts(of type {parent_concept_index: child_concept_index})- Return type
dict
-
fcapy.algorithms.lattice_construction.remove_concept(concept_i, concepts, subconcepts_dict, superconcepts_dict, top_concept_i=None, bottom_concept_i=None, inplace=True)¶ Remove a
concept_ifrom a set ofconceptsregarding its subconcept relation- Parameters
concept_i (int) – An index of concept to be removed
concepts (list of FormalConcept or PatternConcept) – A list of concepts to remove a
concept_ifromsubconcepts_dict (dict of {int: int}) – A dict of the current subconcept relation of the
conceptssuperconcepts_dict (dict of {int: int}) – A dict of the current superconcept relation of the
conceptstop_concept_i (int) – An index of the top (biggest) concept from
conceptsbottom_concept_i (int) – An index of the bottom (smallest) concept from
conceptsinplace (bool) – A flag whether to modify the
conceptslist inplace or create a new one
- Returns
concepts (list of FormalConcept or PatternConcept) – A modified list of concepts
subconcepts_dict (dict of {int: int}) – A dict of modified subconcept relation of returned
conceptssuperconcepts_dict (dict of {int: int}) – A dict of modified superconcept relation of returned
conceptstop_concept_i (int) – An index of the top (biggest) concept of returned
conceptsbottom_concept_i (int) – An index of the bottom (smallest) concept of returned
concepts