DSD as a static simulator

As a simulator DSD can simulate static streams as well as streams with drift. In cases where we are developing algorithms to work on streaming data, we can use this simulator feature effectively.

Let us see how DSD can be leveraged as a data simulator:

> library(stream, quietly = TRUE)
> set.seed(100)
> gaussian.stream <- DSD_Gaussians(k = 3, d = 3, noise = .01)
> gaussian.stream
Mixture of Gaussians
Class: DSD_Gaussians, DSD_R, DSD_data.frame, DSD
With 3 clusters in 3 dimensions
>
> data <- get_points(gaussian.stream, n = 100, class = TRUE)
> head(data)
X1 X2 X3 class
1 0.3431437 0.4621701 0.4151013 2
2 0.6684551 0.4715456 0.4162625 3
3 0.2367551 0.3512569 0.7573724 1
4 0.4465450 0.5563404 0.4582585 2
5 0.3563359 0.5492573 0.4994724 2
6 0.2147759 0.3112417 0.7310448 1

The DSD_Guassian function is a data generator. We want it to generate three-dimensional data points, specified by parameter d. We want them in three different clusters, specified by parameter k.

Calling the get_points function with this stream and specifying the number of tuples to be generated, using parameter n, we get our dataframe of 100 points in a three-dimensional space. With the class parameter, we also request the cluster group the point it belongs to.

Let us plot these points:

library(plotly)
p <- plot_ly(data, x = ~X1, y = ~X2, z = ~X3, color = ~class) %>%
add_markers() %>%
layout(scene = list(xaxis = list(title = 'X1'),
yaxis = list(title = 'X2'),
zaxis = list(title = 'X3')))
P

A 3D plot of the data points generated by DSD_Gaussian is illustrated in the following figure:

If we want to have a simulation function mimicking a live IoT system, where data is generated every n seconds/minutes, we can place the DSD function inside a while loop with a timer. Calling this while loop would continuously generate data every n seconds/minutes as per the timer configuration.

There are a lot of data generators available within the stream package. Refer to the stream documentation to learn more about other data generators: https://cran.r-project.org/web/packages/stream/vignettes/stream.pdf

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset