DSAggregate_Window: Sliding Window (Data Stream Operator)

View source: R/DSAggregate_Window.R

DSAggregate_WindowR Documentation

Sliding Window (Data Stream Operator)

Description

Implements a sliding window data stream operator which keeps a fixed amount (window length) of the most recent data points of the stream.

Usage

DSAggregate_Window(horizon = 100, lambda = 0)

Arguments

horizon

the window length.

lambda

decay factor damped window model. lambda = 0 means no dampening.

Details

If lambda is greater than 0 then the weight uses a damped window model (Zhu and Shasha, 2002). The weight for points in the window follows 2^(-lambda*t) where t is the age of the point.

Value

An object of class DSAggregate_Window (subclass of DSAggregate).

Author(s)

Michael Hahsler

References

Zhu, Y. and Shasha, D. (2002). StatStream: Statistical Monitoring of Thousands of Data Streams in Real Time, Intl. Conference of Very Large Data Bases (VLDB'02).

See Also

Other DSAggregate: DSAggregate(), DSAggregate_Sample()

Examples

set.seed(1500)

## Example 1: Basic use
stream <- DSD_Gaussians(k = 3, d = 2, noise = 0.05)

window <- DSAggregate_Window(horizon = 10)
window

# update with only two points. The window is mostly empty (NA)
update(window, stream, 2)
get_points(window)

# get weights and window as a single data.frame
get_model(window)

# update window
update(window, stream, 100)
get_points(window)

## Example 2: Implement a classifier over a sliding window
window <- DSAggregate_Window(horizon = 100)

update(window, stream, 1000)

# train the classifier on the window
library(rpart)
tree <- rpart(`.class` ~ ., data = get_points(window))
tree

# predict the class for new points from the stream
new_points <- get_points(stream, n = 100, info = FALSE)
pred <- predict(tree, new_points)
plot(new_points, col = pred)

stream documentation built on May 29, 2024, 9:43 a.m.