spam operations             package:spam             R Documentation

_B_a_s_i_c _L_i_n_e_a_r _A_l_g_e_b_r_a _f_o_r _S_p_a_r_s_e _M_a_t_r_i_c_e_s

_D_e_s_c_r_i_p_t_i_o_n:

     Basic linear algebra operations for sparse matrices of class
     'spam'.

_D_e_t_a_i_l_s:

     Linear algebra operations for matrices of class  'spam' are
     designed to behave exactly as for  regular matrices.  In
     particular, matrix multiplication, transpose, addition, 
     subtraction and various logical operations should work as with the
     conventional dense form of matrix storage, as does indexing,
     rbind, cbind, and diagonal assignment and extraction (see for
     example 'diag'). Further functions with identical behavior are
     'dim' and thus 'nrow', 'ncol'.

     The function 'norm' calculates the (matrix-)norm of the argument.
     The argument 'type' specifies the 'l1' norm, 'sup' or max norm
     (default), or the Frobenius or Hilbert-Schmidt ('frobenius/hs')
     norm. Partial matching can be used. For example, 'norm' is used to
     check for symmetry in the function 'chol' by computing the norm of
     the difference between the matrix and its transpose

     The operator '%d*%' efficiently multiplies a diagonal matrix (in
     vector form) and a sparse matrix and is used for compatibility
     with the package fields. More specifically, this method is used in
     the internal functions of 'Krig' to make the code more readable.
     It avoids having a branch in the source code to handle the
     diagonal or nondiagonal cases.  Note that this operator is not
     symmetric: a vector in the left argument is interpreted as a
     diagonal matrix and a vector in the right argument is kept as a
     column vector.

     The operator '%d+%' efficiently adds a diagonal matrix (in vector
     form) and a sparse matrix, similarly to the operator '%d+%'.

_R_e_f_e_r_e_n_c_e_s:

     Some Fortran functions are based on  <URL:
     http://www-users.cs.umn.edu/~saad/software/SPARSKIT/sparskit.html>

_S_e_e _A_l_s_o:

     'spam' for coercion and other class relations involving the sparse
     matrix classes.

_E_x_a_m_p_l_e_s:

     # create a weight matrix and scale it:
     ## Not run: 
     wij <- distmat
     # with distmat from a nearest.dist(..., diag=FALSE, upper=TRUE) call

     n <- dim(wij)[1]

     wij@entries <- kernel( wij@entries, h) # for some function kernel
     wij <- wij + t(wij) + diag.spam(n)     # adjust from diag=FALSE, upper=TRUE

     sumwij <- wij %*% rep(1,n)
         # row scaling:
         #   wij@entries <- wij@entries/sumwij[ wij@colindices]
         # col scaling:
     wij@entries <- wij@entries/sumwij[ rep(1:n, diff(wij@rowpointers))]
     ## End(Not run)

