DPCalc: Calculate change-points using DP approach given number of...

Description Usage Arguments Author(s) References Examples

Description

This function is a part of DP approach. This function calculates change-points using DP approach given number of change-points.

Usage

1
DPCalc(x, y, n, p, Kstar, c)

Arguments

x

input data x

y

input data y

n

total number of data

p

dimension of data

Kstar

the given number of change-points

c

cost matrix c (can be computed by ComputeCost() function)

Author(s)

Bingwen Zhang

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
25
26
27
28
##---- 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, Kstar, c) 
{
    r <- matrix(0, ncol = n, nrow = Kstar + 1)
    s <- matrix(0, ncol = n, nrow = Kstar + 1)
    for (t in 1:n) {
        r[1, t] <- c[1, t]
        s[1, t] <- 1
    }
    for (K in 2:(Kstar + 1)) {
        for (t in K:n) {
            q = -1
            for (j in (K - 1):(t - 1)) {
                tmp <- r[K - 1, j] + c[j + 1, t]
                if (q > tmp || q < 0) {
                  q <- tmp
                  s[K, t] <- j + 1
                }
            }
            r[K, t] <- q
        }
    }
    return(list(r = r, s = s))
  }

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