## ----setup, include=FALSE-----------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>",
  fig.width = 6, fig.height = 5)
library(stream)
set.seed(1000)

## ----data---------------------------------------------------------------------
stream <- DSD_Memory(DSD_BarsAndGaussians(noise = 0.05), n = 10000)
plot(stream, n = 1000)

## ----reset--------------------------------------------------------------------
reset_stream(stream)

## ----train--------------------------------------------------------------------
dbstream<- DSC_DBSTREAM(r = 1, shared_density = TRUE, alpha = 0.3, minweight = .1)
update(dbstream, stream, n = 5000)
dbstream

## ----inspect------------------------------------------------------------------
plot(dbstream, dsd = stream, type = "both", shared_density = TRUE, n = 500)

## ----evaluate-----------------------------------------------------------------
evaluate_static(dbstream, stream, n = 1000,
  measure = c("purity", "crand"), type = "macro", assign = "micro")

## ----evaluate-micro-----------------------------------------------------------
evaluate_static(dbstream, stream, n = 1000,
  measure = c("purity", "crand"), type = "micro")

## ----moving-data--------------------------------------------------------------
plot(DSD_Benchmark(1), n = 250, xlim = c(0, 1), ylim = c(0, 1))

## ----moving-train-------------------------------------------------------------
set.seed(1000)
moving_stream <- DSD_Benchmark(1)
moving_dbstream <- DSC_DBSTREAM(r = 0.05, lambda = 0.01)
update(moving_dbstream, moving_stream, n = 1000)
plot(moving_dbstream, dsd = moving_stream, type = "both",
  xlim = c(0, 1), ylim = c(0, 1), n = 250)

## ----moving-animation, eval=knitr::is_html_output() && requireNamespace("gifski", quietly=TRUE) && requireNamespace("animation", quietly=TRUE), fig.show='animate', animation.hook='gifski', interval=0.1, aniopts='loop', dev='png', fig.width=6.4, fig.height=4.8, dpi=100, fig.retina=1, fig.alt='DBSTREAM following two moving clusters'----
set.seed(1000)
animation_stream <- DSD_Benchmark(1)
animation_model <- DSC_DBSTREAM(r = 0.05, lambda = 0.01)

res <- animate_cluster(animation_model, 
                       animation_stream, 
                       horizon = 100, 
                       n = 5000, 
                       wait = 0,  # for use in a notebook
                       plot.args = list(xlim = c(0, 1), ylim = c(0, 1), 
                                        type = "both"))

