MDP offers some additional utilities of general interest in the mdp.utils module. Refer to the API for the full documentation and interface description.
This class stores an empirical covariance matrix that can be updated incrementally. A call to the fix method returns the current state of the covariance matrix, the average and the number of observations, and resets the internal data.
Note that the internal sum is a standard __add__ operation. We are not using any of the fancy sum algorithms to avoid round off errors when adding many numbers. If you want to contribute a CovarianceMatrix class that uses such algorithms we would be happy to include it in MDP. For a start see the Python recipe by Raymond Hettinger. For a review about floating point arithmetic and its pitfalls see What every computer scientist should know about floating-point arithmetic by David Goldberg, ACM Computing Surveys, Vol 23, No 1, March 1991.
A fully configurable text-mode progress info box tailored to the command-line die-hards. To get a progress info box for your loops use it like this:
>>> for i in progressinfo(sequence):
... do_something(i)
You can also use it with generators, files or any other iterable object, but in this case you have to specify the total length of the sequence:
>>> for line in progressinfo(open_file, nlines):
... do_something(line)
A few examples of the available layouts:
[===================================73%==============>...................]
Progress: 67%[======================================> ]
23% [02:01:28] - [00:12:37]
Rotate in-place a NxM data matrix in the plane defined by the columns when observation are stored on rows. Observations are rotated counterclockwise. This corresponds to the following matrix-multiplication for each data-point (unchanged elements omitted):
[ cos(angle) -sin(angle) [ x_i ]
sin(angle) cos(angle) ] * [ x_j ]
The mdp.utils module contains some classes and helper function to display animated results in a Webbrowser. This works by creating an HTML file with embedded JavaScript code, which dynamically loads image files (the images contain the content that you want to animate and can for example be created with matplotlib). MDP internally uses the open source Templete templating libray, written by David Bau.
The easiest way to create a slideshow it to use one of these two helper function:
Note that there are also two demos in the Examples section Slideshow.
MDP contains mdp.graph, a lightweight package to handle directed graphs.
Represent a directed graph. This class contains several methods to create graph structures and manipulate them, among which
The tree is specified with a nested list of tuple, in a LISP-like notation. The values specified in the list become the values of the single nodes. Return an equivalent nested list with the nodes instead of the values.
Example::
>>> g = mdp.graph.Graph()
>>> a = b = c = d = e = None
>>> nodes = g.add_tree( (a, b, (c, d ,e)) )
Graph g corresponds to this tree, with all node values being None:
a
/ \
b c
/ \
d e
topological_sort: Perform a topological sort of the nodes.
dfs, undirected_dfs: Perform Depth First sort.
bfs, undirected_bfs: Perform Breadth First sort.
connected_components: Return a list of lists containing the nodes of all connected components of the graph.
is_weakly_connected: Return True if the graph is weakly connected.