openest.models.bin_model module

class openest.models.bin_model.BinModel(xx=None, model=None)[source]

Bases: openest.models.univariate_model.UnivariateModel, openest.models.memoizable.MemoizableUnivariate

Bin Model

A bin model represents bins of different spans, where the distribution is constant over each bin. It is a combination of information describing the bins and an underlying categorical model of one of the other types.

The underlying model is always categorical, with categories starting at 1. 0 is reserved for a future version that allows an out-of-sample distribution

The format is:

bin1
<x0>,<x1>,<x2>, ...
<underlying model>
Parameters:
  • xx (list-like) – List-like array of bin edges. len(xx) should be one more than the number of bins.
  • model (object) – Statistical model used in each bin
cdf(x, y)[source]
static combine(one, two)[source]

Both models are BinModels

static consistent_bins(models)[source]

All models are BinModels

copy()[source]

copy data and return BinModel with the same data

draw_sample(x=None)[source]

Produce a sample value of y from the conditional distribution.

eval_pval(x, p, threshold=0.001)[source]

Inverse CDF Evaluation

Returns the value of $y$ that corresponds to a given p-value: $F^{-1}(p | x)$.

eval_pval_index(ii, p, threshold=0.001)[source]
filter_x(xx)[source]

Returns new BinModel

get_bin_at(x)[source]

Returns bin containing value x

Parameters:x (numeric) – Value to search for in binned axis
Returns:Returns index of bin containing x. If bin is not contained in the bin range, returns -1.
Return type:int
get_edges()[source]

Returns bin edges (duplicate of get_xx())

get_mean(x=None, index=None)[source]

E[Y | X]

get_sdev(x=None, index=None)[source]

sqrt Var[Y | X]

get_xx()[source]

returns x axis index

get_xx_centers()[source]

returns x axis index

init_from_bin_file(file, delimiter, status_callback=None, init_submodel=<function <lambda>>)[source]
interpolate_x(newxx)[source]

Returns a copy of the model. Does not interpolate.

kind()[source]

returns model type (“bin_model”)

static merge(models)[source]

All models are BinModels

scale_p(a)[source]

Scales p-values of underlying bin models (in log_p format)

Interface to self.model.scale_p.

scale_y(a)[source]

Scales y-axes of underlying bin models

Interface to self.model.scale_y(a)

to_ddp(ys=None)[source]
to_points_at(x, ys)[source]

Conditional Probability Density Evaluation

Returns unscaled probability density values for given values of $x$ and $y$: $f(y | x)$.

write(file, delimiter)[source]

Write model as delimited document to file-like object

Prepends model type (bin1) and bin borders (xx) to document written by self.model.write.

Parameters:
  • file (object) – file-like object
  • delimiter (str) – Delimiter to use in file (e.g. ‘ ‘, ‘,’)
write_file(filename, delimiter)[source]

Write model as delimited document to filepath

Wrapper around write() method.

Parameters:
  • filename (str) – Path to file to be written
  • delimiter (str) – Delimiter to use in file (e.g. ‘ ‘, ‘,’)