sporco.dictlrn.dictlrn

Dictionary learning based on ADMM sparse coding and dictionary updates

Classes

IterStatsConfig(isfld, isxmap, isdmap, …) Configuration object for general dictionary learning algorithm iteration statistics.
_DictLearn_Meta(*args) Metaclass for DictLearn class that handles intialisation of the object initialisation timer and stopping this timer at the end of initialisation.
DictLearn(xstep, dstep[, opt, isc]) General dictionary learning class that supports alternation between user-specified sparse coding and dictionary update steps, each of which is based on an ADMM algorithm.

Class Descriptions

class sporco.dictlrn.dictlrn.IterStatsConfig(isfld, isxmap, isdmap, evlmap, hdrtxt, hdrmap, fmtmap=None)[source]

Bases: object

Configuration object for general dictionary learning algorithm iteration statistics.

Parameters:
isfld : list

List of field names for iteration statistics namedtuple

isxmap : dict

Dictionary mapping iteration statistics namedtuple field names to field names in corresponding X step object iteration statistics namedtuple

isdmap : dict

Dictionary mapping iteration statistics namedtuple field names to field names in corresponding D step object iteration statistics namedtuple

evlmap : dict

Dictionary mapping iteration statistics namedtuple field names to labels in the dict returned by DictLearn.evaluate

hdrtxt : list

List of column header titles for verbose iteration statistics display

hdrmap : dict

Dictionary mapping column header titles to IterationStats entries

fmtmap : dict, optional (default None)

A dict providing a mapping from field header strings to print format strings, providing a mechanism for fields with print formats that depart from the standard format

fwiter = 4

Field width for iteration count display column

fpothr = 2

Field precision for other display columns

iterstats(j, t, isx, isd, evl)[source]

Construct IterationStats namedtuple from X step and D step IterationStats namedtuples.

Parameters:
j : int

Iteration number

t : float

Iteration time

isx : namedtuple

IterationStats namedtuple from X step object

isd : namedtuple

IterationStats namedtuple from D step object

evl : dict

Dict associating result labels with values computed by DictLearn.evaluate

printheader()[source]

Print status display header and separator strings.

printseparator()[source]

Print status display separator string.

printiterstats(itst)[source]

Print iteration statistics.

Parameters:
itst : namedtuple

IterationStats namedtuple as returned by iterstats

class sporco.dictlrn.dictlrn._DictLearn_Meta(*args)[source]

Bases: type

Metaclass for DictLearn class that handles intialisation of the object initialisation timer and stopping this timer at the end of initialisation.

class sporco.dictlrn.dictlrn.DictLearn(xstep, dstep, opt=None, isc=None)[source]

Bases: object

General dictionary learning class that supports alternation between user-specified sparse coding and dictionary update steps, each of which is based on an ADMM algorithm.

Parameters:
xstep : bpdn (or similar interface) object

Object handling X update step

dstep : cmod (or similar interface) object

Object handling D update step

opt : DictLearn.Options object

Algorithm options

isc : IterStatsConfig object

Iteration statistics and header display configuration

class Options(opt=None)[source]

Bases: sporco.cdict.ConstrainedDict

General dictionary learning algorithm options.

Options:

Verbose : Flag determining whether iteration status is displayed.

StatusHeader : Flag determining whether status header and separator are displayed.

IterTimer : Label of the timer to use for iteration times.

MaxMainIter : Maximum main iterations.

Callback : Callback function to be called at the end of every iteration.

Parameters:
opt : dict or None, optional (default None)

DictLearn algorithm options

solve()[source]

Start (or re-start) optimisation. This method implements the framework for the alternation between X and D updates in a dictionary learning algorithm. There is sufficient flexibility in specifying the two updates that it calls that it is usually not necessary to override this method in derived clases.

If option Verbose is True, the progress of the optimisation is displayed at every iteration. At termination of this method, attribute itstat is a list of tuples representing statistics of each iteration.

Attribute timer is an instance of util.Timer that provides the following labelled timers:

init: Time taken for object initialisation by __init__

solve: Total time taken by call(s) to solve

solve_wo_func: Total time taken by call(s) to solve, excluding time taken to compute functional value and related iteration statistics

solve_wo_rsdl : Total time taken by call(s) to solve, excluding time taken to compute functional value and related iteration statistics as well as time take to compute residuals and implemented AutoRho mechanism

post_xstep()[source]

Handle passing result of xstep to dstep

post_dstep()[source]

Handle passing result of dstep to xstep

evaluate()[source]

Evaluate results (e.g. functional value) of previous iteration

getdict()[source]

Get final dictionary

getcoef()[source]

Get final coefficient map array

getitstat()[source]

Get iteration stats as named tuple of arrays instead of array of named tuples.