projnormal.classes.constraints
Constraints to keep the distribution parameters in a valid region.
Classes
|
Constrain matrix \(M\) to be \(M = d \cdot I_n + W\), where \(d>0\) is a scalar, \(I_n\) is the identity matrix, and \(W\) is a symmetric positive semi-definite matrix of rank at most k. |
|
Diagonal matrix with positive diagonal entries. |
|
Constrain matrix to be \(M = \lambda \cdot I_n\), where \(\lambda>0\) and \(I_n\) is the identity matrix. |
|
Positive value constraint. |
|
Positive and larger than offset value constraint. |
|
Unit norm constraint. |
- class ConstrainedSPD(diag=1.0, rank=1, fixed_diag=False)
Bases:
ModuleConstrain matrix \(M\) to be \(M = d \cdot I_n + W\), where \(d>0\) is a scalar, \(I_n\) is the identity matrix, and \(W\) is a symmetric positive semi-definite matrix of rank at most k.
- forward(vecs)
Generate a constrained SPD matrix as eye + vecs @ vecs.T.
- Parameters:
vecs (torch.Tensor (n_dim, rank).) – Input vectors in euclidean space.
- Returns:
Constrained SPD matrix.
- Return type:
torch.Tensor (n_dim, n_dim).
- right_inverse(M)
Initialize the vectors to a set of k random vectors.
- class Diagonal(*args, **kwargs)
Bases:
ModuleDiagonal matrix with positive diagonal entries.
- forward(diagonal)
Transform the input vector into matrix.
- Parameters:
diagonal (torch.Tensor (n_dim,).) – Input vector in the real line.
- Returns:
Diagonal matrix with positive diagonal of shape
- Return type:
torch.Tensor (n_dim, n_dim).
- right_inverse(M)
Assign as diagonal vector the diagonal entries of M.
- Parameters:
M (torch.Tensor) – Input matrix. Must have positive diagonal entries.
- Returns:
Vector with diagonal entries of M.
- Return type:
torch.Tensor (n_dim,).
- class Isotropic(n_dim=None)
Bases:
ModuleConstrain matrix to be \(M = \lambda \cdot I_n\), where \(\lambda>0\) and \(I_n\) is the identity matrix.
- forward(val)
Transform the input number into an isotropic matrix.
- Parameters:
val (torch.Tensor, shape (1,).) – Input number in the real line.
- Returns:
Isotropic matrix with positive diagonal
- Return type:
torch.Tensor, shape (n_dim, n_dim)
- right_inverse(M)
Assign as val tr(M)/n_dim.
- Parameters:
M (torch.Tensor, shape (n_dim, n_dim).) – Input isotropic matrix.
- Returns:
Scalar value.
- Return type:
torch.Tensor, shape (1,).
- class Positive(*args, **kwargs)
Bases:
ModulePositive value constraint.
- forward(X)
Transform the input tensor to a positive number.
- Parameters:
X (torch.Tensor, shape (...)) – Input vector in the real line
- Returns:
Positive vector.
- Return type:
torch.Tensor, shape (…)
- right_inverse(P)
Inverse of the function to convert positive number to scalar.
- Parameters:
P (torch.Tensor, shape (...)) – Input positive vector
- Returns:
Scalar
- Return type:
torch.Tensor, shape (…)
- class PositiveOffset(offset=1.0)
Bases:
ModulePositive and larger than offset value constraint.
- forward(X)
Transform the input tensor to a positive number.
- Parameters:
X (torch.Tensor, shape (...)) – Input number in the real line
- Returns:
Positive number
- Return type:
torch.Tensor, shape (…)
- right_inverse(P)
Inverse of the function to convert positive number to scalar.
- Parameters:
P (torch.Tensor, shape (...)) – Input positive number
- Returns:
Real number
- Return type:
torch.Tensor, shape (…)
- class Sphere(*args, **kwargs)
Bases:
ModuleUnit norm constraint.
- forward(X)
Normalize the input tensor so that it lies on the sphere.
- Parameters:
X (torch.Tensor, shape (..., n_dim)) – Input tensor in Euclidean space.
- Returns:
Normalized tensor lying on the sphere with shape.
- Return type:
torch.Tensor, shape (…, n_dim)
- right_inverse(S)
Identity function to assign to parametrization.
- Parameters:
S (torch.Tensor, shape (..., n_dim)) – Input tensor. Should be different from zero.
- Returns:
Returns the input tensor S.
- Return type:
torch.Tensor, shape (…, n_dim)