# Harbinger Package
# version 1.0.777
source("https://raw.githubusercontent.com/cefet-rj-dal/harbinger/master/jupyter.R")
#loading Harbinger
load_library("daltoolbox")
load_library("harbinger")
Loading required package: daltoolbox Registered S3 method overwritten by 'quantmod': method from as.zoo.data.frame zoo Attaching package: ‘daltoolbox’ The following object is masked from ‘package:base’: transform Loading required package: harbinger
#Creating dataset
n <- 100 # size of each segment
serie1 <- c(sin((1:n)/pi), 2*sin((1:n)/pi), 10 + sin((1:n)/pi),
10-10/n*(1:n)+sin((1:n)/pi)/2, sin((1:n)/pi)/2)
serie2 <- 2*c(sin((1:n)/pi), 2*sin((1:n)/pi), 10 + sin((1:n)/pi),
10-10/n*(1:n)+sin((1:n)/pi)/2, sin((1:n)/pi)/2)
event <- rep(FALSE, length(serie1))
event[c(100, 200, 300, 400)] <- TRUE
dataset <- data.frame(serie1, serie2, event)
#ploting the time series
plot_ts(x = 1:length(dataset$serie1), y = dataset$serie1)
#ploting serie #2
plot_ts(x = 1:length(dataset$serie2), y = dataset$serie2)
# establishing drift method
model <- hcd_ddm()
# fitting the model
model <- fit(model, dataset)
# making detections
detection <- detect(model, dataset)
Warning message in FUN(X[[i]], ...): “NaNs produced” Warning message in FUN(X[[i]], ...): “NaNs produced” Warning message in FUN(X[[i]], ...): “NaNs produced” Warning message in FUN(X[[i]], ...): “NaNs produced”
# filtering detected events
print(detection[(detection$event),])
[1] idx event type <0 rows> (or 0-length row.names)
# evaluating the detections
evaluation <- evaluate(model, detection$event, dataset$event)
print(evaluation$confMatrix)
event detection TRUE FALSE TRUE 0 0 FALSE 4 496
# ploting the results
grf <- har_plot(model, dataset$serie1, detection, dataset$event)
plot(grf)