fcapy.mvcontext.MVContext
- class fcapy.mvcontext.MVContext(data=None, pattern_types=None, object_names=None, attribute_names=None, **kwargs)
A class used to represent Many Valued Context object from FCA theory.
- __init__(data=None, pattern_types=None, object_names=None, attribute_names=None, **kwargs)
Initialize the MVContext
- Parameters
data (list of list of PatternStructure intents) – The data for MVContext to work with
pattern_types (dict of type {name of an attribute: Pattern Structure type}) – The types of PatternStructure to describe each “column” of the data
object_names (list of str) – The names of objects (default values are [‘0’,’1’,’2’,…]
attribute_names (list of str) – The names of attributes, i.e. pattern structures (default values are [‘0’, ‘1’, ‘2’, …])
kwargs –
- description: str
A human readable description of the context
- target: list of float
A target values to use in Supervised ML scenario
Methods
__init__([data, pattern_types, ...])Initialize the MVContext
assemble_pattern_structures(data, pattern_types)Return pattern_structures based on
dataand thepattern_typesextension(descriptions[, base_objects])Return a subset of objects of
base_objects_iwhich falls intodescriptionsextension_i(descriptions_i[, base_objects_i])Return a subset of objects of
base_objects_iwhich falls intodescriptions_ifrom_pandas(dataframe)Create MVContext from Pandas
dataframegenerators_by_intent_difference(new_intent, ...)Return the set of generators to select the
new_intentfromold_intentget_minimal_generators(intent[, ...])Get a set of minimal generators for closed intent
intentHash value of FormalContext which do not differ between sessions
intention(objects)Return a common description of objects from
objects.intention_i(object_indexes)Return a common description of objects from
object_indexes.leq_descriptions(a, b)Check If description a is 'smaller' (more general) then description b
read_csv([path])Convert the MVContext into csv file format (save if
pathis given)read_json([path, json_data, pattern_types])Read MVContext from .json file .json formatted string data
Return MVContext data in the form of numeric columns and their names
Convert the FormalContext into pandas.DataFrame object
write_json([path])Convert the FormalContext into json file format (save if
pathis given)Attributes
The names of attributes (i.e.
The data for MVContext to work with.
Get or set the human readable description of the context
Get the number of pattern structures (attributes) in the context (i.e.
Get the number of objects in the context (i.e.
The names of objects in the context
A list of pattern structures kept in a context
A dictionary to map the names of attributes (pattern structures) and their types
A list of target values for Supervised ML scenarios
- assemble_pattern_structures(data, pattern_types)
Return pattern_structures based on
dataand thepattern_types
- property attribute_names
The names of attributes (i.e. pattern structures) in the context
- property data
The data for MVContext to work with. List of datas of Pattern Structures of the context
- property description
Get or set the human readable description of the context
JSON is the only file format to store this information. The description will be lost when saving context to .cxt or .csv
- Parameters
value (str, None) – The human readable description of the context
- Raises
AssertionError – If the given
valueis not None and not of type str
- extension(descriptions, base_objects=None)
Return a subset of objects of
base_objects_iwhich falls intodescriptions- Parameters
descriptions (dict of type {pattern_structure_name: description}) – Descriptions to filter objects
base_objects (list of str) – Names of objects to select extension from (default value is the set of all object names)
- Returns
extent_i – A list of names of objects described by
descriptions_i- Return type
list of str
- extension_i(descriptions_i, base_objects_i=None)
Return a subset of objects of
base_objects_iwhich falls intodescriptions_i- Parameters
descriptions_i (dict of type {pattern_structure_index: description}) – Descriptions to filter objects
base_objects_i (list of int) – Indexes of objects to select extension from (default value is the set of all object indexes)
- Returns
extent_i – A list of indexes of objects described by
descriptions_i- Return type
list of int
- static from_pandas(dataframe)
Create MVContext from Pandas
dataframeWARNING: Does not implemented yet
- generators_by_intent_difference(new_intent, old_intent)
Return the set of generators to select the
new_intentfromold_intent
- get_minimal_generators(intent, base_generator=None, base_objects=None, use_indexes=False, ps_to_iterate=None, projection_to_start=1)
Get a set of minimal generators for closed intent
intentWARNING: The current algorithm looks for mimimUM generators instead of mimimAL
- Parameters
intent (dict with PatternStructure intents) – A dict of PatternStructure description to construct generators for.
base_generator (dict with PatternStructure intents) – A dict of PatternStructure descriptions which should be included in each constructed generator
base_objects (list of string or int) – A set of object names (or indexes if
use_indexesset to True) used to check the generatorsuse_indexes (bool) – A flag whether to use object and attribute names (if set to False) or indexes (otherwise)
ps_to_iterate (list of string or int) – A list of pattern structures names (or indexes if
use_indexesset to True) to construct generators onprojection_to_start (int) – A number of PatternStructures projection to construct generators on
- Returns
min_gens – A list of mimimUM generators of a closed
intent- Return type
list of dict of type {pattern_structure_index/name: description}
Notes
An idea of generators for FormalContext is described in the function fcapy.context.formal_context.get_minimal_generators()
- hash_fixed()
Hash value of FormalContext which do not differ between sessions
- intention(objects)
Return a common description of objects from
objects. Pat. structures are denoted by their names
- intention_i(object_indexes)
Return a common description of objects from
object_indexes. Pat. structures are denoted by their indexes
- leq_descriptions(a: dict, b: dict) bool
Check If description a is ‘smaller’ (more general) then description b
- property n_attributes
Get the number of pattern structures (attributes) in the context (i.e. len(
MVContext.pattern_structures))
- property n_objects
Get the number of objects in the context (i.e. len(
MVContext.data))
- property object_names
The names of objects in the context
- property pattern_structures
A list of pattern structures kept in a context
- property pattern_types
A dictionary to map the names of attributes (pattern structures) and their types
- read_csv(path=None, **kwargs)
Convert the MVContext into csv file format (save if
pathis given)WARNING: Does not implemented yet
- Parameters
path (str or None) – Path to save a context
**kwargs –
sepstrField delimiter for the output file
- Returns
context – If
pathis None, the string with .csv file data is returned. Ifpathis given - return None- Return type
str
- static read_json(path: Optional[str] = None, json_data: Optional[str] = None, pattern_types: Optional[Tuple[AbstractPS]] = None)
Read MVContext from .json file .json formatted string data
- Parameters
path (str) – A path to .json file
json_data (str) – A json encoded data
pattern_types (tuple[AbstractPS]) – Tuple of additional Pattern Structures not defined in fcapy.mvcontext.pattern_structure
- Returns
mvK
- Return type
MVContext
- property target
A list of target values for Supervised ML scenarios
- to_numeric()
Return MVContext data in the form of numeric columns and their names
- to_pandas()
Convert the FormalContext into pandas.DataFrame object
WARNING: Does not implemented yet
- Returns
df – The dataframe with boolean variables,
object_namesturned intodf.index,attribute_namesturned intodf.columns- Return type
pandas.DataFrame
- write_json(path=None)
Convert the FormalContext into json file format (save if
pathis given)WARNING: Does not implemented yet
- Parameters
path (str or None) – Path to save a context
- Returns
context – If
pathis None, the string with .json file data is returned. Ifpathis given - return None- Return type
str