pykappa.utils¶
Functions
|
Checks whether the magnitude of the slope of the tail of the series relative to the mean is sufficiently small (below tolerance). |
|
Randomly sample an element from population that is not in excluded. |
|
Format rows into a table with aligned columns. |
Classes
|
Assigns a unique integer ID to each instance, starting from 0. |
|
A subclass of the built-in set, with support for indexing by arbitrary properties of set members and integer indexing to enable random sampling. |
|
- class pykappa.utils.Counted[source]¶
Assigns a unique integer ID to each instance, starting from 0.
- counter = 0¶
- class pykappa.utils.IndexedSet(iterable=[])[source]¶
A subclass of the built-in set, with support for indexing by arbitrary properties of set members and integer indexing to enable random sampling.
Credit https://stackoverflow.com/a/15993515 for the integer indexing logic.
NOTE: Member ordering is not stable across insertions and deletions.
Example usage: ``` […] # define a SportsTeam class
teams: IndexedSet[SportsTeam] = IndexedSet() teams.create_index(“name”, lambda team: [team.name]) teams.create_index(“color”, lambda team: [team.jersey_color])
[…] # populate the set with teams
teams.lookup_one(“name”, “Manchester”) # Returns the team whose name is “Manchester” teams.lookup(“color”, “blue”) # Returns all teams with blue jerseys ```
- Parameters:
iterable (Iterable[T])
- add(item)[source]¶
Add an element to a set.
This has no effect if the element is already present.
- Parameters:
item (T)
- create_index(name, prop)[source]¶
Create an index that’s updated when adding and removing members.
Note
Mutating set members outside of interface calls can invalidate indices.
- Parameters:
name (str)
prop (Callable[[T], Iterable[Hashable]])
- indices: dict[str, defaultdict[Hashable, Self]]¶
- lookup(name, value)[source]¶
Return an IndexedSet of all matching items.
- Parameters:
name (str)
value (Any)
- Return type:
Self
- lookup_one(name, value)[source]¶
Return a single matching item. Raises if not exactly one match.
- Parameters:
name (str)
value (Any)
- Return type:
T
- properties: dict[str, Callable[[T], Iterable[Hashable]]]¶
- pykappa.utils.equilibrated(values, times, tail_fraction=0.1, tolerance=0.01)[source]¶
Checks whether the magnitude of the slope of the tail of the series relative to the mean is sufficiently small (below tolerance). Time can be provided to account for non-uniform sampling intervals.
- Raises:
AssertionError – If there are not enough measurements to assess equilibration.
- Parameters:
values (list[float])
times (list[float] | None)
tail_fraction (float)
tolerance (float)
- Return type:
bool