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(*args, **kwargs)

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:
isfldlist

List of field names for iteration statistics namedtuple

isxmapdict

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

isdmapdict

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

evlmapdict

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

hdrtxtlist

List of column header titles for verbose iteration statistics display

hdrmapdict

Dictionary mapping column header titles to IterationStats entries

fmtmapdict, 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:
jint

Iteration number

tfloat

Iteration time

isxnamedtuple

IterationStats namedtuple from X step object

isdnamedtuple

IterationStats namedtuple from D step object

evldict

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:
itstnamedtuple

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(*args, **kwargs)[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:
xstepbpdn (or similar interface) object

Object handling X update step

dstepcmod (or similar interface) object

Object handling D update step

optDictLearn.Options object

Algorithm options

iscIterStatsConfig object

Iteration statistics and header display configuration

class Options(opt=None)[source]

Bases: 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:
optdict or None, optional (default None)

DictLearn algorithm options

defaults = {'Callback': None, 'IterTimer': 'solve', 'MaxMainIter': 1000, 'StatusHeader': True, 'Verbose': False}

Default content and allowed dict keys

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.