ComputeCost: Compute cost matrix for each interval

Description Usage Arguments References Examples

Description

This function is a part of DP approach. This function computes cost matrix for each interval.

Usage

1
ComputeCost(x, y, n, p)

Arguments

x

input data x

y

input data y

n

total number of samples

p

dimension of data

References

Bingwen Zhang, Jun Geng and Lifeng Lai, Detecting changes in regression models via sparse group lasso, http://users.wpi.edu/~bzhang/icassp_v1.pdf

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (x, y, n, p) 
{
    c <- matrix(0, n, n)
    for (i in 1:n) {
        A <- matrix(0, p, p)
        B <- matrix(0, p, 1)
        for (j in i:n) {
            A <- A + x[j, ] %*% t(x[j, ])
            B <- B + y[j] * x[j, ]
            alpha <- ginv(A) %*% B
            tmp <- 0
            for (t in i:j) {
                tmp <- tmp + (y[t] - (t(x[t, ]) %*% alpha)[1])^2
            }
            c[i, j] <- tmp
        }
    }
    return(c)
  }

boris109able/ChangePointCalc documentation built on May 13, 2019, 12:34 a.m.