proxtorch.operators#

class proxtorch.operators.Dummy[source]#

Bases: ProxOperator

Dummy proximal operator that acts as an identity operation.

This class provides methods for soft-thresholding consistent with L1 norm and computation of the L1 norm.

prox(x: Tensor, tau: float) Tensor[source]#

Soft-thresholding for the L1 norm.

Parameters:
Returns:

Resultant tensor after applying the proximal operator.

Return type:

torch.Tensor

class proxtorch.operators.ElasticNet(alpha: float = 1.0, l1_ratio: float = 0.5)[source]#

Bases: ProxOperator

Elastic Net proximal operator.

Combines both L1 and L2 penalties for regularization.

alpha#

Regularization strength.

Type:

float

l1_ratio#

Proportion of L1 regularization.

Type:

float

l2_ratio#

Proportion of L2 regularization.

Type:

float

prox(x: Tensor, tau: float) Tensor[source]#

Proximal operator for the Elastic Net regularization.

Parameters:
Returns:

Resultant tensor after applying the proximal operator.

Return type:

torch.Tensor

class proxtorch.operators.Frobenius(alpha: float = 1.0)[source]#

Bases: ProxOperator

Proximal operator for the Frobenius norm regularization.

alpha#

Regularization strength.

Type:

float

prox(x: Tensor, tau: float) Tensor[source]#

Proximal operator for the Frobenius norm regularization.

Parameters:
Returns:

Resultant tensor after applying the proximal operator.

Return type:

torch.Tensor

class proxtorch.operators.FusedLasso(alpha: float)[source]#

Bases: ProxOperator

Proximal operator for the 1D Fused Lasso.

prox(x: Tensor, tau: float) Tensor[source]#

Apply the proximal operation for the 1D fused lasso. Uses a simple soft-thresholding approach.

Parameters:
  • x (Tensor) – Input tensor.

  • tau (float) – Proximal step size.

Returns:

Result after applying the fused lasso operation.

Return type:

Tensor

Note

More efficient algorithms exist for larger-scale problems.

class proxtorch.operators.GraphNet2D(alpha, l1_ratio)[source]#

Bases: GraphNet3D, TVL1_2D

divergence(p: Tensor) Tensor#

Compute the divergence of the tensor p.

Parameters:

p (torch.Tensor) – Input tensor.

Returns:

Divergence of the tensor p.

Return type:

torch.Tensor

gradient(x)#

Compute the gradient of the tensor x using finite differences.

Parameters:

x (torch.Tensor) – Input tensor.

Returns:

Gradients of the tensor x.

Return type:

torch.Tensor

prox(x: Tensor, tau: float) Tensor#

Iterative algorithm to compute the proximal mapping of the tensor.

Parameters:
Returns:

Tensor after applying the proximal operation.

Return type:

torch.Tensor

Notes

Total variation denoising aims to minimize the total variation of the image, which can be roughly described as the integral of the norm of the image gradient. As a result, it produces “cartoon-like” images, i.e., piecewise-constant images. For more details, refer to: http://en.wikipedia.org/wiki/Total_variation_denoising

This function implements the FISTA (Fast Iterative Shrinkage Thresholding Algorithm) algorithm of Beck et Teboulle, adapted to total variation denoising in “Fast gradient-based algorithms for constrained total variation image denoising and deblurring problems” (2009).

For more on bound constraints implementation, see the aforementioned Beck and Teboulle paper.

static tvl1_from_grad(gradients: Tensor) Tensor#

Calculate the TV from gradients.

Parameters:

gradients (torch.Tensor) – Gradient tensor.

Returns:

The TV value computed from the gradients.

Return type:

float

class proxtorch.operators.GraphNet3D(alpha, l1_ratio)[source]#

Bases: TVL1_3D

divergence(p: Tensor) Tensor#

Compute the divergence of the tensor p.

Parameters:

p (torch.Tensor) – Input tensor.

Returns:

Divergence of the tensor p.

Return type:

torch.Tensor

gradient(x)#

Compute the gradient of the tensor x using finite differences.

Parameters:

x (torch.Tensor) – Input tensor.

Returns:

Gradients of the tensor x.

Return type:

torch.Tensor

prox(x: Tensor, tau: float) Tensor[source]#

Iterative algorithm to compute the proximal mapping of the tensor.

Parameters:
Returns:

Tensor after applying the proximal operation.

Return type:

torch.Tensor

Notes

Total variation denoising aims to minimize the total variation of the image, which can be roughly described as the integral of the norm of the image gradient. As a result, it produces “cartoon-like” images, i.e., piecewise-constant images. For more details, refer to: http://en.wikipedia.org/wiki/Total_variation_denoising

