pyqrse.utilities package¶
Submodules¶
pyqrse.utilities.defaults module¶
-
pyqrse.utilities.defaults.reset_label_settings()¶ reset labels/color/etc settings to default loaded from DEFAULTS.ini
-
pyqrse.utilities.defaults.view_label_settings()¶
pyqrse.utilities.helpers module¶
-
class
pyqrse.utilities.helpers.ReadOnlyClassProperty(method)¶ Bases:
objectread-only class property
Allows class methods to be called like property with no setter declared.
-
pyqrse.utilities.helpers.date_to_datetime(d)¶
-
pyqrse.utilities.helpers.datetime_to_date(d)¶
-
pyqrse.utilities.helpers.docthief(mark_function)¶ Gives decorated function the __docstring__ of the mark_function
Parameters: mark_function – function to copy __docstring__ from
-
pyqrse.utilities.helpers.kernel_hierarchy_to_hash_bfs(kernel)¶ creates a dictionary of kernels (values) and their string codes (key)
key = kernel’s code value = non-instantiated kernel object
Example:
>>>kernel_hash['S'] pyqrse.kernels.binarykernels.SQRSEKernel
- Arg:
- kernel (QRSEKernelBase object) :
Returns: dict
-
pyqrse.utilities.helpers.kwarg_filter(kwargs, target_function)¶ filters kwargs of outside function to make sure they work in target function. Note: this function may have unexpected results if outer and target functions have the same keyword arguments assigned to different uses.
Parameters: - kwargs – kwargs from outer function
- target_function – function filtered kwargs will be given to
Returns: dictionary of keyword arguments
-
pyqrse.utilities.helpers.matrix_print(mat_to_print, rb=None, cb='|', f=2)¶ prints matrix or np.arrays prettier
Parameters: - mat_to_print (2d list) – list of lists where each item in each row is either a str, int, or float
- rb (str) – Single character to string for rows in between the rows of the matrix. If None (default), no breaks between rows
- cb (str) – Single character to demarcate column breaks. Defaults is “|”
- f (int) – the number of decimals to show in floats.
-
pyqrse.utilities.helpers.mprint(*args, **kwargs)¶ prints matrix or np.arrays prettier
Parameters: - mat_to_print (2d list) – list of lists where each item in each row is either a str, int, or float
- rb (str) – Single character to string for rows in between the rows of the matrix. If None (default), no breaks between rows
- cb (str) – Single character to demarcate column breaks. Defaults is “|”
- f (int) – the number of decimals to show in floats.
-
pyqrse.utilities.helpers.read_only_class_property(function)¶
-
pyqrse.utilities.helpers.split_strip_parser(parser, key1, key2)¶
pyqrse.utilities.mathstats module¶
-
pyqrse.utilities.mathstats.ab_prior_make(value=0, lam=1.0)¶ returns a log prior function for the ab_model on the buy/sell indifference point :param value: :param lam: :return:
-
pyqrse.utilities.mathstats.al_prior(x)¶
-
pyqrse.utilities.mathstats.asymmetric_laplace(x, l, k, m)¶ PDF for the Asymmetric Laplace Distribution
Parameters: - x (float or np.array(float) – input value
- l (float) – p1
- k (float) – p2
- m (float) – location parameter
Returns: float or np.array(float)
-
pyqrse.utilities.mathstats.cond_entropy(model)¶
-
pyqrse.utilities.mathstats.find_marg_like(log_marginals, n=None)¶
-
pyqrse.utilities.mathstats.find_support_bounds(fun, start=0, which='right', minmax=(2e-09, 4.5e-05), imax=100, silent=True)¶ find support for function that is monotonically decreasing in the tails
-
pyqrse.utilities.mathstats.hess_adjust(hess, param, std)¶
-
pyqrse.utilities.mathstats.inv_cdf_sampler(target, n=1, bounds=(-10, 10, 1000))¶ random variable sampler using the interpolated inverse cdf method
Parameters: n (int) – number of samples.
must be either a positive integer or None. if n is a positive int, rvs returns an np.array of length n if n is None, rvs returns a scalar sample from the distribution
bounds (tuple or list) – (lower bound, upper bound, number of ticks)
[-10, 10, 10000] / (-10, 10, 10000) create 10000 ticks between -10 and 10
Returns: float or np.array([float]) of samples
-
pyqrse.utilities.mathstats.is_pos_def(x)¶
-
pyqrse.utilities.mathstats.joint_entropy(model)¶
-
pyqrse.utilities.mathstats.log_marginal(sampler)¶
-
pyqrse.utilities.mathstats.marg_actions(model)¶
-
pyqrse.utilities.mathstats.marg_entropy(model)¶
-
pyqrse.utilities.mathstats.mean_std_fun(data, weights=None)¶
-
pyqrse.utilities.mathstats.model_p(log_marginals, n=None)¶
-
pyqrse.utilities.mathstats.qrse_weak_prior(params0, weights=None)¶ returns a function for weak Gaussian prior on all parameters. mainly used for stability in multiple equilibria setting
Parameters: - params0 –
- weights –
Returns:
-
pyqrse.utilities.mathstats.rejection_sample(target, proposal, m, n, jmax=10)¶ Rejection Sampler
Parameters: - target (function) – pdf of target distribution
- proposal (object) – distribution to sample from. It must have .rvs() and .pdf(x) methods
- m (float) – value to mulitply proposal distribution in order to turn it into an envelope
- n (int) – number of samples
- jmax (int) – maximum number of proposals before quitting. it’s measured as proposal_max = jmax*n. Default is 10, which means that there will be maximum of 10n proposals.
Returns: np.array(float) of the samples from the target distribution
pyqrse.utilities.mixins module¶
-
class
pyqrse.utilities.mixins.HistoryMixin¶ Bases:
object-
history()¶
-
reset_history()¶
-
save_history(new_hist=None)¶
-
-
class
pyqrse.utilities.mixins.PickleMixin¶ Bases:
object-
classmethod
from_pickle(path_to_pickle, trust_check=False, **kwargs)¶ !!!DO NOT RUN THIS FUNCTION UNLESS YOU TRUST THE SOURCE WITH ABSOLUTE CERTAINTY!!!
Pickling is extremely convenient from a workflow perspective, as you can save the results of inquiries and instantly load them back into your python environment.
However, there are no safety checks on the code that will be run. That means:
-If you don’t trust the source, don’t unpickle it.
-Python will run all code in the pickle malicious or not!
Parameters: - path_to_pickle – individual or list of paths to saved pickled QRSE objects
- args –
- kwargs –
- trust_check – prompts the user to verify that they trust the source of the file to be unpickled default value is True
Returns:
-
to_pickle(path_to_pickle)¶ Uses the python pickle module to serialize the object (pickle it). Pickling allows it to be saved and reloaded later.
Parameters: path_to_pickle – Returns:
-
classmethod
pyqrse.utilities.plottools module¶
-
class
pyqrse.utilities.plottools.QRSEPlotter(qrse_object, colors=None, color_order=None)¶ Bases:
objectTHIS IS SWEET AT MAKING CHARTS
-
colors¶
-
plot(which=0, params=None, bounds=None, ticks=1000, showdata=True, bins=20, title=None, dcolor='w', seaborn=True, lw=2, pi=1.0, colors=None, color_order=None, show_legend=True)¶ - plot(self, which=0, params=None, bounds=None,
- ticks=1000, showdata=True, bins=20, title=None, dcolor=’w’, seaborn=True, lw=2, pi=1., colors=None, color_order=None, show_legend=True):
Parameters: - which –
- params –
- bounds –
- ticks –
- showdata –
- bins –
- title –
- dcolor –
- seaborn –
- lw –
- pi –
- colors –
- color_order –
- show_legend –
Returns:
-
plotboth(*args, **kwargs)¶ plot marginal distribution side by side with :param args: :param kwargs: :return:
-
set_color_order(color_order=None, output=False)¶
-
set_colors(colors=None, output=False)¶
-