Package parsimony :: Package functions :: Package nesterov :: Module tv
[hide private]
[frames] | no frames]

Module tv

source code

The :mod:`parsimony.functions.nesterov.tv` module contains the loss function and helper functions for Total variation, TV, smoothed using Nesterov's technique.

Created on Mon Feb 3 10:46:47 2014

Copyright (c) 2013-2014, CEA/DSV/I2BM/Neurospin. All rights reserved.


Author: Tommy Löfstedt, Edouard Duchesnay

License: BSD 3-clause.

Classes [hide private]
  TotalVariation
The smoothed Total variation (TV) function
Functions [hide private]
 
A_from_mask(*args, **kwargs) source code
 
linear_operator_from_mask(mask, offset=0, weights=None)
Generates the linear operator for the total variation Nesterov function from a mask for a 3D image.
source code
 
A_from_subset_mask(*args, **kwargs) source code
 
linear_operator_from_subset_mask(mask, weights=None)
Generates the linear operator for the total variation Nesterov function from a mask for a 3D image.
source code
 
A_from_shape(*args, **kwargs) source code
 
linear_operator_from_shape(shape, weights=None)
Generates the linear operator for the total variation Nesterov function from the shape of a 1D, 2D or 3D image.
source code
 
A_from_mesh(*args, **kwargs) source code
 
nesterov_linear_operator_from_mesh(*args, **kwargs) source code
 
linear_operator_from_mesh(mesh_coord, mesh_triangles, mask=None, offset=0, weights=None)
Generates the linear operator for the total variation Nesterov function from a mesh.
source code
Variables [hide private]
  __package__ = 'parsimony.functions.nesterov'
Function Details [hide private]

A_from_mask(*args, **kwargs)

source code 
Decorators:
  • @utils.deprecated("linear_operator_from_mask")

linear_operator_from_mask(mask, offset=0, weights=None)

source code 
Generates the linear operator for the total variation Nesterov function
from a mask for a 3D image.

Parameters
----------
mask : Numpy array of integers. The mask has the same shape as the original
        data. Non-null values correspond to columns of X. Groups may be
        defined using different values in the mask. TV will be applied
        within groups of the same value in the mask.

offset: Non-negative integer. The index of the first column, variable,
        where TV applies. This is different from penalty_start which
        define where the penalty applies. The offset defines where TV
        applies within the penalised variables.

            Example: X := [Intercept, Age, Weight, Image]. Intercept is
            not penalized, TV does not apply on Age and Weight but only on
            Image. Thus: penalty_start = 1, offset = 2 (skip Age and
            Weight).

weights : Numpy array. The weight put on the gradient of every point.
        Default is weight 1 for each point, or equivalently, no weight. The
        weights is a numpy array of the same shape as mask.

A_from_subset_mask(*args, **kwargs)

source code 
Decorators:
  • @utils.deprecated("linear_operator_from_subset_mask")

linear_operator_from_subset_mask(mask, weights=None)

source code 
Generates the linear operator for the total variation Nesterov function
from a mask for a 3D image.

The binary mask marks a subset of the variables that are supposed to be
smoothed. The mask has the same size as the input and output image.

Parameters
----------
mask : Numpy array. The mask. The mask does not involve any intercept
        variables.

weights : Numpy array. The weight put on the gradient of every point.
        Default is weight 1 for each point, or equivalently, no weight. The
        weights is a numpy array of the same shape as mask.

A_from_shape(*args, **kwargs)

source code 
Decorators:
  • @utils.deprecated("linear_operator_from_shape")

linear_operator_from_shape(shape, weights=None)

source code 
Generates the linear operator for the total variation Nesterov function
from the shape of a 1D, 2D or 3D image.

Parameters
----------
shape : List or tuple with 1, 2 or 3 integers. The shape of the 1D, 2D or
        3D image. shape has the form X, (X,), (Y, X) or (Z, Y, X), where Z
        is the number of "layers", Y is the number of rows and X is the
        number of columns. The shape does not involve any intercept
        variables.

weights : Sequence, e.g. list or numpy (p-by-1) array. Weights put on the
        groups. Default is weight 1 for each group, i.e. no weight.

A_from_mesh(*args, **kwargs)

source code 
Decorators:
  • @utils.deprecated("linear_operator_from_mesh")

nesterov_linear_operator_from_mesh(*args, **kwargs)

source code 
Decorators:
  • @utils.deprecated("linear_operator_from_mesh")

linear_operator_from_mesh(mesh_coord, mesh_triangles, mask=None, offset=0, weights=None)

source code 
Generates the linear operator for the total variation Nesterov function
from a mesh.

Parameters
----------
mesh_coord : Numpy array [n, 3] of float.

mesh_triangles : Numpy array, n_triangles-by-3. The (integer) indices of
        the three nodes forming the triangle.

mask : Numpy array (shape (n,)) of integers/boolean. Non-null values
        correspond to columns of X. Groups may be defined using different
        values in the mask. TV will be applied within groups of the same
        value in the mask.

offset : Non-negative integer. The index of the first column, variable,
        where TV applies. This is different from penalty_start which
        define where the penalty applies. The offset defines where TV
        applies within the penalised variables.

            Example: X := [Intercept, Age, Weight, Image]. Intercept is
            not penalized, TV does not apply on Age and Weight but only on
            Image. Thus: penalty_start = 1, offset = 2 (skip Age and
            Weight).

weights : Numpy array. The weight put on the gradient of every point.
        Default is weight 1 for each point, or equivalently, no weight. The
        weights is a numpy array of the same shape as mask.

Returns
-------
out1 : List or sparse matrices. Linear operator for the total variation
       Nesterov function computed over a mesh.

out2 : Integer. The number of compacts.

Examples
--------
>>> import numpy as np
>>> import parsimony.functions.nesterov.tv as tv_helper
>>> mesh_coord = np.array([[0, 0], [1, 0], [0, 1], [1, 1], [0, 2], [1, 2]])
>>> mesh_triangles = np.array([[0 ,1, 3], [0, 2 ,3], [2, 3, 5], [2, 4, 5]])
>>> A, _ = tv_helper.nesterov_linear_operator_from_mesh(mesh_coord,
...                                                     mesh_triangles)