polymerist.genutils.sequences.discernment.inventory
Utilities and type-hinting for creating symbol inventories, which map symbols and bin labels to occurences Useful concrete data structure for representing ordered sequences of symbol multisets for generalized ransom note enumeration
Attributes
Classes
Representation of a map from a set of symbols of type T and a set of bin labels of type L to integer counts |
Functions
|
Similar to numpy.full (https://numpy.org/doc/stable/reference/generated/numpy.full.html) but with builtin list type |
Module Contents
- polymerist.genutils.sequences.discernment.inventory.LOGGER
- polymerist.genutils.sequences.discernment.inventory.T
- polymerist.genutils.sequences.discernment.inventory.L
- polymerist.genutils.sequences.discernment.inventory.full_arr_builtin(*dims: Iterable[int], fill_value: Any = None) list[Any][source]
Similar to numpy.full (https://numpy.org/doc/stable/reference/generated/numpy.full.html) but with builtin list type
- class polymerist.genutils.sequences.discernment.inventory.SymbolInventory(*args, _number_of_symbols: int | None = None, _number_of_bins: int | None = None, _symbol_index_map: dict[T, int] | None = None, _bin_index_map: dict[L, int] | None = None, **kwargs)[source]
-
Representation of a map from a set of symbols of type T and a set of bin labels of type L to integer counts Implemented as a dict, keyed by symbol, whose values count the number of occurrences of that symbol in all bins that symbol occurs
Data structure with specific methods which are useful in solving the generalized ransom note enumeration problem
- classmethod from_bin_sequence_mapping(choice_bin_map: Mapping[L, Sequence[Iterable[T]]], _symbol_index_map: dict[T, int] | None = None, _bin_index_map: dict[L, int] | None = None) SymbolInventory[T, L][source]
Initialize inventory from a mapping of labels to bins
- classmethod from_bin_sequence(choice_bins: Sequence[Iterable[T]]) SymbolInventory[T, int][source]
Initialize inventory from an ordered sequence of bins Special case of mapping instantiation for sequences of bins; simply uses the index of a bin as its label
- classmethod from_bins(choice_bins: Sequence[Iterable[T]] | dict[L, Sequence[Iterable[T]]]) SymbolInventory[T, L][source]
“Smart” initialization method which dispatches to from_bin_sequence() or from_bin_sequence_mapping(), depending on the nature of the “choice_bins” container provided
- property number_of_symbols: int
Number of unique symbols present in the SymbolInventory
- property number_of_bins: int
Number of unique symbols present in the SymbolInventory
- property symbol_index_map: dict[T, int]
Arbitrary one-to-one mapping between all symbols present in the inventory and integer indices
- property bin_index_map: dict[T, int]
Arbitrary one-to-one mapping between all bins present in the inventory and integer indices
- contains_word(sequence: Sequence[T], ignore_multiplicities: bool = False) bool[source]
Check if a word (i.e. sequence of symbols of type T) could possibly be produced from a SymbolInventory
Returns bool; True indicated the word can be made from the inventory False return indicates the sequence contains symbols not present in the inventory OR contains more of one particular symbol than are present in the whole inventory
- deepcopy() SymbolInventory[T, L][source]
Create a deep copy of the current SymbolInventory
- property involution: SymbolInventory[L, T]
Returns a new SymbolInventory which switches the order of precedence of the symbols and bin labels So-called because self.involution.involution returns a SymbolInventory identical to self (by construction)
- property occurence_matrix: list[list[int]] | numpy.ndarray[Any, int]
Creates an NxM matrix (N is the number of symbols, and M is the number of bins) which represents a SymbolInventory Matrix element A_ij denotes the number of occurences of the i-th symbol (according to an arbitrary numbering) in the j-th bin
Will attempt to return matrix as a 2-D numpy array, but will default to a doubly-nested list if numpy is not found to be installed