Changeset 9018:3f6afcc6c5af in orange
 Timestamp:
 09/26/11 13:51:02 (3 years ago)
 Branch:
 default
 Convert:
 2ad96fac6746e20ff56e35f27258092de62105c3
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

orange/doc/Orange/rst/Orange.data.symmatrix.rst
r9008 r9018 5 5 ================================ 6 6 7 Class `Orange.data.SymMatrix` is symmetric (square) matrixof size fixed at8 construction time (and stored to the attribute dim).7 :obj:`SymMatrix` implements symmetric matrices of size fixed at 8 construction time (and stored in :obj:`SymMatrix.dim`). 9 9 10 10 .. class:: SymMatrix … … 16 16 .. attribute:: matrix_type 17 17 18 Value can be set to SymMatrix.Lower (0), SymMatrix.Upper(1),19 SymMatrix.Symmetric (2, default), SymMatrix.Lower_Filled(3) or20 SymMatrix.Upper_Filled(4).21 22 By setting it to Lower or Upper, we limit the matrix to the lower or23 upper half. Attempts to index anything above or below the diagonal,24 respectively, will yield an error. With Lower_Filled and Upper_Field,25 the elements of the other half (upper or lower, respectively)still26 exist , but are set to zero and can be read, butcannot be modified. The27 matrix type is by default initially set to symmetric, but can be changed18 Can be ``SymMatrix.Lower`` (0), ``SymMatrix.Upper`` (1), 19 ``SymMatrix.Symmetric`` (2, default), ``SymMatrix.Lower_Filled`` (3) or 20 ``SymMatrix.Upper_Filled`` (4). 21 22 If the matrix type is ``Lower`` or ``Upper``, indexing 23 above or below the diagonal, respectively, will fail. 24 With ``Lower_Filled`` and ``Upper_Filled``, 25 the elements upper or lower, respectively, still 26 exist and are set to zero, but they cannot be modified. The 27 default matrix type is ``Symmetric``, but can be changed 28 28 at any time. 29 29 30 If matrix type is changed to SymMatrix.Upper, it gets printed as30 If matrix type is ``Upper``, it is printed as: 31 31 32 32 >>> m.matrix_type = m.Upper … … 37 37 ( 16.000)) 38 38 39 Changing the type to SymMatrix.Lower_Filled will changethe printout to39 Changing the type to ``Lower_Filled`` changes the printout to 40 40 41 41 >>> m.matrix_type = m.Lower_Filled … … 48 48 .. method:: __init__(dim[, default_value]) 49 49 50 Construct a n empty symmetric matrix withthe given dimension.50 Construct a symmetric matrix of the given dimension. 51 51 52 52 :param dim: matrix dimension … … 65 65 :type instances: list of lists 66 66 67 The following example fills the symmetricmatrix created above with68 some data froma list::67 The following example fills a matrix created above with 68 data in a list:: 69 69 70 70 import Orange … … 82 82 matrix = Orange.data.SymMatrix(m) 83 83 84 SymMatrix also stores the diagonal elements. Here they are not 85 specified, so they are set to 0. If any line was shorter, the missing 86 elements would be set to 0 as well. Any line could also be longer, 87 spreading across the diagonal, in which case the constructor would check 88 for asymmetries. For instance, if the matrix started by:: 84 SymMatrix also stores diagonal elements. They are set 85 to zero, if they are not specified. The missing elements 86 (shorter lists) are set to zero as well. If a list 87 spreads over the diagonal, the constructor checks 88 for asymmetries. For instance, the matrix 89 90 :: 89 91 90 92 m = [[], 91 93 [ 3, 0, f], 92 [ 2, 4] , ...94 [ 2, 4]] 93 95 94 this would only be OK if f equals 2; otherwise, the matrix would be 95 asymmetric. 96 97 Finally, no line can be longer than the total number of lines. Here we 98 have 10 rows, so no row may have more than 10 columns. 96 is only OK if f equals 2. Finally, no row can be longer 97 than matrix size. 99 98 100 99 .. method:: get_values() … … 138 137  139 138 140 Indexing is implemented so that order of indices is unimportant (unless set 141 otherwise with the matrix_type attribute). For example, if m is an instance of 142 SymMatrix, then m[2, 4] addresses the same element as m[4, 2]. 139 For symmetric matrices the order of indices is not important: 140 if ``m`` is a SymMatrix, then ``m[2, 4]`` addresses the same element as ``m[4, 2]``. 143 141 144 `symmatrix.py`_145 146 142 .. literalinclude:: code/symmatrix.py 147 143 :lines: 16 148 144 149 Although only the lower left half of the matrix is set , we have actually150 constructed a whole symmetric matrix.145 Although only the lower left half of the matrix was set explicitely, 146 the whole matrix is constructed. 151 147 152 148 >>> print m … … 156 152 ( 4.000, 8.000, 12.000, 16.000)) 157 153 158 Other manipulations also respect the symmetricity, for instance, increasing an 159 element m[3, 2] += 15 will also increase m[2, 3] (since this is, in fact, one 160 and the same element). 161 162 Index entire rows by using a single index instead of two: 154 Entire rows are indexed with a single index. They can be iterated 155 over in a for loop or sliced (with, for example, ``m[:3]``): 163 156 164 157 >>> print m[1] 165 158 (3.0, 6.0, 9.0, 0.0) 166 167 Iterate over the matrix using a for loop:168 169 159 >>> m.matrix_type = m.Lower 170 160 >>> for row in m: … … 175 165 (4.0, 8.0, 12.0, 16.0) 176 166 177 Slicing also works. For example, m[:3] is a tuple containing the first three178 lines of the matrix (again represented as tuples).179 180 .. _symmatrix.py: code/symmatrix.py
Note: See TracChangeset
for help on using the changeset viewer.