proxtorch.constraints#

class proxtorch.constraints.Box(a: float = 0.0, b: float = 1.0)[source]#

Bases: Constraint

prox(x: Tensor) Tensor[source]#

Projects the tensor onto the feasible set defined by the constraint.

Parameters:

x (torch.Tensor) – Input tensor.

Returns:

Tensor after projection.

Return type:

torch.Tensor

Raises:

NotImplementedError – If the method is not implemented in a subclass.

class proxtorch.constraints.Frobenius(s: float = 1.0)[source]#

Bases: Constraint

Constraint for the Frobenius norm.

s#

Regularization strength.

Type:

float

prox(x: Tensor) Tensor[source]#

Projects the tensor onto the feasible set defined by the Frobenius norm constraint.

Parameters:

x (torch.Tensor) – Input tensor.

Returns:

Tensor after projection.

Return type:

torch.Tensor

class proxtorch.constraints.L0Ball(s: int)[source]#

Bases: Constraint

L0Prox ball proximal operator.

Projects onto a vector with at most s non-zero elements.

s#

Budget of non-zero elements.

Type:

int

prox(x: Tensor) Tensor[source]#

Proximal operator for the L0Prox ball.

Keeps the s largest elements in magnitude and sets the rest to zero.

Parameters:
  • x (torch.Tensor) – Input tensor.

  • tau (float) – Proximal step size. Not used for L0Ball, but kept for API consistency.

Returns:

Resultant tensor after applying the proximal operator.

Return type:

torch.Tensor

class proxtorch.constraints.L1Ball(s: float = 1.0)[source]#

Bases: Constraint

Projection onto the L1 ball.

s#

Radius of the L1 ball.

Type:

float

prox(x: Tensor) Tensor[source]#

Project x onto the L1-ball of radius s.

Parameters:
  • x (torch.Tensor) – Input tensor.

  • tau (float) – Proximal step size. Not used for L1Ball, but kept for API consistency.

Returns:

Resultant tensor after the projection.

Return type:

torch.Tensor

class proxtorch.constraints.L2Ball(s: float = 1.0)[source]#

Bases: Constraint

Projection onto the L1 ball.

s#

Radius of the L1 ball.

Type:

float

prox(x: Tensor) Tensor[source]#

Project x onto the L1-ball of radius s.

Parameters:
  • x (torch.Tensor) – Input tensor.

  • tau (float) – Proximal step size. Not used for L1Ball, but kept for API consistency.

Returns:

Resultant tensor after the projection.

Return type:

torch.Tensor

class proxtorch.constraints.LInfinityBall(s: float = 1.0)[source]#

Bases: Constraint

Projection onto the LInfinity ball of radius s.

s#

Radius of the LInfinity ball.

Type:

float

prox(x: Tensor) Tensor[source]#

Project x onto the LInfinity-ball of radius s.

Parameters:
  • x (torch.Tensor) – Input tensor.

  • tau (float) – Proximal step size. Not used for LInfinityBall, but kept for API consistency.

Returns:

Resultant tensor after the projection.

Return type:

torch.Tensor

class proxtorch.constraints.NonNegative[source]#

Bases: Constraint

Proximal operator for the non-negative constraint.

prox(x: Tensor) Tensor[source]#

Apply the proximal operation for non-negative constraint.

Parameters:
  • x (Tensor) – Input tensor.

  • tau (float) – Proximal step size (not used here, but kept for consistency).

Returns:

Result after applying the non-negative constraint.

Return type:

Tensor

class proxtorch.constraints.Rank(max_rank: int)[source]#

Bases: Constraint

Constraint for rank regularization.

max_rank#

Maximum allowable rank.

Type:

int

prox(x: Tensor) Tensor[source]#

Projects the tensor onto the feasible set defined by the rank constraint.

Parameters:

x (torch.Tensor) – Input tensor.

Returns:

Tensor after projection.

Return type:

torch.Tensor

class proxtorch.constraints.TraceNorm(alpha: float = 1.0)[source]#

Bases: Constraint

Constraint for trace norm regularization.

alpha#

Regularization strength.

Type:

float

prox(x: Tensor) Tensor[source]#

Projects the tensor onto the feasible set defined by the trace norm constraint.

Parameters:

x (torch.Tensor) – Input tensor.

Returns:

Tensor after projection.

Return type:

torch.Tensor