costMatrix            package:tilingArray            R Documentation

_S_e_g_m_e_n_t_a_t_i_o_n _c_o_s_t _m_a_t_r_i_x

_D_e_s_c_r_i_p_t_i_o_n:

     This function calculates the cost matrix for the segmentation
     model

_U_s_a_g_e:

     costMatrix(x, maxk)

_A_r_g_u_m_e_n_t_s:

       x: Numeric vector of length 'n' or matrix with 'n' rows and 'd'
          columns, where 'n' is the number of sample points and 'd' the
          number of replicate measurements (e.g. from multiple arrays).

    maxk: Positive integer.

_D_e_t_a_i_l_s:

     See the package vignette _Calculation of the cost matrix_.

_V_a_l_u_e:

     Matrix with 'maxk' rows and 'length(x)' columns.

_A_u_t_h_o_r(_s):

     W. Huber

_E_x_a_m_p_l_e_s:

     d = 4
     x = apply(matrix(rnorm(200), ncol=d), 2, cumsum)
     maxk = 50
      
     G = costMatrix(x, maxk=maxk)
      
     G.pedestrian = matrix(NA, nrow=nrow(G), ncol=ncol(G))
     for(i in 1:(ncol(G)))
       for(k in 1:min(nrow(G), nrow(x)-i+1))
         G.pedestrian[k, i] = (k*d-1)*var(as.vector(x[i:(i+k-1), ]))
      
     stopifnot(identical(is.na(G), is.na(G.pedestrian)))
     stopifnot(max(abs(G-G.pedestrian), na.rm=TRUE) <= 1e-6)

