wmat files are used to store weight matrices in the MatrixMarket format, which can be exchanged easily with MATLAB and other software (http://en.wikipedia.org/wiki/Matrix_Market_exchange_formats). Since in many cases connection matrices are sparse, Auryn uses the
coordinate real format, which needs to be kept in row major order, since it directly maps Auryn's internal sparse matrix format SimpleMatrix.
See also SparseConnection.
The header of a typical weight matrix looks the following:
%%MatrixMarket matrix coordinate real general % Auryn weight matrix. Has to be kept in row major order for load operation. % Connection name: Poisson->E % Locked range: 8 % 1000 4000 49952 1 57 6.971942e-02 1 129 6.517706e-02 1 233 6.546227e-02 1 385 5.322644e-02 1 457 7.060073e-02 1 617 6.956130e-02 ...
It contains some generic header lines and comments followed by the Connection name (which is not read upon load) and some additional information to identify from on how many ranks the weight matrix was residing. The first line without percent sign specifies the dimensionality followed by the number of nonzero elements. The latter is used by SimpleMatrix to reserve exactly the right amount of memory. After that, the existing connection elements are listed in the format: row (from) column (to) value.
Nota bene: Cells in the wmat file are indexed starting from 1 (unlike everywhere else in Auryn, where we adapt the C convention and start numbering arrays with 0).
In Python Auryn's wmat files can be loaded or saved using existing SciPy functionality (http://docs.scipy.org/doc/scipy/reference/io.html). To load the output file
output.wmat in Python it is sufficient to invoke the following code:
from scipy.sparse import * from scipy.io import mmread A = mmread('output.wmat')
A now contains the Auryn output weight matrix
output.wmat as a sparse matrix for further processing.
Likewise, a structured matrix can be prepared in Python and then be loaded in Auryn. To do so, use code along the lines of the following snipped:
from scipy.sparse import * from scipy.io import mmwrite # code which generates the matrix A sw = csr_matrix(A) # ensures row major format in COO output mmwrite('save.wmat',sw)
The additional conversion step to a csr_matrix is necessary to ensure the correct ordering of entries in the text file. If this step is omitted, Auryn might not be able to parse the sparse matrix and will throw a runtime exception.
Note that in many cases SciPy will append the file extension
mtx to the output file which will require you to rename it to wmat afterwards.