\HeaderA{costMatrix}{Segmentation cost matrix}{costMatrix}
\keyword{manip}{costMatrix}
\begin{Description}\relax
This function calculates the cost matrix for the segmentation model
\end{Description}
\begin{Usage}
\begin{verbatim}
costMatrix(x, maxk)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] Numeric vector of length \code{n} or matrix with \code{n} rows and \code{d}
columns, where \code{n} is the number of sample points and \code{d}
the number of replicate measurements (e.g. from multiple arrays).
\item[\code{maxk}] Positive integer.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
See the vignette costMatrix.tex (.pdf) in the \code{inst/doc} directory of
the package.
\end{Details}
\begin{Value}
Matrix with \code{maxk} rows and \code{length(x)} columns.
\end{Value}
\begin{Author}\relax
W. Huber
\end{Author}
\begin{Examples}
\begin{ExampleCode}
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)
\end{ExampleCode}
\end{Examples}

