soft.fuzzy.temporal.association package
Submodules
soft.fuzzy.temporal.association.ftarm module
Implements the Fuzzy Temporal Association Rule Mining algorithm and its necessary helper functions.
- class soft.fuzzy.temporal.association.ftarm.AssociationRule(antecedents, consequents, confidence)
Bases:
tuple
- antecedents
Alias for field number 0
- confidence
Alias for field number 2
- consequents
Alias for field number 1
- class soft.fuzzy.temporal.association.ftarm.FuzzyTemporalAssocationRuleMining(dataframe: DataFrame, knowledge_base: KnowledgeBase, config: Config)
Bases:
object
Implements the fuzzy temporal association rule mining (FTARM) algorithm.
- calc_confidence(node: tuple, predecessors: list) Tensor
Calculate the fuzzy temporal confidence.
- Parameters:
node – A node, representing an itemset(s) of interest.
predecessors – The predecessors of the itemset(s) (node).
- Returns:
Fuzzy temporal confidences.
- find_antecedents(node: tuple, predecessors: list) list
Find the antecedents’ confidence and return only those with confidences greater than the minimum confidence threshold. :param node: A frequent itemset. :param predecessors: The predecessors to that frequent itemset.
- Returns:
A list of the antecedents, where each element is a 2-tuple of an antecedent with its corresponding confidence.
- find_association_rules() set
Must be run after .find_candidates(), as it searches the saved lattice structure to produce the fuzzy temporal association rules.
- Returns:
A set of association rules, where each element is an association rule.
- find_candidates(candidates: list | None = None) list
Executes the FTARM algorithm to produce the frequent temporal itemsets.
- Parameters:
candidates – A list of candidates to start the FTARM algorithm from; default is ‘None’.
- Returns:
(nested list) A list of frequent temporal itemsets where the 0’th candidates family item are the 2-itemsets, the 1’th candidates family item are the 3-itemsets, etc.
- find_closed_itemsets() set
Must be run after .find_candidates(), as it searches the saved lattice structure to produce the fuzzy temporal association rules.
- Returns:
A set of closed itemsets, where each element is a closed itemset. An itemset is closed if none of its immediate supersets has the same support as the itemset.
- find_maximal_itemsets() set
Must be run after .find_candidates(), as it searches the saved lattice structure to produce the fuzzy temporal association rules.
- Returns:
A set of maximal itemsets, where each element is a maximal itemset. An itemset is maximal if none of its immediate supersets are frequent.
- frequent_temporal_items(supports: Tensor) Tuple[list, Tensor]
Keep only the supports of the frequent 1-itemsets.
- fuzzy_representation(candidates: list | None = None, starting_period: int | None = None) Tensor
Generate the ‘fuzzy representations’ for each transaction that is currently relevant (i.e., >= starting_period).
- Parameters:
candidates – The candidate itemsets.
starting_period – The starting period to begin counting transactions from.
- Returns:
The fuzzy representations of each transaction in the database that occurs at or after the given starting_period.
- fuzzy_temporal_supports(candidates: list | None = None, starting_period: int | None = None) Tensor
Calculate the fuzzy temporal supports of the candidates, given the possible restriction of starting_period (None means no restriction aka the earliest transaction is fine).
- Parameters:
candidates – The candidate itemsets.
starting_period – The starting period to begin counting transactions from.
- Returns:
PyTorch tensor.
- generate_candidates_of_length_two(supports: Tensor) list
Generate the candidate itemsets from the given fuzzy temporal supports of the itemsets.
- Parameters:
supports – The fuzzy temporal supports of the itemsets.
- Returns:
The generated candidates.
- generate_superset_itemsets(frequent_itemsets: list, max_len_of_itemsets: int) set
Generate the superset itemsets of the frequent itemsets.
- Parameters:
frequent_itemsets – The frequent itemsets.
max_len_of_itemsets – The maximum length of the itemsets.
- Returns:
The superset itemsets.
- make_candidates(candidates: list | None = None) list | None
Make the candidate itemsets.
- Parameters:
candidates – Any existing candidate itemsets.
- Returns:
The generated candidates.
- scalar_cardinality(candidates: list | None = None, starting_period: int | None = None) Tensor
The scalar cardinality, or ‘count’ is the summation of the membership degrees across the transactions. Here, dim=0 refers to the dimension that separates the transactions from one another (i.e., num of transactions, num of items, num of linguistic terms).
- Parameters:
candidates – The candidate itemsets.
starting_period – The starting period to begin counting transactions from.
- Returns:
(torch.Tensor) The scalar cardinalities.
- visualize_lattice(layout: str = 'grid') None
Visualize and display the constructed lattice. :param layout: The chosen layout style; default is ‘grid’.
- Returns:
None
- class soft.fuzzy.temporal.association.ftarm.TemporalInformationTable(dataframe, variables)
Bases:
object
The TemporalInformationTable provides a convenient interface for handling the transactions’ temporal information.
- max_starting_periods(candidates: list) array
The maximum starting periods of the given candidates.
- Parameters:
candidates – The candidate itemsets.
- Returns:
Numpy array.
- relevant_transactions(time_column: str = 'date', starting_period: int | None = None) DataFrame
Obtain the transactions from the database that have a time_column value either at or after starting_period.
- Parameters:
time_column – The column that should be used as timestamps for the transactions;
'date'. (default is)
starting_period – The timestamp that all transactions should either occur at
'None'. (or after it; default is)
- Returns:
(pandas.DataFrame) A dataframe that contains all the relevant transactions.
- soft.fuzzy.temporal.association.ftarm.add_candidates_to_granulation(knowledge_base: KnowledgeBase, candidates: list) None
Clear any existing operators on the KnowledgeBase object and reset the KnowledgeBase with the candidates.
- Parameters:
knowledge_base – An object instance of KnowledgeBase.
candidates – The candidate itemsets.
- Returns:
None
- soft.fuzzy.temporal.association.ftarm.find_predecessors(predecessors_vertices: VertexSeq) list
Given the vertices referencing an itemset’s predecessors, retrieve the values they are actually representing.
- Parameters:
predecessors_vertices – VertexSeq object.
- Returns:
A list of predecessors.
- soft.fuzzy.temporal.association.ftarm.make_candidates_inference_engine(knowledge_base: KnowledgeBase, candidates: list)
Create a temporary inference engine to quickly calculate candidates’ fuzzy temporal supports and related metrics.
- Parameters:
knowledge_base – An object instance of KnowledgeBase.
candidates – The candidate itemsets.
- Returns:
MinimumInference