Learn R Programming

stream (version 2.0-1)

DSF: Data Stream Filter Base Classes

Description

Abstract base classes for all data stream filter (DSF) classes. Data stream filters transform a data stream (DSD).

Usage

DSF(...)

# S3 method for DSF reset_stream(dsd, pos = 1)

# S3 method for DSF get_points(x, n = 1L, info = TRUE, ...)

# S3 method for DSF update(object, dsd = NULL, n = 1L, return = "data", ...)

# S3 method for DSF close_stream(dsd, ...)

Arguments

...

Further arguments passed on.

dsd

a stream object of class DSD.

pos

position in the stream.

x, object

a DSF object.

n

number of points to get/use for the update.

info

return additional columns with information about the data point (e.g., a known cluster assignment).

return

a character string indicating what update returns. The only value is currently "data" to return the transformed data. possible values depend on the DST.

Methods (by generic)

  • reset_stream(DSF): reset the attached stream if reset is supported.

  • get_points(DSF): DSD-like interface to get points if the DSF was created with an attached stream.

  • update(DSF): updates with data and returns the filtered data.

  • close_stream(DSF): close the attached stream if close is supported.

Author

Michael Hahsler

Details

The DSF class cannot be instantiated, but it serve as a base class from which other DSF classes inherit.

Data stream filters transform a DSD data stream. DSF can be used in two ways.

  1. DSD Adapter: When a data stream (dsd) is specified in the constructor, then the DSF acts as an a adapter for a connected data stream. The DSF implementations inherit the interface from DSD and provide:

    • get_points() get the transformed points.

    • reset_stream() reset the underlying stream

    • close_stream() close the underlying stream

  2. Stream Transformer: When no data stream (dsd) is specified in the constructor, then the DSF acts like a DST data stream task and provides:

    • update() to transform the points from a specified DSD. It is convenient to use the pipe (magrittr::%>%) to apply one or more filters to data streams (see Examples section).

See Also

Other DSF: DSF_Convolve(), DSF_Downsample(), DSF_ExponentialMA(), DSF_Func(), DSF_Scale(), DSF_dplyr()

Other DSD: DSD_BarsAndGaussians(), DSD_Benchmark(), DSD_Cubes(), DSD_Gaussians(), DSD_MG(), DSD_Memory(), DSD_Mixture(), DSD_NULL(), DSD_ReadDB(), DSD_ReadStream(), DSD_Target(), DSD_UniformNoise(), DSD_mlbenchData(), DSD_mlbenchGenerator(), DSD(), animate_data(), close_stream(), get_points(), plot.DSD(), reset_stream()

Examples

Run this code
DSF()

# Example 1: Use as a DSD adapter
stream <- DSD_Gaussians(k = 3, d = 2) %>%
  DSF_Func(func = function(x) cbind(x, Xsum = x$X1 + x$X2))
stream

get_points(stream, n = 5)

# Example 2: Use as a stream transformer
trans <- DSF_Func(func = function(x) cbind(x, Xsum = x$X1 + x$X2))
trans

update(trans, stream, n = 5)

# Example 3: Use as a DST preprocessor
clusterer <- DSF_Func(func = function(x) cbind(x, X1_squared = x$X1^2)) %>%
               DST_Runner(DSC_Kmeans(k = 3))
clusterer

update(clusterer, stream, n = 100)

# Example 5: Specify a complete pipeline DSD -> DSF -> DST
pipeline <- DSD_Gaussians(k = 3, d = 2) %>%
               DSF_Func(func = function(x) cbind(x, X1_squared = x$X1^2)) %>%
               DST_Runner(DSC_Kmeans(k = 3))
pipeline

update(pipeline, n = 100)
plot(pipeline$dst)

Run the code above in your browser using DataLab