This function implements the FISTA (Fast Iterative Shrinkage Thresholding Algorithm) algorithm of Beck et Teboulle, adapted to total variation denoising in “Fast gradient-based algorithms for constrained total variation image denoising and deblurring problems” (2009).

For more on bound constraints implementation, see the aforementioned Beck and Teboulle paper.

static tvl1_from_grad(gradients: Tensor) Tensor#

Calculate the TV from gradients.

Parameters:

gradients (torch.Tensor) – Gradient tensor.

Returns:

The TV value computed from the gradients.

Return type:

float

class proxtorch.operators.GroupLasso(alpha: float, group_sizes: list)[source]#

Bases: ProxOperator

prox(x: Tensor, tau: float) Tensor[source]#

Proximal mapping of the Group Lasso operator.

Parameters:
Returns:

Result of the proximal mapping.

Return type:

torch.Tensor

class proxtorch.operators.Huber(alpha: float = 1.0, delta: float = 1.0)[source]#

Bases: ProxOperator

Proximal operator for the Huber penalty.

prox(x: Tensor, tau: float) Tensor[source]#

Apply the proximal operation for the Huber penalty.

Parameters:
  • x (Tensor) – Input tensor.

  • tau (float) – Proximal step size.

Returns:

Result after applying the Huber operation.

Return type:

Tensor

class proxtorch.operators.L1(alpha: float = 1.0)[source]#

Bases: ProxOperator

L1 norm proximal operator.

The L1 norm promotes sparsity in the tensor.

alpha#

Regularization strength.

Type:

float

prox(x: Tensor, tau: float) Tensor[source]#

Soft-thresholding for the L1 norm.

Parameters:
Returns:

Resultant tensor after soft-thresholding.

Return type:

torch.Tensor

class proxtorch.operators.L2(alpha: float = 1.0)[source]#

Bases: ProxOperator

L2 norm proximal operator.

This class provides methods for soft-thresholding and computation of the L2 norm.

alpha#

Regularization parameter.

Type:

float

prox(x: Tensor, tau: float) Tensor[source]#

Apply the L2 proximal operator.

Parameters:
Returns:

Resultant tensor after applying the proximal operator.

Return type:

torch.Tensor

proxtorch.operators.NuclearNorm#

alias of TraceNorm

class proxtorch.operators.TVL1_2D(alpha: float, l1_ratio=0.05, max_iter: int = 200, tol: float = 5e-05)[source]#

Bases: TVL1_3D

divergence(p: Tensor) Tensor[source]#

Compute the divergence of the tensor p.

Parameters:

p (torch.Tensor) – Input tensor.

Returns:

Divergence of the tensor p.

Return type:

torch.Tensor

gradient(x)#

Compute the gradient of the tensor x using finite differences.

Parameters:

x (torch.Tensor) – Input tensor.

Returns:

Gradients of the tensor x.

Return type:

torch.Tensor

prox(x: Tensor, lr: float) Tensor#

Iterative algorithm to compute the proximal mapping of the tensor.

Parameters:
Returns:

Tensor after applying the proximal operation.

Return type:

torch.Tensor

Notes

Total variation denoising aims to minimize the total variation of the image, which can be roughly described as the integral of the norm of the image gradient. As a result, it produces “cartoon-like” images, i.e., piecewise-constant images. For more details, refer to: http://en.wikipedia.org/wiki/Total_variation_denoising

This function implements the FISTA (Fast Iterative Shrinkage Thresholding Algorithm) algorithm of Beck et Teboulle, adapted to total variation denoising in “Fast gradient-based algorithms for constrained total variation image denoising and deblurring problems” (2009).

For more on bound constraints implementation, see the aforementioned Beck and Teboulle paper.

static tvl1_from_grad(gradients: Tensor) Tensor#

Calculate the TV from gradients.

Parameters:

gradients (torch.Tensor) – Gradient tensor.

Returns:

The TV value computed from the gradients.

Return type:

float

class proxtorch.operators.TVL1_3D(alpha: float, l1_ratio=0.05, max_iter: int = 200, tol: float = 5e-05)[source]#

Bases: ProxOperator

Class for the 3D Total Variation proximal operator.

divergence(p: Tensor) Tensor[source]#

Compute the divergence of the tensor p.

Parameters:

p (torch.Tensor) – Input tensor.

Returns:

Divergence of the tensor p.

Return type:

torch.Tensor

gradient(x)[source]#

Compute the gradient of the tensor x using finite differences.

Parameters:

x (torch.Tensor) – Input tensor.

Returns:

Gradients of the tensor x.

Return type:

torch.Tensor

