Skip to content

Instantly share code, notes, and snippets.

@tdhock
Created August 11, 2016 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tdhock/e2128057c13194a3455a5e465221310a to your computer and use it in GitHub Desktop.
Save tdhock/e2128057c13194a3455a5e465221310a to your computer and use it in GitHub Desktop.
Bug in Segmentor3IsBack package
works_with_R("3.2.3", Segmentor3IsBack="2.0")
data.vec <- c(1, 2, 2)
Segmentor(data.vec, Kmax=3, model=1)
mean.vec.list <- list(
"1 segment"=rep(mean(data.vec), 3),
"2 segments"=data.vec,
"3 segments"=data.vec)
neg.log.lik.list <- list()
for(mean.vec.name in names(mean.vec.list)){
mean.vec <- mean.vec.list[[mean.vec.name]]
neg.log.lik.list[[mean.vec.name]] <-
-sum(dpois(data.vec, mean.vec, log=TRUE))
}
(neg.log.lik <- do.call(rbind, neg.log.lik.list))
@tdhock
Copy link
Author

tdhock commented Aug 11, 2016

The output I got on my machine was

thocking@silene:~/R$ R --no-save < Segmentor-bug.R

R version 3.2.3 (2015-12-10) -- "Wooden Christmas-Tree"
Copyright (C) 2015 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> works_with_R("3.2.3", Segmentor3IsBack="2.0")
Loading required package: Segmentor3IsBack
Segmentor3IsBack v2.0 Loaded 

> 
> data.vec <- c(1, 2, 2)
> Segmentor(data.vec, Kmax=3, model=1)
Object of class Segmentor 

 Model used for the segmentation: 
[1] "Poisson"

 Maximum number of segments: 
[1] 3

 Compression factor used: 
[1] 1.5

 Matrix of breakpoints: 
           1th break 2th break 3th break
1 segment          3         0         0
2 segments         1         3         0
3 segments         1         1         3

 Parameter of each segment: 
 num [1:3, 1:3] 1.67 1 1 0 2 ...
 - attr(*, "dimnames")=List of 2
  ..$ : chr [1:3] "1 segment" "2 segments" "3 segments"
  ..$ : chr [1:3] "1th parameter" "2th parameter" "3th parameter"

 Likelihood of the segmentation 
               [,1]
1 segment  3.832166
2 segments 3.613706
3 segments 1.386294
> mean.vec.list <- list(
+   "1 segment"=rep(mean(data.vec), 3),
+   "2 segments"=data.vec,
+   "3 segments"=data.vec)
> neg.log.lik.list <- list()
> for(mean.vec.name in names(mean.vec.list)){
+   mean.vec <- mean.vec.list[[mean.vec.name]]
+   neg.log.lik.list[[mean.vec.name]] <-
+     -sum(dpois(data.vec, mean.vec, log=TRUE))
+ }
> (neg.log.lik <- do.call(rbind, neg.log.lik.list))
               [,1]
1 segment  3.832166
2 segments 3.613706
3 segments 3.613706
> 
thocking@silene:~/R$ 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment