Skip to content

Commit

Permalink
fastcpd 0.2.9
Browse files Browse the repository at this point in the history
* Fix Poisson regression bug related to `lfactorial`.
  • Loading branch information
doccstat committed Aug 28, 2023
1 parent 6567be4 commit be4d162
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 29 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: fastcpd
Type: Package
Title: Fast Change Point Detection Based on Dynamic Programming with Pruning
with Sequential Gradient Descent
Version: 0.2.8
Version: 0.2.9
Authors@R: c(
person("Xingchi", "Li", email = "anthony.li@stat.tamu.edu",
role = c("aut", "cre", "cph"),
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# fastcpd 0.2.9

* Fix Poisson regression bug related to `lfactorial`.

# fastcpd 0.2.8

* Make penalized linear regression estimated coefficients output sparse.
Expand Down
12 changes: 6 additions & 6 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ find change points in a fast manner. It is easy to install and extensible to
all kinds of change point problems with a user specified cost function apart
from the built-in cost functions.

If you'd like to learn how to use the fastcpd effectively, please refer to the following references:
If you'd like to learn how to use the fastcpd effectively, please refer to:

* [Sequential Gradient Descent and Quasi-Newton's Method for Change-Point Analysis](https://proceedings.mlr.press/v206/zhang23b.html)

Expand All @@ -45,7 +45,11 @@ install.packages("fastcpd")
pak::pak("doccstat/fastcpd")
```

If you're compiling from source, you can run `pak::pkg_system_requirements("fastcpd")`, to see the complete set of system packages needed on your machine.
If you're compiling from source, you can run
`pak::pkg_system_requirements("fastcpd")`, to see the complete set of system
packages needed on your machine.

[documentation & examples](https://fastcpd.xingchi.li/reference/fastcpd.html#ref-examples)

## Dependency

Expand All @@ -58,10 +62,6 @@ If you're compiling from source, you can run `pak::pkg_system_requirements("fast
* [glmnet](https://glmnet.stanford.edu/), for penalized regression.
* [ggplot2](https://github.com/tidyverse/ggplot2), for data visualization.

## Documentation

[documentation & examples](https://fastcpd.xingchi.li/reference/fastcpd.html#ref-examples)

## Contact us

Encountered a bug or unintended behavior?
Expand Down
59 changes: 39 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,53 +1,72 @@

<!-- README.md is generated from README.Rmd. Please edit that file -->



# fastcpd

[![CRAN status](https://www.r-pkg.org/badges/version/fastcpd)](https://cran.r-project.org/package=fastcpd) [![R-CMD-check](https://github.com/doccstat/fastcpd/workflows/R-CMD-check/badge.svg)](https://github.com/doccstat/fastcpd/actions) [![Codecov test coverage](https://codecov.io/gh/doccstat/fastcpd/branch/main/graph/badge.svg)](https://app.codecov.io/gh/doccstat/fastcpd?branch=main) [![Last Commit](https://img.shields.io/github/last-commit/doccstat/fastcpd)](https://github.com/doccstat/fastcpd) [![r-universe](https://doccstat.r-universe.dev/badges/fastcpd)](https://doccstat.r-universe.dev)
[![CRAN
status](https://www.r-pkg.org/badges/version/fastcpd)](https://cran.r-project.org/package=fastcpd)
[![R-CMD-check](https://github.com/doccstat/fastcpd/workflows/R-CMD-check/badge.svg)](https://github.com/doccstat/fastcpd/actions)
[![Codecov test
coverage](https://codecov.io/gh/doccstat/fastcpd/branch/main/graph/badge.svg)](https://app.codecov.io/gh/doccstat/fastcpd?branch=main)
[![Last
Commit](https://img.shields.io/github/last-commit/doccstat/fastcpd)](https://github.com/doccstat/fastcpd)
[![r-universe](https://doccstat.r-universe.dev/badges/fastcpd)](https://doccstat.r-universe.dev)

## Overview

The fastcpd (**fast** **c**hange **p**oint **d**etection) is a fast implmentation of change point detection methods in R. The **fastcpd** package is designed to find change points in a fast manner. It is easy to install and extensible to all kinds of change point problems with a user specified cost function apart from the built-in cost functions.
The fastcpd (**fast** **c**hange **p**oint **d**etection) is a fast
implmentation of change point detection methods in R. The **fastcpd**
package is designed to find change points in a fast manner. It is easy
to install and extensible to all kinds of change point problems with a
user specified cost function apart from the built-in cost functions.

If you'd like to learn how to use the fastcpd effectively, please refer to the following references:
If you’d like to learn how to use the fastcpd effectively, please refer
to:

- [Sequential Gradient Descent and Quasi-Newton's Method for Change-Point Analysis](https://proceedings.mlr.press/v206/zhang23b.html)
- [Sequential Gradient Descent and Quasi-Newton’s Method for
Change-Point
Analysis](https://proceedings.mlr.press/v206/zhang23b.html)

## Installation

``` {.r}
``` r
# Install from CRAN, (not yet available)
install.packages("fastcpd")
```

``` {.r}
``` r
# Install the development version from GitHub
# install.packages("pak")
pak::pak("doccstat/fastcpd")
```

If you're compiling from source, you can run `pak::pkg_system_requirements("fastcpd")`, to see the complete set of system packages needed on your machine.
If you’re compiling from source, you can run
`pak::pkg_system_requirements("fastcpd")`, to see the complete set of
system packages needed on your machine.

[documentation &
examples](https://fastcpd.xingchi.li/reference/fastcpd.html#ref-examples)

## Dependency

`library(fastcpd)` will load the following packages:

- [Rcpp](https://github.com/RcppCore/Rcpp), for C++ source code compilation.
- [RcppArmadillo](https://github.com/RcppCore/RcppArmadillo), for fast linear algebra.
- [fastglm](https://github.com/jaredhuling/fastglm), for fast generalized linear models.
- [DescTools](https://github.com/AndriSignorell/DescTools), for Winsorizing Poisson data.
- [glmnet](https://glmnet.stanford.edu/), for penalized regression.
- [ggplot2](https://github.com/tidyverse/ggplot2), for data visualization.

## Documentation

[documentation & examples](https://fastcpd.xingchi.li/reference/fastcpd.html#ref-examples)
- [Rcpp](https://github.com/RcppCore/Rcpp), for C++ source code
compilation.
- [RcppArmadillo](https://github.com/RcppCore/RcppArmadillo), for fast
linear algebra.
- [fastglm](https://github.com/jaredhuling/fastglm), for fast
generalized linear models.
- [DescTools](https://github.com/AndriSignorell/DescTools), for
Winsorizing Poisson data.
- [glmnet](https://glmnet.stanford.edu/), for penalized regression.
- [ggplot2](https://github.com/tidyverse/ggplot2), for data
visualization.

## Contact us

Encountered a bug or unintended behavior?

1. File a ticket at [GitHub Issues](https://github.com/doccstat/fastcpd/issues).
1. File a ticket at [GitHub
Issues](https://github.com/doccstat/fastcpd/issues).
2. Contact the developers specified in [DESCRIPTION](/DESCRIPTION).
13 changes: 11 additions & 2 deletions src/fastcpd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,17 @@ Rcpp::List negative_log_likelihood(
arma::vec y = data.col(0);
arma::mat x = data.cols(1, data.n_cols - 1);
arma::colvec u = x * theta_nonnull;
Rcpp::NumericVector y_factorial = Rcpp::lfactorial(Rcpp::wrap(y));
return Rcpp::List::create(Rcpp::Named("value") = arma::accu(-y % u + arma::exp(u) + arma::vec(y_factorial.begin(), y_factorial.size(), false)));

arma::colvec y_factorial(y.n_elem);
for (unsigned int i = 0; i < y.n_elem; i++) {
double log_factorial = 0;
for (int j = 1; j <= y(i); ++j) {
log_factorial += std::log(j);
}
y_factorial(i) = log_factorial;
}

return Rcpp::List::create(Rcpp::Named("value") = arma::accu(-y % u + arma::exp(u) + y_factorial));
}
}

Expand Down

0 comments on commit be4d162

Please sign in to comment.