Skip to content

Commit

Permalink
Remove useless examples
Browse files Browse the repository at this point in the history
  • Loading branch information
doccstat committed May 30, 2024
1 parent 88637d3 commit eeca55f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 47 deletions.
29 changes: 7 additions & 22 deletions man/fastcpd.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 7 additions & 22 deletions tests/testthat/examples/fastcpd_3.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
\donttest{
set.seed(1)
p <- 5
p <- 1
x <- matrix(rnorm(375 * p, 0, 1), ncol = p)
theta <- rbind(rnorm(p, 0, 1), rnorm(p, 2, 1))
y <- c(
rbinom(200, 1, 1 / (1 + exp(-x[1:200, ] %*% theta[1, ]))),
rbinom(175, 1, 1 / (1 + exp(-x[201:375, ] %*% theta[2, ])))
rbinom(200, 1, 1 / (1 + exp(-x[1:200, ] %*% theta[1, , drop = FALSE]))),
rbinom(175, 1, 1 / (1 + exp(-x[201:375, ] %*% theta[2, , drop = FALSE])))
)
data <- data.frame(y = y, x = x)
result_builtin <- suppressWarnings(fastcpd.binomial(data))
logistic_loss <- function(data, theta) {
x <- data[, -1]
x <- data[, -1, drop = FALSE]
y <- data[, 1]
u <- x %*% theta
nll <- -y * u + log(1 + exp(u))
nll[u > 10] <- -y[u > 10] * u[u > 10] + u[u > 10]
sum(nll)
}
logistic_loss_gradient <- function(data, theta) {
x <- data[nrow(data), -1]
x <- data[nrow(data), -1, drop = FALSE]
y <- data[nrow(data), 1]
c(-(y - 1 / (1 + exp(-x %*% theta)))) * x
}
Expand All @@ -35,21 +35,6 @@ result_custom <- fastcpd(
cost_gradient = logistic_loss_gradient,
cost_hessian = logistic_loss_hessian
)
cat(
"Change points detected by built-in logistic regression model: ",
result_builtin@cp_set, "\n",
"Change points detected by custom logistic regression model: ",
result_custom@cp_set, "\n",
sep = ""
)
result_custom_two_epochs <- fastcpd(
formula = y ~ . - 1,
data = data,
multiple_epochs = function(segment_length) 1,
epsilon = 1e-5,
cost = logistic_loss,
cost_gradient = logistic_loss_gradient,
cost_hessian = logistic_loss_hessian
)
summary(result_custom_two_epochs)
result_builtin@cp_set
result_custom@cp_set
}
5 changes: 2 additions & 3 deletions tests/testthat/test-examples-fastcpd_3.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ testthat::test_that(
collapse = "\n"
)))

testthat::expect_equal(result_builtin@cp_set, 202)
testthat::expect_equal(result_custom@cp_set, 202)
testthat::expect_equal(result_custom_two_epochs@cp_set, 202)
testthat::expect_equal(result_builtin@cp_set, 198)
testthat::expect_equal(result_custom@cp_set, 204)
}
)

0 comments on commit eeca55f

Please sign in to comment.