garpar.utils package¶
Utils subpackage of Garpar project.
Utilities for particular implementations of Garpar project.
Submodules¶
garpar.utils.accabc module¶
Accessor abstract base class for Garpar project.
- class garpar.utils.accabc.AccessorABC¶
Bases:
ABCGeneralization of the accessor idea for use in Garpar.
Instances of this class are callable and accept as the first parameter ‘kind’ the name of a method to be executed followed by all the all the parameters of this method.
If ‘kind’ is None, the method defined in the class variable ‘_default_kind_kind’ is used.
The last two considerations are that ‘kind’, cannot be a private method and that all subclasses of the method and that all AccessorABC subclasses have to redefine ‘_default_kind’.
garpar.utils.bunch module¶
Bunch util for Garpar project.
- class garpar.utils.bunch.Bunch(name, data)¶
Bases:
MappingContainer object exposing keys as attributes.
Concept based on the sklearn.utils.Bunch.
Bunch objects are sometimes used as an output for functions and methods. They extend dictionaries by enabling values to be accessed by key, bunch[“value_key”], or by an attribute, bunch.value_key.
Examples
>>> b = SKCBunch("data", {"a": 1, "b": 2}) >>> b data({a, b}) >>> b['b'] 2 >>> b.b 2 >>> b.a = 3 >>> b['a'] 3 >>> b.c = 6 >>> b['c'] 6
- to_dict()¶
Convert the Bunch object to a dictionary.
This method performs a deep copy of the _data attribute, ensuring that the original data remains unchanged.
- Returns:
A deep copy of the _data attribute.
- Return type:
dict
Example
>>> bunch = Bunch() >>> bunch._data = {'key1': 'value1', 'key2': 'value2'} >>> dict_data = bunch.to_dict() >>> print(dict_data) {'key1': 'value1', 'key2': 'value2'}
garpar.utils.context module¶
Context util for Garpar project.
- garpar.utils.context.df_temporal_header(df, header, name=None)¶
Temporarily replaces a DataFrame columns names.
Optionally also assign another name to the columns.
- Parameters:
header (sequence) – The new names of the columns.
name (str or None (default None)) – New name for the index containing the columns in the DataFrame. If ‘None’ the original name of the columns present in the DataFrame is preserved.
garpar.utils.entropy module¶
Entropy measure module.
A collection of functions for calculating entropy measures.
- garpar.utils.entropy.risso(prices, window_size=None, **kwargs)¶
Calculate the Risso entropy of the given prices.
- Parameters:
prices (Dataframe) – Description of prices parameter.
window_size (int) – Description of window_size parameter.
**kwargs – Additional keyword arguments.
- Raises:
ValueError – If ‘window_size’ is not valid.
- Returns:
The Risso entropy of the prices.
- Return type:
array-like
- garpar.utils.entropy.shannon(prices, window_size=None, **kwargs)¶
Calculate the Shannon entropy of the given prices.
- Parameters:
prices (array_like) – Prices data to calculate entropy.
window_size (int, optional) – Ignored parameter for Shannon entropy calculation.
**kwargs – Additional keyword arguments to pass to stats.entropy.
- Returns:
The Shannon entropy of the prices along axis 0.
- Return type:
array_like
- garpar.utils.entropy.yager_inf(weigths)¶
Compute Yager’s entropy for a fuzzy set and z->inf.
- Parameters:
weights (array-like) – List of membership degrees (values in [0, 1])
- Returns:
Yager’s entropy for z->inf
- Return type:
float
- garpar.utils.entropy.yager_one(weights)¶
Compute Yager’s entropy for a fuzzy set and z=1.
- Parameters:
weights (array-like) – List of membership degrees (values in [0, 1])
- Returns:
Yager’s entropy for z->1
- Return type:
float
garpar.utils.mabc module¶
Metadata utilities.
- class garpar.utils.mabc.ModelABC¶
Bases:
objectBase class for all model classes.
This class provides a base for all model classes in the project. It is designed to be used with the attrs library, and it ensures that all inherited classes are decorated with attr.s() and have a frozen configuration.
- garpar.utils.mabc.hparam(**kwargs)¶
Create a hyper parameter for market maker.
By design decision, hyper-parameter is required to have a sensitive default value.
- Parameters:
**kwargs – Additional keyword arguments are passed and are documented in
attr.ib().- Return type:
Hyper parameter with a default value.
Notes
This function is a thin-wrapper over the attrs function
attr.ib().
- garpar.utils.mabc.mproperty(**kwargs)¶
Create a hyper parameter for market maker.
By design decision, hyper-parameter is required to have a sensitive default value.
- Parameters:
default – Sensitive default value of the hyper-parameter.
**kwargs – Additional keyword arguments are passed and are documented in
attr.ib().
- Return type:
Hyper parameter with a default value.
Notes
This function is a thin-wrapper over the attrs function
attr.ib().
garpar.utils.scalers module¶
Scalers.
- garpar.utils.scalers.max_scaler(arr)¶
Scales the input array by the maximun value.
- garpar.utils.scalers.minmax_scaler(arr)¶
Scales the input array using the min-max normalization technique.
- garpar.utils.scalers.proportion_scaler(arr)¶
Scale the input array by normalizing each element.
- garpar.utils.scalers.standar_scaler(arr)¶
Standardize an array by subtracting the mean and dividing by std.
garpar.utils.unames module¶
Unique names util for Garpar project.
- garpar.utils.unames.unique_names(*, names, elements)¶
Generate names unique name.
- Parameters:
elements (iterable of size n) – objects to be named
names (iterable of size n) – names candidates
- Returns:
Returns a list where each element is a tuple. Each tuple contains two elements: The first element is the unique name of the second is the named object.
- Return type:
list of tuples