manual:wmat
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
manual:wmat [2013/10/09 08:53] – Adds example matrix header zenke | manual:wmat [2014/12/02 10:03] (current) – Fixes bug in example zenke | ||
---|---|---|---|
Line 1: | Line 1: | ||
'' | '' | ||
+ | |||
+ | See also [[SparseConnection]]. | ||
+ | |||
+ | ====== File structure ====== | ||
The header of a typical weight matrix looks the following: | The header of a typical weight matrix looks the following: | ||
Line 18: | Line 22: | ||
</ | </ | ||
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. | 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). | ||
+ | |||
+ | |||
+ | ===== Loading Matrix Market files in Python for analysis ===== | ||
+ | |||
+ | In Python Auryn' | ||
+ | |||
+ | <code python> | ||
+ | from scipy.sparse import * | ||
+ | from scipy.io import mmread | ||
+ | |||
+ | A = mmread(' | ||
+ | </ | ||
+ | '' | ||
+ | |||
+ | |||
+ | |||
+ | ===== Saving Matrix Market files in Python ===== | ||
+ | |||
+ | 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: | ||
+ | <code python> | ||
+ | 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(' | ||
+ | </ | ||
+ | |||
+ | 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 '' |
manual/wmat.1381308823.txt.gz · Last modified: 2013/10/09 08:53 (external edit)