projects
/
talweg.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fix bugs
[talweg.git]
/
pkg
/
R
/
F_Neighbors.R
diff --git
a/pkg/R/F_Neighbors.R
b/pkg/R/F_Neighbors.R
index
0295cd5
..
ea27d5c
100644
(file)
--- a/
pkg/R/F_Neighbors.R
+++ b/
pkg/R/F_Neighbors.R
@@
-137,7
+137,7
@@
NeighborsForecaster = R6::R6Class("NeighborsForecaster",
days_in=tdays_cut, operational=opera)
nb_neighbs <- round( window[length(window)] )
# TODO: 10 == magic number
days_in=tdays_cut, operational=opera)
nb_neighbs <- round( window[length(window)] )
# TODO: 10 == magic number
- tdays <- .getConstrainedNeighbs(today, data, tdays,
min_neighbs=nb_neighbs
)
+ tdays <- .getConstrainedNeighbs(today, data, tdays,
nb_neighbs, opera
)
if (length(tdays) == 1)
{
if (final_call)
if (length(tdays) == 1)
{
if (final_call)
@@
-171,7
+171,7
@@
NeighborsForecaster = R6::R6Class("NeighborsForecaster",
if (simtype == "exo" || simtype == "mix")
{
if (simtype == "exo" || simtype == "mix")
{
- distances2 <- .computeDistsExo(data, today, tdays)
+ distances2 <- .computeDistsExo(data, today, tdays
, opera
)
# Compute exogen similarities using the given window
window_exo = ifelse(simtype=="mix", window[2], window[1])
# Compute exogen similarities using the given window
window_exo = ifelse(simtype=="mix", window[2], window[1])
@@
-218,9
+218,9
@@
NeighborsForecaster = R6::R6Class("NeighborsForecaster",
# @param min_neighbs Minimum number of points in a neighborhood
# @param max_neighbs Maximum number of points in a neighborhood
#
# @param min_neighbs Minimum number of points in a neighborhood
# @param max_neighbs Maximum number of points in a neighborhood
#
-.getConstrainedNeighbs = function(today, data, tdays, min_neighbs
=10
)
+.getConstrainedNeighbs = function(today, data, tdays, min_neighbs
, opera
)
{
{
- levelToday =
data$getLevelHat(today
)
+ levelToday =
ifelse(opera, tail(data$getLevelHat(today),1), data$getLevel(today)
)
distances = sapply( tdays, function(i) abs(data$getLevel(i) - levelToday) )
#TODO: 1, +1, +3 : magic numbers
dist_thresh = 1
distances = sapply( tdays, function(i) abs(data$getLevel(i) - levelToday) )
#TODO: 1, +1, +3 : magic numbers
dist_thresh = 1
@@
-265,10
+265,13
@@
NeighborsForecaster = R6::R6Class("NeighborsForecaster",
})
}
})
}
-.computeDistsExo <- function(data, today, tdays)
+.computeDistsExo <- function(data, today, tdays
, opera
)
{
M = matrix( ncol=1+length(tdays), nrow=1+length(data$getExo(1)) )
{
M = matrix( ncol=1+length(tdays), nrow=1+length(data$getExo(1)) )
- M[,1] = c( data$getLevelHat(today), as.double(data$getExoHat(today)) )
+ if (opera)
+ M[,1] = c( tail(data$getLevelHat(today),1), as.double(data$getExoHat(today)) )
+ else
+ M[,1] = c( data$getLevel(today), as.double(data$getExo(today)) )
for (i in seq_along(tdays))
M[,i+1] = c( data$getLevel(tdays[i]), as.double(data$getExo(tdays[i])) )
for (i in seq_along(tdays))
M[,i+1] = c( data$getLevel(tdays[i]), as.double(data$getExo(tdays[i])) )