prox(x: Tensor, lr: float) Tensor[source]#

Iterative algorithm to compute the proximal mapping of the tensor.

Parameters:
Returns:

Tensor after applying the proximal operation.

Return type:

torch.Tensor

Notes

Total variation denoising aims to minimize the total variation of the image, which can be roughly described as the integral of the norm of the image gradient. As a result, it produces “cartoon-like” images, i.e., piecewise-constant images. For more details, refer to: http://en.wikipedia.org/wiki/Total_variation_denoising

This function implements the FISTA (Fast Iterative Shrinkage Thresholding Algorithm) algorithm of Beck et Teboulle, adapted to total variation denoising in “Fast gradient-based algorithms for constrained total variation image denoising and deblurring problems” (2009).

For more on bound constraints implementation, see the aforementioned Beck and Teboulle paper.

static tvl1_from_grad(gradients: Tensor) Tensor[source]#

Calculate the TV from gradients.

Parameters:

gradients (torch.Tensor) – Gradient tensor.

Returns:

The TV value computed from the gradients.

Return type:

float

class proxtorch.operators.TV_2D(alpha: float, max_iter: int = 200, tol: float = 0.0001)[source]#

Bases: TVL1_2D

divergence(p: Tensor) Tensor#

Compute the divergence of the tensor p.

Parameters:

p (torch.Tensor) – Input tensor.

Returns:

Divergence of the tensor p.

Return type:

torch.Tensor

gradient(x)#

Compute the gradient of the tensor x using finite differences.

Parameters:

x (torch.Tensor) – Input tensor.

Returns:

Gradients of the tensor x.

Return type:

torch.Tensor

prox(x: Tensor, lr: float) Tensor#

Iterative algorithm to compute the proximal mapping of the tensor.

Parameters:
Returns:

Tensor after applying the proximal operation.

Return type:

torch.Tensor

Notes

Total variation denoising aims to minimize the total variation of the image, which can be roughly described as the integral of the norm of the image gradient. As a result, it produces “cartoon-like” images, i.e., piecewise-constant images. For more details, refer to: http://en.wikipedia.org/wiki/Total_variation_denoising

This function implements the FISTA (Fast Iterative Shrinkage Thresholding Algorithm) algorithm of Beck et Teboulle, adapted to total variation denoising in “Fast gradient-based algorithms for constrained total variation image denoising and deblurring problems” (2009).

For more on bound constraints implementation, see the aforementioned Beck and Teboulle paper.

static tvl1_from_grad(gradients: Tensor) Tensor#

Calculate the TV from gradients.

Parameters:

gradients (torch.Tensor) – Gradient tensor.

Returns:

The TV value computed from the gradients.

Return type:

float

class proxtorch.operators.TV_3D(alpha: float, max_iter: int = 200, tol: float = 0.0001)[source]#

Bases: TVL1_3D

divergence(p: Tensor) Tensor#

Compute the divergence of the tensor p.

Parameters:

p (torch.Tensor) – Input tensor.

Returns:

Divergence of the tensor p.

Return type:

torch.Tensor

gradient(x)#

Compute the gradient of the tensor x using finite differences.

Parameters:

x (torch.Tensor) – Input tensor.

Returns:

Gradients of the tensor x.

Return type:

torch.Tensor

prox(x: Tensor, lr: float) Tensor#

Iterative algorithm to compute the proximal mapping of the tensor.

Parameters:
Returns:

Tensor after applying the proximal operation.

Return type:

torch.Tensor

Notes

Total variation denoising aims to minimize the total variation of the image, which can be roughly described as the integral of the norm of the image gradient. As a result, it produces “cartoon-like” images, i.e., piecewise-constant images. For more details, refer to: http://en.wikipedia.org/wiki/Total_variation_denoising

This function implements the FISTA (Fast Iterative Shrinkage Thresholding Algorithm) algorithm of Beck et Teboulle, adapted to total variation denoising in “Fast gradient-based algorithms for constrained total variation image denoising and deblurring problems” (2009).

For more on bound constraints implementation, see the aforementioned Beck and Teboulle paper.

static tvl1_from_grad(gradients: Tensor) Tensor#

Calculate the TV from gradients.

Parameters:

gradients (torch.Tensor) – Gradient tensor.

Returns:

The TV value computed from the gradients.

Return type:

float

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

Bases: ProxOperator

Proximal operator for the trace norm regularization.

alpha#

Regularization strength.

Type:

float

prox(x: Tensor, tau: float) Tensor[source]#

Proximal operator for the trace norm regularization.

Parameters:
Returns:

Resultant tensor after applying the proximal operator.

Return type:

torch.Tensor