Changeset 9018:3f6afcc6c5af in orange


Ignore:
Timestamp:
09/26/11 13:51:02 (3 years ago)
Author:
markotoplak
Branch:
default
Convert:
2ad96fac6746e20ff56e35f27258092de62105c3
Message:

Orange.data.SymMatrix changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orange/doc/Orange/rst/Orange.data.symmatrix.rst

    r9008 r9018  
    55================================ 
    66 
    7 Class `Orange.data.SymMatrix` is symmetric (square) matrix of size fixed at  
    8 construction time (and stored to the attribute dim). 
     7:obj:`SymMatrix` implements symmetric matrices of size fixed at  
     8construction time (and stored in :obj:`SymMatrix.dim`). 
    99 
    1010.. class:: SymMatrix 
     
    1616    .. attribute:: matrix_type  
    1717 
    18         Value can be set to SymMatrix.Lower (0), SymMatrix.Upper (1),  
    19         SymMatrix.Symmetric (2, default), SymMatrix.Lower_Filled (3) or 
    20         SymMatrix.Upper_Filled (4).  
    21          
    22         By setting it to Lower or Upper, we limit the matrix to the lower or  
    23         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) still  
    26         exist, but are set to zero and can be read, but cannot be modified. The  
    27         matrix type is by default initially set to symmetric, but can be changed  
     18        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  
    2828        at any time. 
    2929 
    30         If matrix type is changed to SymMatrix.Upper, it gets printed as 
     30        If matrix type is ``Upper``, it is printed as: 
    3131 
    3232        >>> m.matrix_type = m.Upper 
     
    3737         (                        16.000)) 
    3838 
    39         Changing the type to SymMatrix.Lower_Filled will change the printout to 
     39        Changing the type to ``Lower_Filled`` changes the printout to 
    4040 
    4141        >>> m.matrix_type = m.Lower_Filled 
     
    4848    .. method:: __init__(dim[, default_value]) 
    4949 
    50         Construct an empty symmetric matrix with the given dimension. 
     50        Construct a symmetric matrix of the given dimension. 
    5151 
    5252        :param dim: matrix dimension 
     
    6565        :type instances: list of lists 
    6666         
    67         The following example fills the symmetric matrix created above with 
    68         some data from a list:: 
     67        The following example fills a matrix created above with 
     68        data in a list:: 
    6969 
    7070            import Orange 
     
    8282            matrix = Orange.data.SymMatrix(m) 
    8383 
    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        :: 
    8991 
    9092            m = [[], 
    9193                 [ 3,  0, f], 
    92                  [ 2,  4], ... 
     94                 [ 2,  4]] 
    9395     
    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.   
    9998 
    10099    .. method:: get_values() 
     
    138137------------------- 
    139138 
    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]. 
     139For symmetric matrices the order of indices is not important:  
     140if ``m`` is a SymMatrix, then ``m[2, 4]`` addresses the same element as ``m[4, 2]``. 
    143141 
    144 `symmatrix.py`_ 
    145      
    146142.. literalinclude:: code/symmatrix.py 
    147143    :lines: 1-6 
    148144 
    149 Although only the lower left half of the matrix is set , we have actually  
    150 constructed a whole symmetric matrix. 
     145Although only the lower left half of the matrix was set explicitely,  
     146the whole matrix is constructed. 
    151147 
    152148>>> print m 
     
    156152 ( 4.000,  8.000, 12.000, 16.000)) 
    157153  
    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: 
     154Entire rows are indexed with a single index. They can be iterated 
     155over in a for loop or sliced (with, for example, ``m[:3]``): 
    163156 
    164157>>> print m[1] 
    165158(3.0, 6.0, 9.0, 0.0) 
    166  
    167 Iterate over the matrix using a for loop: 
    168  
    169159>>> m.matrix_type = m.Lower 
    170160>>> for row in m: 
     
    175165(4.0, 8.0, 12.0, 16.0) 
    176166 
    177 Slicing also works. For example, m[:3] is a tuple containing the first three  
    178 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.