Skip to content

Commit

Permalink
Merge pull request #76 from rkillick/dev
Browse files Browse the repository at this point in the history
Merging 2.2.5 from dev
  • Loading branch information
rkillick committed Nov 8, 2022
2 parents f9a1f6d + d471984 commit 5253a05
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 30 deletions.
11 changes: 6 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: changepoint
Type: Package
Title: Methods for Changepoint Detection
Version: 2.2.4
Date: 2022-10-31
Version: 2.2.5
Date: 2022-11-08
Authors@R: c(person("Rebecca", "Killick",
role=c("aut","cre"),email="r.killick@lancs.ac.uk"),
person("Kaylea", "Haynes", role="aut"),
Expand All @@ -12,17 +12,18 @@ Maintainer: Rebecca Killick <r.killick@lancs.ac.uk>
BugReports: https://github.com/rkillick/changepoint/issues
URL: https://github.com/rkillick/changepoint/
Description: Implements various mainstream and specialised changepoint methods for finding single and multiple changepoints within data. Many popular non-parametric and frequentist methods are included. The cpt.mean(), cpt.var(), cpt.meanvar() functions should be your first point of call.
Depends: R(>= 3.1), methods, stats, zoo(>= 0.9-1)
Depends: R(>= 3.2), methods, stats, zoo(>= 0.9-1)
Suggests: testthat, vdiffr
License: GPL
LazyData: true
Packaged: 2022-10-31 14:14:13 UTC; killick
Packaged: 2022-11-08 14:14:13 UTC; killick
NeedsCompilation: yes
Repository: CRAN
Date/Publication: 2022-10-31 15:50:02 UTC
Date/Publication: 2022-11-08 15:50:02 UTC
Author: Rebecca Killick [aut, cre],
Kaylea Haynes [aut],
Idris Eckley [ths],
Paul Fearnhead [ctb, ths],
Robin Long [ctb],
Jamie Lee [ctr]

11 changes: 9 additions & 2 deletions NEWS
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
Version 2.2.5
=============
* Thanks to Toby Hocking for highlighting that when pen=0, BinSeg doesn't need to warn that ncpts=Q as this is by design. Warning for pen=0 removed.
* Thanks to Toby Hocking and his students for spotting that when minseglen=1 BinSeg would not allow the maximum Q. This was due to a hardcoding of minseglen=2 in the check function. This has been corrected.

Version 2.2.4
=============
* Updated C code to be compliant with new CRAN flags
* Updated check for 1D objects to also check for 1D arrays. Thanks to Github user ChristopherEeles for highlighting the bug.
* Updated C code to be compliant with new CRAN flags

Version 2.2.3
=============
Expand All @@ -17,7 +22,6 @@ Version 2.2.3
* Removed a feature from the direct call to "segnigh.XX.YY" functions where a vector of penalties could be supplied. This caused a warning to occur in a dependency.
* Re-evaluated the maximum Q that could be given to all segneigh functions. Thanks to Aaron Lowther for highlighting.


Version 2.2.2
=============
* Updated R dependency, thanks to Mateusz Konieczny to identifying the problem (and solution).
Expand Down Expand Up @@ -222,3 +226,6 @@ Version 0.2
Version 0.1
===========
* Original



26 changes: 12 additions & 14 deletions R/BinSeg_one_func_minseglen.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
BINSEG = function(sumstat, pen = 0, cost_func = "norm.mean", shape = 1, minseglen = 2, Q=5){

n=length(sumstat[,1])-1
if(n<2){stop('Data must have atleast 2 observations to fit a changepoint model.')}
if(Q>((n/2)+1)){stop(paste('Q is larger than the maximum number of segments',floor(n/2)+1))}

n = length(sumstat[,1]) - 1
if(n<2){stop('Data must have at least 2 observations to fit a changepoint model.')}
if(Q>((n/minseglen)+1)){stop(paste('Q is larger than the maximum number of segments',(n/minseglen)+1))}
if(Q>n){stop(paste("Q is larger than the length of the data length"))}
if(Q<=0){stop(paste('Q is the maximum number of changepoints so should be greater than 0'))}

storage.mode(sumstat) = 'double'
Expand All @@ -11,16 +12,13 @@ BINSEG = function(sumstat, pen = 0, cost_func = "norm.mean", shape = 1, minsegle
likeout=rep(0,Q) # sets up null vector for likelihood of changepoints in cptsout
storage.mode(cptsout)='integer'
storage.mode(likeout)='double'
op_cps=0

#on.exit(.C("FreeBinSeg",answer[[6]],PACKAGE='changepoint'))
# answer=.C('PELT',cost_func, y3, y2,y,as.integer(n),as.double(pen),cptsout,as.integer(error),as.double(shape))
answer=.C('binseg',cost_func, sumstat,as.integer(n),as.double(pen),as.integer(Q),cptsout, as.integer(minseglen), likeout, as.integer(op_cps), as.double(shape))
if(answer[[9]]==Q){warning('The number of changepoints identified is Q, it is advised to increase Q to make sure changepoints have not been missed.')}
if(answer[[9]]==0){cpts=n}
else{cpts=c(sort(answer[[6]][1:answer[[9]]]),n)}
return(list(cps=rbind(answer[[6]],2*answer[[8]]),cpts=cpts,op.cpts=answer[[9]],pen=pen))
##answer[6] is cptsout, answer[8] is likeout ("beta value")
op_cps = 0

answer=.C('binseg', cost_func = cost_func, sumstat = sumstat, n = as.integer(n), pen = as.double(pen), Q = as.integer(Q), cptsout = cptsout, minseglen = as.integer(minseglen), likeout = likeout, op_cps = as.integer(op_cps), shape = as.double(shape))
if((answer$op_cps == Q)&(pen!=0)){warning('The number of changepoints identified is Q, it is advised to increase Q to make sure changepoints have not been missed.')}
if(answer$op_cps == 0){cpts=n}
else{cpts=c(sort(answer$cptsout[1:answer$op_cps]),n)}
return(list(cps=rbind(answer$cptsout,2*answer$likeout),cpts=cpts,op.cpts=answer$op_cps,pen=pen))
}


Expand Down
4 changes: 2 additions & 2 deletions R/class_input.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class_input <- function(data, cpttype, method, test.stat, penalty, pen.value, mi
ans=new("cpt")
}

data.set(ans)=data;cpttype(ans)=cpttype;method(ans)=method; test.stat(ans)=test.stat;pen.type(ans)=penalty;pen.value(ans)=pen.value;minseglen(ans)=minseglen;
data.set(ans)=data;cpttype(ans)=cpttype;method(ans)=method; test.stat(ans)=test.stat;pen.type(ans)=penalty;pen.value(ans)=pen.value;minseglen(ans)=minseglen;ans@date=date();
if(penalty!="CROPS"){ # crops is only one that doesn't give a single set of cpts
cpts(ans)=out[[2]]

Expand Down Expand Up @@ -49,4 +49,4 @@ class_input <- function(data, cpttype, method, test.stat, penalty, pen.value, mi
}

return(ans)
}
}
7 changes: 3 additions & 4 deletions R/cpt.class.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
setClass("cpt",slots=list(data.set="ts", cpttype="character", method="character", test.stat="character",pen.type="character",pen.value="numeric",minseglen="numeric",cpts="numeric",ncpts.max="numeric",param.est="list",date="character",version="character"),prototype=prototype(cpttype="Not Set",date=date(),version=as(packageVersion("changepoint"),'character')))
setClass("cpt",slots=list(data.set="ts", cpttype="character", method="character", test.stat="character",pen.type="character",pen.value="numeric",minseglen="numeric",cpts="numeric",ncpts.max="numeric",param.est="list",date="character",version="character"),prototype=prototype(cpttype="Not Set",date=date(),version=as(packageVersion("changepoint"),'character')))

setClass("cpt.reg",slots=list(data.set="matrix", cpttype="character", method="character", test.stat="character",pen.type="character",pen.value="numeric",minseglen="numeric",cpts="numeric",ncpts.max="numeric",param.est="list",date="character",version="character"),prototype=prototype(cpttype="regression",date=date(),version=as(packageVersion("changepoint"),"character")))

Expand Down Expand Up @@ -587,9 +587,8 @@
}
return(tmpscale)
}
param.trend=function(object){
cpts=c(0,object@cpts)
seglen=seg.len(object)
param.trend=function(object,cpts){
seglen=cpts[-1]-cpts[-length(cpts)]
data=data.set(object)
n=length(data)
sumstat=cbind(cumsum(c(0,data)),cumsum(c(0,data*c(1:n))))
Expand Down
4 changes: 2 additions & 2 deletions man/changepoint-package.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ Implements various mainstream and specialised changepoint methods for finding si
\tabular{ll}{
Package: \tab changepoint\cr
Type: \tab Package\cr
Version: \tab 2.2.4 \cr
Date: \tab 2022-10-31\cr
Version: \tab 2.2.5 \cr
Date: \tab 2022-11-08\cr
License: \tab GPL\cr
LazyLoad: \tab yes\cr
}
Expand Down
2 changes: 1 addition & 1 deletion man/cpt.var.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test.stat="Normal",class=TRUE,param.estimates=TRUE,minseglen=2)
A vector, ts object or matrix containing the data within which you wish to find a changepoint. If data is a matrix, each row is considered a separate dataset.
}
\item{penalty}{
Choice of "None", "SIC", "BIC", "MBIC", AIC", "Hannan-Quinn", "Asymptotic", "Manual" and "CROPS" penalties. If Manual is specified, the manual penalty is contained in the pen.value parameter. If Asymptotic is specified, the theoretical type I error is contained in the pen.value parameter. If CROPS is specified, the penalty range is contained in the pen.value parameter; note this is a vector of length 2 which contains the minimum and maximum penalty value. Note CROPS can only be used if the method is "PELT". The predefined penalties listed DO count the changepoint as a parameter, postfix a 0 e.g."SIC0" to NOT count the changepoint as a parameter.
Choice of "None", "SIC", "BIC", "MBIC", "AIC", "Hannan-Quinn", "Asymptotic", "Manual" and "CROPS" penalties. If Manual is specified, the manual penalty is contained in the pen.value parameter. If Asymptotic is specified, the theoretical type I error is contained in the pen.value parameter. If CROPS is specified, the penalty range is contained in the pen.value parameter; note this is a vector of length 2 which contains the minimum and maximum penalty value. Note CROPS can only be used if the method is "PELT". The predefined penalties listed DO count the changepoint as a parameter, postfix a 0 e.g."SIC0" to NOT count the changepoint as a parameter.
}
\item{pen.value}{
The theoretical type I error e.g.0.05 when using the Asymptotic penalty. A vector of length 2 (min,max) if using the CROPS penalty. The value of the penalty when using the Manual penalty option - this can be a numeric value or text giving the formula to use. Available variables are, n=length of original data, null=null likelihood, alt=alternative likelihood, tau=proposed changepoint, diffparam=difference in number of alternatve and null parameters.
Expand Down

0 comments on commit 5253a05

Please sign in to comment.