1 | update.SlidingWindow(window, new.data)
|
window |
|
new.data |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | ##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (window, new.data)
{
num.itens <- length(new.data)
if (num.itens > window$max.length)
stop("Updated more points than the size of the window")
excess.data <- window$count + num.itens - window$max.length
if (excess.data > 0) {
window$data <- window$data[-1:-excess.data]
}
window$data <- c(window$data, new.data)
window$count <- length(window$data)
if (window$compute.embedded.data) {
if (is.null(window$embedded.data)) {
if (window$count >= (window$m - 1) * window$d + 1) {
window$embedded.data <- embedd(window$data, window$m,
window$d)
if (window$compute.distances) {
window$distances <- as.matrix(dist(window$embedded.data))
}
}
}
else {
if (excess.data > 0) {
window$embedded.data <- window$embedded.data[-1:-excess.data,
]
}
range.embbed.data <- c((window$count - num.itens -
((window$m - 1) * window$d) + 1), window$count)
if (range.embbed.data[1] < 1) {
range.embbed.data[1] <- 1
}
data.to.embedd <- window$data[range.embbed.data[1]:range.embbed.data[2]]
new.embedded.data <- embedd(data.to.embedd, window$m,
window$d)
if (window$compute.distances) {
distance.between.points <- proxy::dist(window$embedded.dat,
new.embedded.data)
}
window$embedded.data <- rbind(window$embedded.data,
new.embedded.data)
if (window$compute.distances) {
if (excess.data > 0) {
old.distances <- window$distances[-1:-excess.data,
-1:-excess.data]
}
else {
old.distances <- window$distances
}
new.distances <- as.matrix(dist(new.embedded.data))
window$distances <- rbind(cbind(old.distances,
distance.between.points), cbind(t(distance.between.points),
new.distances))
}
}
}
window
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.