truncated.gaussian

Module: truncated.gaussian

Inheritance diagram for selectinf.truncated.gaussian:

digraph inheritance1c072f7fcc { rankdir=LR; size="8.0, 12.0"; "truncated.base.truncated" [URL="selectinf.truncated.base.html#selectinf.truncated.base.truncated",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",target="_top",tooltip="A distribution, truncated to a union of intervals"]; "truncated.gaussian.TruncatedGaussianError" [URL="#selectinf.truncated.gaussian.TruncatedGaussianError",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",target="_top"]; "truncated.gaussian.truncated_gaussian" [URL="#selectinf.truncated.gaussian.truncated_gaussian",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",target="_top",tooltip=">>> from selectinf.constraints.intervals import intervals"]; "truncated.base.truncated" -> "truncated.gaussian.truncated_gaussian" [arrowsize=0.5,style="setlinewidth(0.5)"]; "truncated.gaussian.truncated_gaussian_old" [URL="#selectinf.truncated.gaussian.truncated_gaussian_old",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",target="_top",tooltip="A Gaussian distribution, truncated to"]; }

This module implements the class truncated_gaussian which performs (conditional) UMPU tests for Gaussians restricted to a set of intervals.

Classes

TruncatedGaussianError

class selectinf.truncated.gaussian.TruncatedGaussianError[source]

Bases: ValueError

__init__($self, /, *args, **kwargs)

Initialize self. See help(type(self)) for accurate signature.

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

truncated_gaussian

class selectinf.truncated.gaussian.truncated_gaussian(I, mu=0, scale=1.0)[source]

Bases: selectinf.truncated.base.truncated

>>> from selectinf.constraints.intervals import intervals
>>> I = intervals.intersection(intervals((-1, 6)),                                        intervals(( 0, 7)),                                        ~intervals((1, 4)))
>>> distr = truncated_gaussian(I, 3.1, 2.)
__init__(I, mu=0, scale=1.0)[source]

Create a new object for a truncated_gaussian distribution

Parameters

I : intervals

The intervals the distribution is truncated to.

mu : int

Mean of Gaussian that is truncated.

scale : float

SD of Gaussian that is truncated.

cdf(z)

Compute the survival function of the truncated distribution

Parameters

z : float

Minimum bound of the interval

Returns

cdf : float

function The cumulative distribution function of the truncated distribution cdf(z) = P( X < z | X is in intervals )

WARNING : This method only use the sf method

more precise

pdf(z)

Compute the probability distribution funtion of the truncated distribution

Parameters

z : float

Returns

p : float

p(z) such that E[f(X)] = int f(z)p(z)dz

quantile(q, tol=1e-06)
rvs(size=1)

Sample a random variable from the truncated disribution

Parameters

size : int

Number of samples. Default : 1

Returns

X : np.array

array of sample

sf(z)

Compute the survival function of the truncated distribution

Parameters

z : float

Minimum bound of the interval

Returns

sf : float

The survival function of the truncated distribution sf(z) = P( X > z | X is in intervals )

truncated_gaussian_old

class selectinf.truncated.gaussian.truncated_gaussian_old(intervals, mu=0, scale=1)[source]

Bases: object

A Gaussian distribution, truncated to

__init__(intervals, mu=0, scale=1)[source]

Initialize self. See help(type(self)) for accurate signature.

property intervals
property negated
set_mu(mu)[source]
get_mu()[source]
property mu
set_scale(scale)[source]
get_scale()[source]
property scale
property delta
\[\begin{split}\begin{align} \delta_\mu(a,b) &\triangleq \int_a^b x\phi(x-\mu)\,dx \\ &= - \phi(b-\mu) + \phi(a-\mu) + \mu\left(\Phi(b-\mu)-\Phi(a-\mu)\right), \end{align}\end{split}\]
static twosided(thresh, mu=0, scale=1)[source]
cdf(observed)[source]
quantile(q)[source]
right_endpoint(left_endpoint, alpha)[source]
G(left_endpoint, alpha)[source]

\(g_{\mu}\) from Will’s code

dG(left_endpoint, alpha)[source]

\(gg_{\mu}\) from Will’s code

equal_tailed_interval(observed, alpha)[source]
UMAU_interval(observed, alpha, mu_lo=None, mu_hi=None, tol=1e-08)[source]

Functions

selectinf.truncated.gaussian.G(left_endpoints, mus, alpha, tg)[source]

Compute the \(G\) function of tg(intervals) over zip(left_endpoints, mus).

A copy is made of tg and its \((\mu,\scale)\) are not modified.

selectinf.truncated.gaussian.dG(left_endpoints, mus, alpha, tg)[source]

Compute the \(G\) function of tg(intervals) over zip(left_endpoints, mus).

A copy is made of tg and its \((\mu,\scale)\) are not modified.

selectinf.truncated.gaussian.find_root(f, y, lb, ub, tol=1e-06)[source]

searches for solution to f(x) = y in (lb, ub), where f is a monotone decreasing function