SynthesizeData: Generate synthesized data used by SGL approach

Description Usage Arguments Author(s) References Examples

Description

Generate synthesized data used by SGL approach

Usage

1
SynthesizeData(ChangePoints, sigma1, sigma2, n = 1000, p = 20, s = 4, coefficients = NULL)

Arguments

ChangePoints

list of change-points set by user

sigma1

variance of signal

sigma2

variance of noise

n

total number of data generated

p

dimension of data generated

s

sparsity level of coefficients

coefficients

matrix of coefficients of each interval set by user

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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
##---- 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 (ChangePoints, sigma1, sigma2, n = 1000, p = 20, s = 4, coefficients = NULL) 
{
    np <- n * p
    KReal <- length(ChangePoints)
    TmpPoints <- c(1, ChangePoints, n + 1)
    x <- matrix(rnorm(n * p) * sigma1, ncol = p, nrow = n)
    XTilde <- matrix(NA, n, np)
    for (i in 1:n) {
        for (j in 1:i) {
            XTilde[i, ((j - 1) * p + 1):(j * p)] <- x[i, ]
        }
    }
    if (is.null(coefficients)) {
        coefficients <- matrix(0, KReal + 1, p)
        for (i in 1:(KReal + 1)) {
            if (i%%2 == 1) {
                coefficients[i, 1:s] <- 2 * rep.int(1, s)
            }
            else {
                coefficients[i, 1:s] <- -2 * rep.int(1, s)
            }
        }
    }
    beta <- matrix(NA, n, p)
    for (i in 1:(KReal + 1)) {
        beta[TmpPoints[i]:(TmpPoints[i + 1] - 1), ] <- t(matrix(rep(coefficients[i, 
            ], TmpPoints[i + 1] - TmpPoints[i]), p, TmpPoints[i + 
            1] - TmpPoints[i]))
    }
    y <- matrix(NA, n, 1)
    for (i in 1:n) {
        y[i] <- (x[i, ] %*% beta[i, ])[1] + matrix(rnorm(1) * 
            sigma2, ncol = 1, nrow = 1)
    }
    data <- list(x = XTilde, y = y, coefficients = coefficients, 
        beta = beta)
    return(data)
  }

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