projects
/
talweg.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
all by-col except M in F_Neighbors.R
[talweg.git]
/
pkg
/
R
/
F_Neighbors.R
diff --git
a/pkg/R/F_Neighbors.R
b/pkg/R/F_Neighbors.R
index
202b7e2
..
5b1f826
100644
(file)
--- a/
pkg/R/F_Neighbors.R
+++ b/
pkg/R/F_Neighbors.R
@@
-4,6
+4,7
@@
#'
#' Predict tomorrow as a weighted combination of "futures of the past" days.
#' Inherits \code{\link{Forecaster}}
#'
#' Predict tomorrow as a weighted combination of "futures of the past" days.
#' Inherits \code{\link{Forecaster}}
+#'
NeighborsForecaster = R6::R6Class("NeighborsForecaster",
inherit = Forecaster,
NeighborsForecaster = R6::R6Class("NeighborsForecaster",
inherit = Forecaster,
@@
-100,17
+101,22
@@
NeighborsForecaster = R6::R6Class("NeighborsForecaster",
{
delta = data$getCenteredSerie(today) - data$getCenteredSerie(fdays[i])
# Require at least half of non-NA common values to compute the distance
{
delta = data$getCenteredSerie(today) - data$getCenteredSerie(fdays[i])
# Require at least half of non-NA common values to compute the distance
- if (
sum(is.na(delta)) <= 0) #length(delta)/2
)
- distances2[i] = mean(delta^2)
#, na.rm=TRUE)
+ if (
!any( is.na(delta) )
)
+ distances2[i] = mean(delta^2)
}
sd_dist = sd(distances2)
if (sd_dist < .Machine$double.eps)
}
sd_dist = sd(distances2)
if (sd_dist < .Machine$double.eps)
+ {
+# warning("All computed distances are very close: stdev too small")
sd_dist = 1 #mostly for tests... FIXME:
sd_dist = 1 #mostly for tests... FIXME:
+ }
simils_endo =
if (kernel=="Gauss")
exp(-distances2/(sd_dist*h_endo^2))
simils_endo =
if (kernel=="Gauss")
exp(-distances2/(sd_dist*h_endo^2))
- else { #Epanechnikov
+ else
+ {
+ # Epanechnikov
u = 1 - distances2/(sd_dist*h_endo^2)
u[abs(u)>1] = 0.
u
u = 1 - distances2/(sd_dist*h_endo^2)
u[abs(u)>1] = 0.
u
@@
-138,10
+144,17
@@
NeighborsForecaster = R6::R6Class("NeighborsForecaster",
}
sd_dist = sd(distances2)
}
sd_dist = sd(distances2)
+ if (sd_dist < .Machine$double.eps)
+ {
+# warning("All computed distances are very close: stdev too small")
+ sd_dist = 1 #mostly for tests... FIXME:
+ }
simils_exo =
if (kernel=="Gauss")
exp(-distances2/(sd_dist*h_exo^2))
simils_exo =
if (kernel=="Gauss")
exp(-distances2/(sd_dist*h_exo^2))
- else { #Epanechnikov
+ else
+ {
+ # Epanechnikov
u = 1 - distances2/(sd_dist*h_exo^2)
u[abs(u)>1] = 0.
u
u = 1 - distances2/(sd_dist*h_exo^2)
u[abs(u)>1] = 0.
u
@@
-166,13
+179,12
@@
NeighborsForecaster = R6::R6Class("NeighborsForecaster",
private$.params$weights <- similarities
private$.params$indices <- fdays
private$.params$window <-
private$.params$weights <- similarities
private$.params$indices <- fdays
private$.params$window <-
- if (simtype=="endo")
{
+ if (simtype=="endo")
h_endo
h_endo
- } else if (simtype=="exo") {
+ else if (simtype=="exo")
h_exo
h_exo
-
} else {
#mix
+
else
#mix
c(h_endo,h_exo)
c(h_endo,h_exo)
- }
}
return (prediction)
}
return (prediction)