constraints.quadratic

Module: constraints.quadratic

Inheritance diagram for selectinf.constraints.quadratic:

digraph inheritance6cc2edc5d8 { rankdir=LR; size="8.0, 12.0"; "constraints.base.constraints" [URL="selectinf.constraints.base.html#selectinf.constraints.base.constraints",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",target="_top"]; "constraints.quadratic.constraints" [URL="#selectinf.constraints.quadratic.constraints",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",target="_top",tooltip="Object solving the problems of slices for quadratic and linear "]; "constraints.base.constraints" -> "constraints.quadratic.constraints" [arrowsize=0.5,style="setlinewidth(0.5)"]; "constraints.quadratic.constraints_vecnorm" [URL="#selectinf.constraints.quadratic.constraints_vecnorm",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",target="_top"]; "constraints.quadratic.constraints" -> "constraints.quadratic.constraints_vecnorm" [arrowsize=0.5,style="setlinewidth(0.5)"]; }

Classes

constraints

class selectinf.constraints.quadratic.constraints(quad_part, lin_part=None, offset=None, covariance=None, mean=None, rank=None)[source]

Bases: selectinf.constraints.base.constraints

Object solving the problems of slices for quadratic and linear inequalities

\[\forall i, y^T Q_i y + a_i^t < b_i\]
__init__(quad_part, lin_part=None, offset=None, covariance=None, mean=None, rank=None)[source]

Create a new object for quadratic constraints

Parameters

quad_part : np.float(l, p, p)

3-dimensions array. The lines are some quadratic forms

lin_part : np.float(l, p)

The lines are the vector of the linear forms in the inquality Default to np.zeros(l, p)

offset : np.float(l)

The offsets of all inequalities Defaults to np.zeros(l)

covariance : np.float((p,p))

Covariance matrix of Gaussian distribution to be truncated. Defaults to np.identity(self.dim).

mean : np.float(p)

Mean vector of Gaussian distribution to be truncated. Defaults to np.zeros(self.dim).

rank : int

If not None, this should specify the rank of the covariance matrix. Defaults to self.dim.

WARNING : The shapes of the three parameters must fit

bounds(nu, y)[source]

Return the intervals of the slice in a direction nu, which respects the inequality

Parameters

nu : np.float(p)

The direction of the slice

y : np.float(p)

A point on the affine slice

Returns

intervals : array of couples

Array of (a, b), which means that the set is the union of [a, b]

Examples

The constraints are : (x - 1)^2 + y ^ 2 < 4 10 * x^2 - 10 * y^2 < -1 (x + 1)^2 + y ^ 2 < 4

>>> q1, lin1, off1 = np.identity(2), np.array([2., 0.]), 3.
>>> q2, lin2, off2 = np.array([[10., 0], [0, -10.]]), np.zeros(2), -1.
>>> q3, lin3, off3 = np.identity(2), np.array([-2., 0.]), 3.
>>> cons = constraints(np.array([q1, q2, q3]),                                np.array([lin1, lin2, lin3]),                                np.array([off1, off2, off3]))
>>> y = np.array([[0., -1.]]).T
>>> nu1 = np.array([[0., 1.]]).T
>>> I1 = np.array(cons.bounds(nu1, y).intersection())
>>> I1_expected = np.array([[- np.sqrt(3) + 1, 1. -1./np.sqrt(10)],                                      [1. + 1./np.sqrt(10), 1. + np.sqrt(3)]])
>>> #np.all(np.fabs(I1 - I1_expected) < 1.e-10)
>>> nu2 = 2*nu1             ## Try with a nu not unitary
>>> I2 = np.array(cons.bounds(nu2, y).intersection())
>>> I2_expected = I1_expected /2
>>> #np.all(np.fabs(I2 - I2_expected) < 1.e-10)
>>> nu3 = np.array([[1., 0]]).T
>>> I3 = np.array(cons.bounds(nu3, y).intersection())
>>> I3_expected = np.array([[1. - np.sqrt(3), -1. + np.sqrt(3)]])
>>> #np.all(np.fabs(I3 - I3_expected) < 1.e-10)
bounds_unknownSigma(P, y)[source]
sample(n_sample, initial_point)[source]
sample_dum(n_sample)[source]
gen_p_value(y, f, sigma=1.0, n_samples=1000)[source]
Parameters

f : z -> x

observed value

distr_norm_unknownSigma(P, y, n, p)[source]
p_value_unknownSigma(P, y, n, p)[source]
distr_norm(X_s, y, sigma=1.0)[source]

Return the value of the norm of X_s.T*y and an instance of truncated : the distribution of X_s.T*y This is implementing the forward stepwise paper in the general case

Parameters

X_s : np.float(p, k):

X_s is a full ranked matrix

y : np.float(p):

y is the data, and satisfies the constraints

sigma: float

sigma is the variance of the normal distribution under wich y is chosen

Returns

distr : truncated_chi

distr is an object used to study the distribution of np.linalg.norm(np.dot(X_s.T, y)), when y is a gaussian vector, chosen under the constraints and on the slice given by nu

p_value(X_s, y, sigma=1.0)[source]

constraints_vecnorm

class selectinf.constraints.quadratic.constraints_vecnorm(alpha, beta, dim)[source]

Bases: selectinf.constraints.quadratic.constraints

__init__(alpha, beta, dim)[source]

Create a new object for quadratic constraints

Parameters

quad_part : np.float(l, p, p)

3-dimensions array. The lines are some quadratic forms

lin_part : np.float(l, p)

The lines are the vector of the linear forms in the inquality Default to np.zeros(l, p)

offset : np.float(l)

The offsets of all inequalities Defaults to np.zeros(l)

covariance : np.float((p,p))

Covariance matrix of Gaussian distribution to be truncated. Defaults to np.identity(self.dim).

mean : np.float(p)

Mean vector of Gaussian distribution to be truncated. Defaults to np.zeros(self.dim).

rank : int

If not None, this should specify the rank of the covariance matrix. Defaults to self.dim.

WARNING : The shapes of the three parameters must fit

bounds(nu, y)[source]

Return the intervals of the slice in a direction nu, which respects the inequality

Parameters

nu : np.float(p)

The direction of the slice

y : np.float(p)

A point on the affine slice

Returns

intervals : array of couples

Array of (a, b), which means that the set is the union of [a, b]

Examples

The constraints are : (x - 1)^2 + y ^ 2 < 4 10 * x^2 - 10 * y^2 < -1 (x + 1)^2 + y ^ 2 < 4

>>> q1, lin1, off1 = np.identity(2), np.array([2., 0.]), 3.
>>> q2, lin2, off2 = np.array([[10., 0], [0, -10.]]), np.zeros(2), -1.
>>> q3, lin3, off3 = np.identity(2), np.array([-2., 0.]), 3.
>>> cons = constraints(np.array([q1, q2, q3]),                                np.array([lin1, lin2, lin3]),                                np.array([off1, off2, off3]))
>>> y = np.array([[0., -1.]]).T
>>> nu1 = np.array([[0., 1.]]).T
>>> I1 = np.array(cons.bounds(nu1, y).intersection())
>>> I1_expected = np.array([[- np.sqrt(3) + 1, 1. -1./np.sqrt(10)],                                      [1. + 1./np.sqrt(10), 1. + np.sqrt(3)]])
>>> #np.all(np.fabs(I1 - I1_expected) < 1.e-10)
>>> nu2 = 2*nu1             ## Try with a nu not unitary
>>> I2 = np.array(cons.bounds(nu2, y).intersection())
>>> I2_expected = I1_expected /2
>>> #np.all(np.fabs(I2 - I2_expected) < 1.e-10)
>>> nu3 = np.array([[1., 0]]).T
>>> I3 = np.array(cons.bounds(nu3, y).intersection())
>>> I3_expected = np.array([[1. - np.sqrt(3), -1. + np.sqrt(3)]])
>>> #np.all(np.fabs(I3 - I3_expected) < 1.e-10)
bounds_unknownSigma(P, y)
distr_norm(X_s, y, sigma=1.0)

Return the value of the norm of X_s.T*y and an instance of truncated : the distribution of X_s.T*y This is implementing the forward stepwise paper in the general case

Parameters

X_s : np.float(p, k):

X_s is a full ranked matrix

y : np.float(p):

y is the data, and satisfies the constraints

sigma: float

sigma is the variance of the normal distribution under wich y is chosen

Returns

distr : truncated_chi

distr is an object used to study the distribution of np.linalg.norm(np.dot(X_s.T, y)), when y is a gaussian vector, chosen under the constraints and on the slice given by nu

distr_norm_unknownSigma(P, y, n, p)
gen_p_value(y, f, sigma=1.0, n_samples=1000)
Parameters

f : z -> x

observed value

p_value(X_s, y, sigma=1.0)
p_value_unknownSigma(P, y, n, p)
sample(n_sample, initial_point)
sample_dum(n_sample)

Functions

selectinf.constraints.quadratic.roots_poly2(a, b, c)[source]
selectinf.constraints.quadratic.stack(*quad_cons)[source]