[chronojump] Fixed problem with extrema cross that sometimes did not find 0 cross
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] Fixed problem with extrema cross that sometimes did not find 0 cross
- Date: Mon, 18 May 2015 19:07:37 +0000 (UTC)
commit 2732a95c8846b106ed8fc5535511d94c7fcb6546
Author: Xavier de Blas <xaviblas gmail com>
Date: Mon May 18 21:01:55 2015 +0200
Fixed problem with extrema cross that sometimes did not find 0 cross
encoder/util.R | 29 ++++++++++++++++++++++++++++-
1 files changed, 28 insertions(+), 1 deletions(-)
---
diff --git a/encoder/util.R b/encoder/util.R
index c496b48..2ceb127 100644
--- a/encoder/util.R
+++ b/encoder/util.R
@@ -146,7 +146,34 @@ extrema <- function(y, ndata = length(y), ndatam1 = ndata - 1) {
}
ncross <- nrow(cross)
}
- }
+ }
+
+ #extrema cross working:
+ #a=c(-3,-2,-1,0,1,2,1)
+ #extrema(a)$cross
+ # [,1] [,2]
+ #[1,] 4 4
+ #extrema(a)$ncross
+ #[1] 1
+ #
+ #But, if there's no change of direction, cross does not find anything:
+ #a=c(-3,-2,-1,0,1,2)
+ #extrema(a)$cross
+ #NULL
+ #extrema(a)$ncross
+ #[1] 0
+ #
+ #then find a cross in this situation. Find just one cross.
+ if(ncross == 0) {
+ positiveAtStart = (y[1] >= 0)
+ for(i in 1:length(y)) {
+ if( (y[i] >= 0) != positiveAtStart) { #if there's a sign change
+ cross = rbind(cross, c(i-1,i))
+ ncross = 1
+ break
+ }
+ }
+ }
list(minindex=minindex, maxindex=maxindex, nextreme=nextreme, cross=cross, ncross=ncross)
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]