SlipGURU Dipartimento di Informatica e Scienze dell'Informazione Università Degli Studi di Genova

Common and low-level functions (paddle.common)

This module implements some common and low-level functions used both by paddle.dual and paddle.tight.

Evalutation of dictionaries

paddle.common.print_frame_assessment(D)

Prints an evalutation of D as a frame.

This functions computes and prints the following information for D:

  • the frame bounds (computed from the eigenvalues)
  • the equivalent tight frame constant \alpha
  • if there is a violation of the fundamental inequality
  • the value of the frame potential and its theoretical lower bound
  • the relative error between the frame operator DD^T and \alpha I
  • the mutual coherence
Parameters :

D : (d, K) ndarray

Frame matrix

paddle.common.coherence(D)

Compute the mutual coherence of D.

Parameters :

D : (d, K) ndarray

A dictionary.

Returns :

c : float

The mutual coherence.

paddle.common.cumcoherence(D, C=None)

Compute the cumulative mutual/cross coherence of D/(D,C).

Parameters :

D : (d, K) ndarray

A dictionary.

C : (K, d) ndarray

A dual of the dictionary (optional).

Returns :

c : (K-1,) ndarray

The cumulative coherence.

Misc

paddle.common._cost_rec(D, X, U, pars=None)

Reconstruction error term.

Computes the normalized reconstruction error \|X-DU\|_F^2/(d*N).

Parameters :

D : (d, K) ndarray

Dictionary.

X : (d, N) ndarray

Input data.

U : (K, N) ndarray

Encondings.

pars : not used

Returns :

rec_err : float

Reconstruction error.

paddle.common._cost_cod(C, X, U, pars)

Coding error term.

Computes the normalized and weighted coding error \eta\|U-CX\|_F^2/(K*N).

Parameters :

C : (K, d) ndarray

Dual Dictionary.

X : (d, N) ndarray

Input data.

U : (K, N) ndarray

Encondings.

pars : dict with at least key eta

pars[“eta”] is the \eta parameter weighting the coding error

Returns :

cod_err : float

Coding error.

paddle.common._replaceAtoms(X, U, D, replace)

Replaces some atoms.

Replaces the atoms of D listed in replace with the worst reconstructed examples of X. Only U is changed (and returned).

Parameters :

X : (d, N) ndarray

Input data

U : (K, N) ndarray

Current encodings of the input data X

D : (d, K) ndarray

Current dictionary

replace : list of integer

List of indexes of the atoms to be replaced

Returns :

U : (K, N) ndarray

The updated encodings.

paddle.common._saveDict(D, U, Nrows=8, Ncols=25, path='./savedDict.png', sorted=False)

Saves a figure of a dictionary atoms.

Creates a table with Nrows x Ncols images of the atoms of D, drawn as square image patches. It assumes that the dimension d of the atoms is a perfect square.

Parameters :

D : (d, K) ndarray

Dictionary

U : (K, N) ndarray

Encodings

Nrows : integer

Number of rows in the figure

Ncols : integer

Number of columns in the figure

path : string

Name of the file where the figure will be saved

sorted : bool

If True, the atoms will be sorted according to their usage in U

paddle.common.img2patches(img, size, Nmax=0)

Extract patches from an image.

Parameters :

img : (rows, cols) or (rows, cols, channels) ndimage

Input image.

size : 2-tuple

Size of the patches

Nmax : int

If > 0, number of patches to sample randomly

paddle.common.sparsity(X, axis=0)
paddle.common.gendata(d, N, s, K, D=None, rnd=<built-in method normal of mtrand.RandomState object at 0x7f1c7b3c1660>, dtype=<type 'numpy.float32'>)

Generates N vectors in d dimensions. Each vector is the linear combinations of s atoms sampled from a dictionary of size K.

rnd is a function returning an array of randomly generated numbers. The shape of the array is passed as the keyword argument size.

Table Of Contents