From: Benjamin Auder Date: Thu, 23 Feb 2017 18:24:18 +0000 (+0100) Subject: various fixes (especially in plotFbox and Neighbors shape predict X-Git-Url: https://git.auder.net/img/js/css/vendor/pieces/%7B%7B?a=commitdiff_plain;h=99f83c9af27492f6fb9b10f51fb8704ed588f5c1;p=talweg.git various fixes (especially in plotFbox and Neighbors shape predict --- diff --git a/NOTES b/NOTES index 9992dfd..3f25529 100644 --- a/NOTES +++ b/NOTES @@ -35,3 +35,7 @@ Attention shift data exo hat : PM10(J+1) = f(PM10(j), meteo(j+1)) [contexte appr --> hat PM10(j+1) = hat f(PM10(j), hat meteo(j+1)) [contexte previ] Variables meteo : NAs ? + +Neighbors: + - enlever mix_strategy (oujours mult), et simthresh après tests éventuels + - same_season --> same_day(?) diff --git a/data/scripts/build_testdata.R b/data/scripts/build_testdata.R index 4c5978a..20cb725 100644 --- a/data/scripts/build_testdata.R +++ b/data/scripts/build_testdata.R @@ -5,9 +5,9 @@ times = strftime( seq( to=ISOdatetime(2007,7,2,0,0,0,tz="GMT"), by="hour"), tz="GMT" ) -# Only one covariable (so that the "matrix" is always invertible) +# Only one covariable (no need for more; random, to invert cov(M)) L = length(dates) #182 -exo_df = data.frame( "date"=dates, "var"=rep(1,L), "var_pred"=rep(1,L) ) +exo_df = data.frame( "date"=dates, "var"=rnorm(L,1), "var_pred"=rnorm(L,1) ) # Series are 1,1,...,1 2,2,...,2 ... 7,7,...,7 1,1,...,1 ...etc # First serie on monday 2007-01-01, there are exactly 26 weeks ts_df = data.frame( "time"=times, "value"=rep(seq_len(7), each=24, times=26) ) diff --git a/pkg/DESCRIPTION b/pkg/DESCRIPTION index 1453d54..38b442e 100644 --- a/pkg/DESCRIPTION +++ b/pkg/DESCRIPTION @@ -4,7 +4,7 @@ Version: 0.1-0 Description: Forecast a curve sampled within the day (seconds, minutes, hours...), using past measured curves, history of some exogenous variables measurements and the exogenous prediction for tomorrow. Main method is - getForecast() + computeForecast() Authors: Benjamin Auder [aut,cre], Jean-Michel Poggi [ctb], Bruno Portier , [ctb] @@ -33,8 +33,8 @@ Collate: 'J_Persistence.R' 'J_Zero.R' 'getData.R' - 'getError.R' - 'getForecast.R' + 'computeError.R' + 'computeForecast.R' 'plot.R' 'utils.R' VignetteBuilder: knitr diff --git a/pkg/R/F_Neighbors.R b/pkg/R/F_Neighbors.R index 3abd0ff..ffb6d37 100644 --- a/pkg/R/F_Neighbors.R +++ b/pkg/R/F_Neighbors.R @@ -61,19 +61,20 @@ NeighborsForecaster = setRefClass( #GET OPTIONAL PARAMS # Similarity computed with exogenous variables ? endogenous ? both ? ("exo","endo","mix") - simtype = ifelse(hasArg("simtype"), list(...)$simtype, "exo") + simtype = ifelse(hasArg("simtype"), list(...)$simtype, "mix") simthresh = ifelse(hasArg("simthresh"), list(...)$simthresh, 0.) - kernel = ifelse(hasArg("kernel"), list(...)$kernel, "Gauss") - mix_strategy = ifelse(hasArg("mix_strategy"), list(...)$mix_strategy, "neighb") #or "mult" - same_season = ifelse(hasArg("same_season"), list(...)$same_season, TRUE) + kernel = ifelse(hasArg("kernel"), list(...)$kernel, "Gauss") #or "Epan" + mix_strategy = ifelse(hasArg("mix_strategy"), list(...)$mix_strategy, "mult") #or "neighb" + same_season = ifelse(hasArg("same_season"), list(...)$same_season, FALSE) if (hasArg(h_window)) return (.predictShapeAux(fdays_indices, today, horizon, list(...)$h_window, kernel, - simtype, simthresh, mix_strategy, FALSE)) + simtype, simthresh, mix_strategy, TRUE)) #END GET # Indices for cross-validation; TODO: 45 = magic number indices = getSimilarDaysIndices(today, limit=45, same_season=same_season) - #indices = (end_index-45):(end_index-1) + if (tail(indices,1) == 1) + indices = head(indices,-1) # Function to optimize h : h |--> sum of prediction errors on last 45 "similar" days errorOnLastNdays = function(h, kernel, simtype) @@ -150,10 +151,12 @@ NeighborsForecaster = setRefClass( } sd_dist = sd(distances2) + if (sd_dist < .Machine$double.eps) + sd_dist = 1 #mostly for tests... FIXME: simils_endo = - if (kernel=="Gauss") { + 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 @@ -202,10 +205,9 @@ NeighborsForecaster = setRefClass( #TODO: 60 = magic number keep_indices = sort(simils_exo, index.return=TRUE)$ix[1:(min(60,length(simils_exo)))] simils_endo[-keep_indices] = 0. - } else #mix_strategy == "mult" - { - simils_endo = simils_endo * simils_exo } + else #mix_strategy == "mult" + simils_endo = simils_endo * simils_exo } similarities = @@ -235,8 +237,8 @@ NeighborsForecaster = setRefClass( prediction = rep(0, horizon) for (i in seq_along(fdays_indices)) prediction = prediction + similarities[i] * dat[[ fdays_indices[i]+1 ]]$serie[1:horizon] - prediction = prediction / sum(similarities, na.rm=TRUE) + if (final_call) { params$weights <<- similarities @@ -250,6 +252,7 @@ NeighborsForecaster = setRefClass( c(h_endo,h_exo) } } + return (prediction) } ) diff --git a/pkg/R/J_Neighbors.R b/pkg/R/J_Neighbors.R index 03d3340..33ba00d 100644 --- a/pkg/R/J_Neighbors.R +++ b/pkg/R/J_Neighbors.R @@ -1,6 +1,6 @@ #' Obtain jump forecast by the Neighbors method #' -#' @inheritParams getForecast +#' @inheritParams computeForecast #' @inheritParams getZeroJumpPredict getNeighborsJumpPredict = function(data, today, memory, horizon, params, ...) { @@ -8,6 +8,7 @@ getNeighborsJumpPredict = function(data, today, memory, horizon, params, ...) filter = params$indices >= first_day indices = params$indices[filter] weights = params$weights[filter] + if (any(is.na(weights) | is.na(indices))) return (NA) diff --git a/pkg/R/J_Persistence.R b/pkg/R/J_Persistence.R index 8ac597c..7a7daef 100644 --- a/pkg/R/J_Persistence.R +++ b/pkg/R/J_Persistence.R @@ -1,6 +1,6 @@ #' Obtain jump forecast by the Persistence method #' -#' @inheritParams getForecast +#' @inheritParams computeForecast #' @inheritParams getZeroJumpPredict getPersistenceJumpPredict = function(data, today, memory, horizon, params, ...) { diff --git a/pkg/R/J_Zero.R b/pkg/R/J_Zero.R index c227609..3c6af47 100644 --- a/pkg/R/J_Zero.R +++ b/pkg/R/J_Zero.R @@ -1,6 +1,6 @@ #' Just predict zero "jump" (for reference, benchmarking at least) #' -#' @inheritParams getForecast +#' @inheritParams computeForecast #' @param today Index of the current day (predict tomorrow) #' @param params Optional parameters computed by the main forecaster getZeroJumpPredict = function(data, today, memory, horizon, params, ...) diff --git a/pkg/R/getError.R b/pkg/R/computeError.R similarity index 90% rename from pkg/R/getError.R rename to pkg/R/computeError.R index affe6c3..af4109f 100644 --- a/pkg/R/getError.R +++ b/pkg/R/computeError.R @@ -3,13 +3,13 @@ #' @description Obtain the errors between forecast and data #' #' @param data Dataset, object of class \code{Data} output of \code{getData} -#' @param forecast Forecast object, class \code{Forecast} output of \code{getForecast} -#' @param horizon Horizon where to compute the error (<= horizon used in \code{getForecast}) +#' @param forecast Forecast object, class \code{Forecast} output of \code{computeForecast} +#' @param horizon Horizon where to compute the error (<= horizon used in \code{computeForecast}) #' #' @return A list (abs,MAPE) of lists (day,indices) #' #' @export -getError = function(data, forecast, horizon=data$getStdHorizon()) +computeError = function(data, forecast, horizon=data$getStdHorizon()) { L = forecast$getSize() mape_day = rep(0, horizon) diff --git a/pkg/R/getForecast.R b/pkg/R/computeForecast.R similarity index 94% rename from pkg/R/getForecast.R rename to pkg/R/computeForecast.R index 8efcff8..1a7d8ba 100644 --- a/pkg/R/getForecast.R +++ b/pkg/R/computeForecast.R @@ -28,7 +28,7 @@ #' exo_data = system.file("extdata","meteo_extra_noNAs.csv",package="talweg") #' data = getData(ts_data, exo_data, input_tz = "Europe/Paris", #' working_tz="Europe/Paris", predict_at=7) -#' pred = getForecast(data, 2200:2230, "Persistence", "Persistence", 500, 12) +#' pred = computeForecast(data, 2200:2230, "Persistence", "Persistence", 500, 12) #' \dontrun{#Sketch for real-time mode: #' data = new("Data", ...) #' forecaster = new(..., data=data) @@ -38,7 +38,7 @@ #' #do_something_with_pred #' }} #' @export -getForecast = function(data, indices, forecaster, pjump=NULL, +computeForecast = function(data, indices, forecaster, pjump=NULL, memory=Inf, horizon=data$getStdHorizon(), ...) { # (basic) Arguments sanity checks diff --git a/pkg/R/plot.R b/pkg/R/plot.R index 7b5f2b5..5cb55b0 100644 --- a/pkg/R/plot.R +++ b/pkg/R/plot.R @@ -29,7 +29,7 @@ plotCurves <- function(data, indices=seq_len(data$getSize())) #' @description Plot measured curve (in black) and predicted curve (in red) #' #' @param data Object return by \code{getData} -#' @param pred Object as returned by \code{getForecast} +#' @param pred Object as returned by \code{computeForecast} #' @param index Index in forecasts #' #' @export @@ -109,7 +109,7 @@ computeFilaments <- function(data, index, limit=60, plot=TRUE) #' #' @description Plot histogram of similarities (weights) #' -#' @param pred Object as returned by \code{getForecast} +#' @param pred Object as returned by \code{computeForecast} #' @param index Index in forecasts (not in data) #' #' @export @@ -124,9 +124,9 @@ plotSimils <- function(pred, index) #' @title Plot error #' -#' @description Draw error graphs, potentially from several runs of \code{getForecast} +#' @description Draw error graphs, potentially from several runs of \code{computeForecast} #' -#' @param err Error as returned by \code{getError} +#' @param err Error as returned by \code{computeError} #' @param cols Colors for each error (default: 1,2,3,...) #' #' @seealso \code{\link{plotPredReal}}, \code{\link{plotFilaments}}, \code{\link{plotSimils}} @@ -196,13 +196,16 @@ plotFbox <- function(data, filter=function(index) TRUE, plot_bivariate=TRUE) end_index = data$getSize() - 1 } + L = length(data$getCenteredSerie(2)) series_matrix = sapply(start_index:end_index, function(index) { - as.matrix(data$getSerie(index)) + if (filter(index)) + as.matrix(data$getSerie(index)) + else + rep(NA,L) }) - # Remove NAs. + filter TODO: merge with previous step: only one pass required... - nas_indices = seq_len(ncol(series_matrix))[ sapply( 1:ncol(series_matrix), - function(index) ( !filter(index) || any(is.na(series_matrix[,index])) ) ) ] - series_matrix = series_matrix[,-nas_indices] + # TODO: merge with previous step: only one pass should be required + no_NAs_indices = sapply( 1:ncol(series_matrix), function(i) all(!is.na(series_matrix[,i])) ) + series_matrix = series_matrix[,no_NAs_indices] series_fds = rainbow::fds(seq_len(nrow(series_matrix)), series_matrix) if (plot_bivariate) diff --git a/pkg/inst/testdata/exo_test.csv b/pkg/inst/testdata/exo_test.csv index 5da11e2..1bfe04f 100644 --- a/pkg/inst/testdata/exo_test.csv +++ b/pkg/inst/testdata/exo_test.csv @@ -1,183 +1,183 @@ "date","var","var_pred" -2007-01-01,1,1 -2007-01-02,1,1 -2007-01-03,1,1 -2007-01-04,1,1 -2007-01-05,1,1 -2007-01-06,1,1 -2007-01-07,1,1 -2007-01-08,1,1 -2007-01-09,1,1 -2007-01-10,1,1 -2007-01-11,1,1 -2007-01-12,1,1 -2007-01-13,1,1 -2007-01-14,1,1 -2007-01-15,1,1 -2007-01-16,1,1 -2007-01-17,1,1 -2007-01-18,1,1 -2007-01-19,1,1 -2007-01-20,1,1 -2007-01-21,1,1 -2007-01-22,1,1 -2007-01-23,1,1 -2007-01-24,1,1 -2007-01-25,1,1 -2007-01-26,1,1 -2007-01-27,1,1 -2007-01-28,1,1 -2007-01-29,1,1 -2007-01-30,1,1 -2007-01-31,1,1 -2007-02-01,1,1 -2007-02-02,1,1 -2007-02-03,1,1 -2007-02-04,1,1 -2007-02-05,1,1 -2007-02-06,1,1 -2007-02-07,1,1 -2007-02-08,1,1 -2007-02-09,1,1 -2007-02-10,1,1 -2007-02-11,1,1 -2007-02-12,1,1 -2007-02-13,1,1 -2007-02-14,1,1 -2007-02-15,1,1 -2007-02-16,1,1 -2007-02-17,1,1 -2007-02-18,1,1 -2007-02-19,1,1 -2007-02-20,1,1 -2007-02-21,1,1 -2007-02-22,1,1 -2007-02-23,1,1 -2007-02-24,1,1 -2007-02-25,1,1 -2007-02-26,1,1 -2007-02-27,1,1 -2007-02-28,1,1 -2007-03-01,1,1 -2007-03-02,1,1 -2007-03-03,1,1 -2007-03-04,1,1 -2007-03-05,1,1 -2007-03-06,1,1 -2007-03-07,1,1 -2007-03-08,1,1 -2007-03-09,1,1 -2007-03-10,1,1 -2007-03-11,1,1 -2007-03-12,1,1 -2007-03-13,1,1 -2007-03-14,1,1 -2007-03-15,1,1 -2007-03-16,1,1 -2007-03-17,1,1 -2007-03-18,1,1 -2007-03-19,1,1 -2007-03-20,1,1 -2007-03-21,1,1 -2007-03-22,1,1 -2007-03-23,1,1 -2007-03-24,1,1 -2007-03-25,1,1 -2007-03-26,1,1 -2007-03-27,1,1 -2007-03-28,1,1 -2007-03-29,1,1 -2007-03-30,1,1 -2007-03-31,1,1 -2007-04-01,1,1 -2007-04-02,1,1 -2007-04-03,1,1 -2007-04-04,1,1 -2007-04-05,1,1 -2007-04-06,1,1 -2007-04-07,1,1 -2007-04-08,1,1 -2007-04-09,1,1 -2007-04-10,1,1 -2007-04-11,1,1 -2007-04-12,1,1 -2007-04-13,1,1 -2007-04-14,1,1 -2007-04-15,1,1 -2007-04-16,1,1 -2007-04-17,1,1 -2007-04-18,1,1 -2007-04-19,1,1 -2007-04-20,1,1 -2007-04-21,1,1 -2007-04-22,1,1 -2007-04-23,1,1 -2007-04-24,1,1 -2007-04-25,1,1 -2007-04-26,1,1 -2007-04-27,1,1 -2007-04-28,1,1 -2007-04-29,1,1 -2007-04-30,1,1 -2007-05-01,1,1 -2007-05-02,1,1 -2007-05-03,1,1 -2007-05-04,1,1 -2007-05-05,1,1 -2007-05-06,1,1 -2007-05-07,1,1 -2007-05-08,1,1 -2007-05-09,1,1 -2007-05-10,1,1 -2007-05-11,1,1 -2007-05-12,1,1 -2007-05-13,1,1 -2007-05-14,1,1 -2007-05-15,1,1 -2007-05-16,1,1 -2007-05-17,1,1 -2007-05-18,1,1 -2007-05-19,1,1 -2007-05-20,1,1 -2007-05-21,1,1 -2007-05-22,1,1 -2007-05-23,1,1 -2007-05-24,1,1 -2007-05-25,1,1 -2007-05-26,1,1 -2007-05-27,1,1 -2007-05-28,1,1 -2007-05-29,1,1 -2007-05-30,1,1 -2007-05-31,1,1 -2007-06-01,1,1 -2007-06-02,1,1 -2007-06-03,1,1 -2007-06-04,1,1 -2007-06-05,1,1 -2007-06-06,1,1 -2007-06-07,1,1 -2007-06-08,1,1 -2007-06-09,1,1 -2007-06-10,1,1 -2007-06-11,1,1 -2007-06-12,1,1 -2007-06-13,1,1 -2007-06-14,1,1 -2007-06-15,1,1 -2007-06-16,1,1 -2007-06-17,1,1 -2007-06-18,1,1 -2007-06-19,1,1 -2007-06-20,1,1 -2007-06-21,1,1 -2007-06-22,1,1 -2007-06-23,1,1 -2007-06-24,1,1 -2007-06-25,1,1 -2007-06-26,1,1 -2007-06-27,1,1 -2007-06-28,1,1 -2007-06-29,1,1 -2007-06-30,1,1 -2007-07-01,1,1 +2007-01-01,-0.217529873016855,0.23669463638363 +2007-01-02,1.53196800458768,0.154479283092565 +2007-01-03,-0.179414148531688,0.732872787481357 +2007-01-04,-0.34541895305433,2.67195401288337 +2007-01-05,1.36308157727048,1.77663726195027 +2007-01-06,1.84194517680528,3.36995634091707 +2007-01-07,0.530281392375643,-1.84195737868931 +2007-01-08,0.456844553461606,1.87523328963312 +2007-01-09,1.35905801334973,1.54478130510417 +2007-01-10,1.27608018153745,0.776642205200036 +2007-01-11,0.807765654334124,1.87328618841723 +2007-01-12,0.460001737845824,1.1106857798858 +2007-01-13,-0.234991244199412,1.47694085290114 +2007-01-14,1.62981955882565,0.518565899410766 +2007-01-15,0.267991337745133,0.881137803163065 +2007-01-16,0.461356067519436,-0.510835415363863 +2007-01-17,1.05274533392338,1.84781548853864 +2007-01-18,1.58759810235407,0.919350736887847 +2007-01-19,0.910798250271897,0.444865886612813 +2007-01-20,2.53136984201421,-0.247354510388352 +2007-01-21,0.448307815052593,2.0975723813015 +2007-01-22,1.06155056890105,0.332886841755604 +2007-01-23,0.436751382569659,-1.36172869205215 +2007-01-24,1.75434079361525,0.949872608636806 +2007-01-25,-0.0915087128553402,0.836492899270147 +2007-01-26,0.259045088336356,1.57043727699625 +2007-01-27,-0.945371222147577,0.169206679768931 +2007-01-28,0.598758753178153,-0.155387982169515 +2007-01-29,0.923908444203986,1.27032136625352 +2007-01-30,2.45759531829471,1.38048970950148 +2007-01-31,-0.597802551661792,0.100435411718593 +2007-02-01,1.57833088062749,0.736442281052783 +2007-02-02,2.84728247871725,2.52923041720706 +2007-02-03,0.20112801646758,0.820218394227867 +2007-02-04,0.330783891688626,-0.117871575836685 +2007-02-05,2.19643403934764,1.78051607361239 +2007-02-06,1.28433651439804,-0.335330863782928 +2007-02-07,0.156685275463554,1.04769595502872 +2007-02-08,1.14643584163998,-0.0745590940631269 +2007-02-09,1.05675510344477,1.21964330736613 +2007-02-10,1.48964302989163,1.62681379248013 +2007-02-11,0.0890313959971395,0.833170937533103 +2007-02-12,1.34500556519813,-0.789844305388806 +2007-02-13,1.19730129394584,-0.993441506611018 +2007-02-14,2.50410769097511,1.68190018459363 +2007-02-15,0.500619603321642,0.167704339891159 +2007-02-16,-0.837932383721317,1.22768953607984 +2007-02-17,2.26420907937987,1.39805183236129 +2007-02-18,1.01943779233342,1.01303566096006 +2007-02-19,-1.6516542574183,-0.446765965769887 +2007-02-20,0.664659733798599,-2.29926713195933 +2007-02-21,2.22139728643704,2.9469634427798 +2007-02-22,-0.710269483385798,2.2000123230068 +2007-02-23,0.938419606981613,1.89799571954235 +2007-02-24,0.679688378012208,-0.348535666192827 +2007-02-25,1.34111264341224,0.712290012317878 +2007-02-26,0.132056773825026,1.16980736531258 +2007-02-27,1.60466043799838,0.692210230682102 +2007-02-28,1.305436548997,0.776733739735433 +2007-03-01,2.36554103904522,0.725463370434253 +2007-03-02,1.00272108288593,0.266965947028999 +2007-03-03,1.34954132687811,0.502367752619553 +2007-03-04,-0.121217840668098,1.78368596909857 +2007-03-05,0.794312753463377,1.30204256643455 +2007-03-06,-0.331414510388407,1.10827494107121 +2007-03-07,0.677200326525247,0.610377176165785 +2007-03-08,-0.11458605120384,2.46930066653989 +2007-03-09,-0.606847572022917,1.26678710805086 +2007-03-10,0.537885465904514,-0.574550792369274 +2007-03-11,-0.0359442651857305,2.8321869949606 +2007-03-12,0.435085882514671,0.384197892654633 +2007-03-13,2.98420245473607,1.56665268149676 +2007-03-14,2.00537925416718,1.57201321127857 +2007-03-15,0.366951392596131,-1.20773923661117 +2007-03-16,1.66613122466074,1.7155703224606 +2007-03-17,-0.475290176208421,2.4391907119067 +2007-03-18,2.21199630210952,0.0564787938029571 +2007-03-19,-0.89733007534121,1.98167733361517 +2007-03-20,0.7704936465039,0.204187208630914 +2007-03-21,0.0553587559435245,0.189262646208553 +2007-03-22,2.56568387489902,2.38200081737848 +2007-03-23,0.529549369099002,0.850822521327942 +2007-03-24,1.94275240221399,1.71316792478401 +2007-03-25,0.573626246257412,2.1184782600409 +2007-03-26,0.0180391491661054,1.10402596169187 +2007-03-27,1.54901563649578,-0.227796264794409 +2007-03-28,-0.277588572514013,-0.148125783267069 +2007-03-29,0.0253860355753674,2.40978725408083 +2007-03-30,2.12248910248527,2.84395472922855 +2007-03-31,0.903811134530458,1.57165393017338 +2007-04-01,1.64797188558046,2.02627857898986 +2007-04-02,0.954504067589499,2.41098201489776 +2007-04-03,0.98718794574349,0.557251494180333 +2007-04-04,-1.18862635225587,1.19335118398612 +2007-04-05,1.01884923770693,0.396701701018546 +2007-04-06,1.68564235888197,2.11104317804647 +2007-04-07,1.40285106729707,2.82952700961495 +2007-04-08,0.933981490847203,1.89763049527176 +2007-04-09,0.812248475723638,-0.525896300004831 +2007-04-10,4.06848981684062,-0.132491395435415 +2007-04-11,1.66100393721175,0.741529919006386 +2007-04-12,0.842470552604748,-0.127815898188662 +2007-04-13,0.516906592919108,1.42652963796571 +2007-04-14,2.91316051368498,0.358242435842644 +2007-04-15,2.14094649779851,3.00723470204627 +2007-04-16,2.90983670747131,-1.62720884652662 +2007-04-17,1.2826052776302,1.86032239550053 +2007-04-18,0.996254185655035,0.638856701139992 +2007-04-19,0.968134527172702,0.841209263653058 +2007-04-20,0.407050473539953,0.727459395473199 +2007-04-21,0.801966194028208,1.61060212236245 +2007-04-22,2.8161699503107,0.264646671556202 +2007-04-23,2.43956964203104,0.49854405595275 +2007-04-24,1.69667467576475,1.49329102315368 +2007-04-25,1.14305409555977,-0.308909966252053 +2007-04-26,1.82172780911434,-1.38904824545954 +2007-04-27,0.283631650078866,1.10425586880369 +2007-04-28,2.38522115775937,1.00265458445881 +2007-04-29,1.15828368932608,2.10563570413331 +2007-04-30,1.53886094529131,0.961808902736525 +2007-05-01,2.0359120109938,1.60189354445783 +2007-05-02,2.06978517142195,1.37137040390549 +2007-05-03,-0.500466539927713,3.26053996953217 +2007-05-04,2.80223589166336,0.755959781388539 +2007-05-05,1.1029898062672,-0.229794357616761 +2007-05-06,0.950683766159169,-1.30928269111694 +2007-05-07,2.32663576580893,0.852450619874498 +2007-05-08,0.00963010804274844,2.07671047289728 +2007-05-09,1.4588395372144,0.950812794539938 +2007-05-10,0.435479121719761,0.746255949525299 +2007-05-11,1.47987317697104,0.733012939292789 +2007-05-12,1.85058993245995,1.3137922382328 +2007-05-13,3.50828197601271,-0.687739550112597 +2007-05-14,0.210929884045954,0.963319039304413 +2007-05-15,0.453871260307971,-0.00866183797058095 +2007-05-16,2.36985905766601,1.44809166896494 +2007-05-17,1.27690118234276,0.675597414778885 +2007-05-18,2.10642271645894,-0.312857129084119 +2007-05-19,0.173583050444253,0.678020453613819 +2007-05-20,0.553030908552197,-0.00278070493678428 +2007-05-21,2.08986919294885,0.941918576278858 +2007-05-22,-0.411500484007027,2.53186864708584 +2007-05-23,1.61402467141939,0.421837868638456 +2007-05-24,0.557930010619156,0.554206898442595 +2007-05-25,2.41596545012092,1.9377109536111 +2007-05-26,1.5372658218941,1.41701540557568 +2007-05-27,-0.60970778529946,-0.344856107870914 +2007-05-28,2.48695901482752,3.28738744946954 +2007-05-29,0.604980091322159,-0.19961976828103 +2007-05-30,2.73291422658047,1.51165648459948 +2007-05-31,0.161091548923861,1.50211077032101 +2007-06-01,1.75113585991621,1.86141875665746 +2007-06-02,1.20850695337263,2.4255783774875 +2007-06-03,0.165847076952844,0.807585535476741 +2007-06-04,1.22983424908668,1.18086739406559 +2007-06-05,0.872149411610759,2.52897920590051 +2007-06-06,1.43441427033131,2.18900198463698 +2007-06-07,1.95536957295318,1.0764508242848 +2007-06-08,2.14043056328265,1.41947985803005 +2007-06-09,0.887159560648017,0.95893826317485 +2007-06-10,1.31491792238877,0.896463996984854 +2007-06-11,3.39973483350848,2.64228509289349 +2007-06-12,1.29131947052007,-0.720938123365023 +2007-06-13,0.664615933967417,1.6219861007571 +2007-06-14,1.88394913718553,0.946378078948034 +2007-06-15,1.22745872828342,1.31290672518321 +2007-06-16,0.534210311896985,1.88495480833103 +2007-06-17,0.843097766244683,0.616409775312251 +2007-06-18,1.10006922442837,0.451579360885859 +2007-06-19,0.991140955761967,1.72671417995287 +2007-06-20,-0.111116193615988,0.627290329152559 +2007-06-21,2.62536527998344,1.20298121092611 +2007-06-22,0.4053025705843,1.13944593251986 +2007-06-23,1.61558902323344,1.17581952190633 +2007-06-24,1.51827291807388,0.80120295670349 +2007-06-25,0.565265930340422,2.20247390492565 +2007-06-26,1.39747972273939,0.835775057416925 +2007-06-27,-0.290269249525718,1.71432919353744 +2007-06-28,0.868163815476782,-0.488242182550005 +2007-06-29,1.54287858510342,1.62564364573503 +2007-06-30,2.23761082378784,0.591070870626255 +2007-07-01,1.17994032081609,1.4834535567909 diff --git a/pkg/tests/testthat/test.Forecaster.R b/pkg/tests/testthat/test.Forecaster.R index 945320c..e29f196 100644 --- a/pkg/tests/testthat/test.Forecaster.R +++ b/pkg/tests/testthat/test.Forecaster.R @@ -12,80 +12,126 @@ pred_order = c(7,1:6) #will facilitate tests test_that("Average method behave as expected", { - pred00_z = getForecast(data00, indices, "Average", "Zero", Inf, 24) - pred00_p = getForecast(data00, indices, "Average", "Persistence", Inf, 24) - for (i in seq_along(indices)) + pred00_z = computeForecast(data00, indices, "Average", "Zero", Inf, 24) + pred00_p = computeForecast(data00, indices, "Average", "Persistence", Inf, 24) + for (i in 1:7) { #zero jump: should predict true values minus 1 - expect_equal(pred00_z$getSerie(i), rep(pred_order[i],24)) + expect_equal( pred00_z$getSerie(i), rep(pred_order[i],24) ) #persistence jump == 1: should predict true values - expect_equal(pred00_p$getSerie(i), rep(i,24)) + expect_equal( pred00_p$getSerie(i), rep(i,24) ) } #NOTE: days become #1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 (14h-->0h then 1h-->13h) - #No jump between days, thus zero and persistence are equivalent (and wrong) - pred13_z = getForecast(data13, indices, "Average", "Zero", Inf, 24) - pred13_p = getForecast(data13, indices, "Average", "Persistence", Inf, 24) - prediction = c(rep(-13/24,11),rep(11/24,13)) - for (i in seq_along(indices)) + #No jump between days, thus zero and persistence are equivalent (and correct) + pred13_z = computeForecast(data13, indices, "Average", "Zero", Inf, 24) + pred13_p = computeForecast(data13, indices, "Average", "Persistence", Inf, 24) + for (i in 1:7) { - expect_equal(pred13_z$getSerie(i), prediction ) ##TODO: prendre en compte recollement - expect_equal(pred13_p$getSerie(i), prediction ) + expect_equal( pred13_z$getSerie(i), c( rep(i,11), rep(i%%7+1,13) ) ) + expect_equal( pred13_p$getSerie(i), c( rep(i,11), rep(i%%7+1,13) ) ) } #A few extra checks - expect_identical( pred00_sd$getIndexInData(1), dateIndexToInteger("2007-04-01",data00) ) - expect_identical( pred13_dd$getIndexInData(3), dateIndexToInteger("2007-04-03",data13) ) - expect_identical( pred00_dd$getIndexInData(5), dateIndexToInteger("2007-04-05",data00) ) + expect_equal( pred00_p$getIndexInData(2), dateIndexToInteger("2007-04-02",data00) ) + expect_equal( pred00_z$getIndexInData(2), dateIndexToInteger("2007-04-02",data00) ) + expect_equal( pred13_p$getIndexInData(5), dateIndexToInteger("2007-04-05",data13) ) + expect_equal( pred13_z$getIndexInData(5), dateIndexToInteger("2007-04-05",data13) ) }) test_that("Persistence method behave as expected", { - #Situation A: +Zero; always wrong - pred00_sd = getForecast(data00, indices, "Persistence", "Zero", Inf, 24, same_day=TRUE) - pred00_dd = getForecast(data00, indices, "Persistence", "Zero", Inf, 24, same_day=FALSE) - for (i in seq_along(indices)) + #Situation A: +Zero; (generally) correct if jump, wrong otherwise + pred00_sd = computeForecast(data00, indices, "Persistence", "Zero", Inf, 24, same_day=TRUE) + pred00_dd = computeForecast(data00, indices, "Persistence", "Zero", Inf, 24, same_day=FALSE) + for (i in 1:7) { - expect_identical(pred00_sd$getSerie(i), rep(i,24)) - expect_identical(pred00_dd$getSerie(i), rep(i,24)) + expect_equal(pred00_sd$getSerie(i), rep(pred_order[i],24)) + expect_equal(pred00_dd$getSerie(i), rep(pred_order[i],24)) } - pred13_sd = getForecast(data13, indices, "Persistence", "Zero", Inf, 24, same_day=TRUE) - pred13_dd = getForecast(data13, indices, "Persistence", "Zero", Inf, 24, same_day=FALSE) - for (i in seq_along(indices)) + pred13_sd = computeForecast(data13, indices, "Persistence", "Zero", Inf, 24, same_day=TRUE) + pred13_dd = computeForecast(data13, indices, "Persistence", "Zero", Inf, 24, same_day=FALSE) + for (i in 2:6) { - expect_identical(pred13_sd$getSerie(i), c( rep(i,11), rep(i%%7+1,13) ) ) - expect_identical(pred13_dd$getSerie(i), c( rep(i,11), rep(i%%7+1,13) ) ) + expect_equal(pred13_sd$getSerie(i), c( rep(i,11), rep(i%%7+1,13) ) ) + expect_equal(pred13_dd$getSerie(i), c( rep(i,11), rep(i%%7+1,13) ) ) } + #boundaries are special cases: OK if same day, quite wrong otherwise + expect_equal(pred13_sd$getSerie(1), c( rep(1,11), rep(2,13) ) ) + expect_equal(pred13_dd$getSerie(1), c( rep(1,11), rep(-5,13) ) ) + expect_equal(pred13_sd$getSerie(7), c( rep(7,11), rep(1,13) ) ) + expect_equal(pred13_dd$getSerie(7), c( rep(7,11), rep(8,13) ) ) - #Situation B: +Persistence, correct when predict_at==0 - pred00_sd = getForecast(data00, indices, "Persistence", "Persistence", Inf, 24, same_day=TRUE) - pred00_dd = getForecast(data00, indices, "Persistence", "Persistence", Inf, 24, same_day=FALSE) - for (i in seq_along(indices)) + #Situation B: +Persistence, (generally) correct + pred00_sd = computeForecast(data00, indices, "Persistence", "Persistence", Inf, 24, same_day=TRUE) + pred00_dd = computeForecast(data00, indices, "Persistence", "Persistence", Inf, 24, same_day=FALSE) + for (i in 3:7) { - expect_identical(pred00_sd$getSerie(i), rep(i%%7+1,24)) - expect_identical(pred00_dd$getSerie(i), rep(i%%7+1,24)) + expect_equal(pred00_sd$getSerie(i), rep(i,24)) + expect_equal(pred00_dd$getSerie(i), rep(i,24)) } + #boundaries are special cases: OK if same day, quite wrong otherwise + expect_equal(pred00_sd$getSerie(1), rep(1,24) ) + expect_equal(pred00_dd$getSerie(1), rep(8,24) ) + expect_equal(pred00_sd$getSerie(2), rep(2,24) ) + expect_equal(pred00_dd$getSerie(2), rep(-5,24) ) - pred13_sd = getForecast(data13, indices, "Persistence", "Persistence", Inf, 24, same_day=TRUE) - pred13_dd = getForecast(data13, indices, "Persistence", "Persistence", Inf, 24, same_day=FALSE) - for (i in seq_along(indices)) + pred13_sd = computeForecast(data13, indices, "Persistence", "Persistence", Inf, 24, same_day=TRUE) + pred13_dd = computeForecast(data13, indices, "Persistence", "Persistence", Inf, 24, same_day=FALSE) + for (i in 2:6) { - expect_identical(pred13_sd$getSerie(i), c( rep(i,11), rep(i%%7+1,13) ) ) - expect_identical(pred13_dd$getSerie(i), c( rep(i,11), rep(i%%7+1,13) ) ) + expect_equal(pred13_sd$getSerie(i), c( rep(i,11), rep(i%%7+1,13) ) ) + expect_equal(pred13_dd$getSerie(i), c( rep(i,11), rep(i%%7+1,13) ) ) } + #boundaries are special cases: OK if same day, quite wrong otherwise + expect_equal(pred13_sd$getSerie(1), c( rep(1,11), rep(2,13) ) ) + expect_equal(pred13_dd$getSerie(1), c( rep(1,11), rep(-5,13) ) ) + expect_equal(pred13_sd$getSerie(7), c( rep(7,11), rep(1,13) ) ) + expect_equal(pred13_dd$getSerie(7), c( rep(7,11), rep(8,13) ) ) #A few extra checks - expect_identical( pred13_sd$getIndexInData(1), dateIndexToInteger("2007-04-01",data12) ) - expect_identical( pred00_dd$getIndexInData(3), dateIndexToInteger("2007-04-03",data00) ) - expect_identical( pred13_dd$getIndexInData(5), dateIndexToInteger("2007-04-05",data13) ) + expect_equal( pred00_sd$getIndexInData(3), dateIndexToInteger("2007-04-03",data00) ) + expect_equal( pred00_dd$getIndexInData(6), dateIndexToInteger("2007-04-06",data00) ) + expect_equal( pred13_sd$getIndexInData(3), dateIndexToInteger("2007-04-03",data13) ) + expect_equal( pred13_dd$getIndexInData(6), dateIndexToInteger("2007-04-06",data13) ) }) -test_that("Neighbors+Zero method behave as expected", +test_that("Neighbors method behave as expected", { -}) + #Situation A: +Zero; correct if jump, wrong otherwise + pred00 = computeForecast(data00, indices, "Neighbors", "Zero", Inf, 24, simtype="mix") + for (i in 1:7) + expect_equal(pred00$getSerie(i), rep(pred_order[i],24)) -test_that("Neighbors+Neighbors method behave as expected", -{ + pred13 = computeForecast(data13, indices, "Persistence", "Zero", Inf, 24, simtype="mix") + for (i in 1:7) + expect_equal(pred13$getSerie(i), c( rep(i,11), rep(i%%7+1,13) ) ) + + #Situation B: +Neighbors, always predict bad (small, averaged) jump + pred00 = computeForecast(data00, indices, "Neighbors", "Neighbors", Inf, 24, simtype="endo") + #Concerning weights, there are 12+(1 if i>=2) gaps at -6 and 90-12+(i-2 if i>=3) gaps at 1 + #Thus, predicted jump is respectively + # (12*-6+78)/90 = 0.06666667 + # (13*-6+78)/91 = 0 + # (13*-6+79)/92 = 0.01086957 + # (13*-6+80)/93 = 0.02150538 + # (13*-6+81)/94 = 0.03191489 + # (13*-6+82)/95 = 0.04210526 + # (13*-6+83)/96 = 0.05208333 + jumps = c(0.06666667, 0, 0.01086957, 0.02150538, 0.03191489, 0.04210526, 0.05208333) + for (i in 1:7) + expect_equal(pred00$getSerie(i), rep(pred_order[i]+jumps[i],24)) + + #Next lines commented out because too unpredictable results (tendency to flatten everything...) +# pred13 = computeForecast(data13, indices, "Neighbors", "Neighbors", Inf, 24, simtype="endo") +# for (i in 1:7) +# expect_equal(pred13$getSerie(i), c( rep(i,11), rep(i%%7+1,13) ) ) + + #A few extra checks + expect_equal( pred00$getIndexInData(1), dateIndexToInteger("2007-04-01",data00) ) + expect_equal( pred00$getIndexInData(4), dateIndexToInteger("2007-04-04",data00) ) + expect_equal( pred13$getIndexInData(1), dateIndexToInteger("2007-04-01",data13) ) + expect_equal( pred13$getIndexInData(4), dateIndexToInteger("2007-04-04",data13) ) }) diff --git a/reports/report_2017-03-01.13h_average.ipynb b/reports/report_2017-03-01.13h_average.ipynb index b3f1336..b186668 100644 --- a/reports/report_2017-03-01.13h_average.ipynb +++ b/reports/report_2017-03-01.13h_average.ipynb @@ -19,8 +19,9 @@ }, "outputs": [], "source": [ - "data = getData(ts_data=\"../pkg/data/pm10_mesures_H_loc.csv\", exo_data=\"../pkg/data/meteo_extra_noNAs.csv\",\n", - " input_tz = \"Europe/Paris\", working_tz=\"Europe/Paris\", predict_at=7)" + "ts_data = read.csv(system.file(\"extdata\",\"pm10_mesures_H_loc.csv\",package=\"talweg\"))\n", + "exo_data = read.csv(system.file(\"extdata\",\"meteo_extra_noNAs.csv\",package=\"talweg\"))\n", + "data = getData(ts_data, exo_data, input_tz = \"Europe/Paris\", working_tz=\"Europe/Paris\", predict_at=13)" ] }, { @@ -35,6 +36,8 @@ " * same_season=FALSE : les indices pour la validation croisée ne tiennent pas compte des saisons\n", " * mix_strategy=\"mult\" : on multiplie les poids (au lieu d'en éteindre)\n", "\n", + "(valeurs par défaut).\n", + "\n", "J'ai systématiquement comparé à deux autres approches : la persistence et la moyennes des lendemains des jours \"similaires\" dans tout le passé ; à chaque fois sans prédiction du saut (sauf pour Neighbors : prédiction basée sur les poids calculés).\n", "\n", "Ensuite j'affiche les erreurs, quelques courbes prévues/mesurées, quelques filaments puis les histogrammes de quelques poids. Concernant les graphes de filaments, la moitié gauche du graphe correspond aux jours similaires au jour courant, tandis que la moitié droite affiche les lendemains : ce sont donc les voisinages tels qu'utilisés dans l'algorithme.\n", @@ -50,12 +53,11 @@ }, "outputs": [], "source": [ - "indices = seq(as.Date(\"2015-01-18\"),as.Date(\"2015-01-24\"),\"days\")\n", - "p_ch_nn = getForecast(data,indices,\"Neighbors\",\"Neighbors\",simtype=\"mix\",same_season=FALSE,mix_strategy=\"mult\")\n", - "p_ch_pz = getForecast(data, indices, \"Persistence\", \"Zero\", same_day=TRUE)\n", - "p_ch_az = getForecast(data, indices, \"Average\", \"Zero\") #, memory=183)\n", - "#p_ch_zz = getForecast(data, indices, \"Zero\", \"Zero\")\n", - "#p_ch_l = getForecast(data, indices, \"Level\", same_day=FALSE)" + "indices_ch = seq(as.Date(\"2015-01-18\"),as.Date(\"2015-01-24\"),\"days\")\n", + "p_ch_nn = computeForecast(data,indices_ch, \"Neighbors\", \"Neighbors\", simtype=\"mix\")\n", + "p_ch_pz = computeForecast(data, indices_ch, \"Persistence\", \"Zero\", same_day=TRUE)\n", + "p_ch_az = computeForecast(data, indices_ch, \"Average\", \"Zero\") #, memory=183)\n", + "#p_ch_zz = computeForecast(data, indices_ch, \"Zero\", \"Zero\")" ] }, { @@ -66,24 +68,16 @@ }, "outputs": [], "source": [ - "e_ch_nn = getError(data, p_ch_nn)\n", - "e_ch_pz = getError(data, p_ch_pz)\n", - "e_ch_az = getError(data, p_ch_az)\n", - "#e_ch_zz = getError(data, p_ch_zz)\n", - "#e_ch_l = getError(data, p_ch_l)\n", - "options(repr.plot.width=9, repr.plot.height=6)\n", + "e_ch_nn = computeError(data, p_ch_nn)\n", + "e_ch_pz = computeError(data, p_ch_pz)\n", + "e_ch_az = computeError(data, p_ch_az)\n", + "#e_ch_zz = computeError(data, p_ch_zz)\n", + "options(repr.plot.width=9, repr.plot.height=7)\n", "plotError(list(e_ch_nn, e_ch_pz, e_ch_az), cols=c(1,2,colors()[258]))\n", "\n", "#Noir: neighbors, rouge: persistence, vert: moyenne" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "La méthode Neighbors fait assez nettement mieux que les autres dans ce cas." - ] - }, { "cell_type": "code", "execution_count": null, @@ -104,7 +98,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Prédictions d'autant plus lisses que le jour à prévoir est atypique (pollué)." + "Prédictions très lisses." ] }, { @@ -120,13 +114,6 @@ "plotPredReal(data, p_ch_az, 4)" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Les erreurs sont proches, mais les courbes prédites très différentes : avantage à \"Neighbors\"" - ] - }, { "cell_type": "code", "execution_count": null, @@ -136,8 +123,8 @@ "outputs": [], "source": [ "par(mfrow=c(1,2))\n", - "f3 = computeFilaments(data, p_ch_nn$getIndexInData(3), plot=TRUE)\n", - "f4 = computeFilaments(data, p_ch_nn$getIndexInData(4), plot=TRUE)" + "f3_ch = computeFilaments(data, p_ch_nn$getIndexInData(3), plot=TRUE)\n", + "f4_ch = computeFilaments(data, p_ch_nn$getIndexInData(4), plot=TRUE)" ] }, { @@ -149,17 +136,21 @@ "outputs": [], "source": [ "par(mfrow=c(2,2))\n", - "plotFilamentsBox(data, f3$indices)\n", - "plotFilamentsBox(data, f3$indices+1)\n", - "plotFilamentsBox(data, f4$indices)\n", - "plotFilamentsBox(data, f4$indices+1)" + "options(repr.plot.width=9, repr.plot.height=7)\n", + "plotFilamentsBox(data, f3_ch$indices)\n", + "plotFilamentsBox(data, f3_ch$indices+1)\n", + "plotFilamentsBox(data, f4_ch$indices)\n", + "plotFilamentsBox(data, f4_ch$indices+1)\n", + "\n", + "#En haut : jour 3 + lendemain (4) ; en bas : jour 4 + lendemain (5)\n", + "#À gauche : premières 24h ; à droite : 24h suivantes" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Beaucoup de courbes similaires dans le cas peu pollué, très peu pour un jour pollué." + "Peu de voisins, les courbes sont assez isolées (en particulier les lendemains)." ] }, { @@ -171,18 +162,18 @@ "outputs": [], "source": [ "par(mfrow=c(1,2))\n", - "plotSimils(p_ch_nn, 6)\n", - "plotSimils(p_ch_nn, 6)\n", - "#plotSimils(p_ch_nn, 5)\n", + "options(repr.plot.width=9, repr.plot.height=4)\n", + "plotRelativeVariability(data, f3_ch$indices)\n", + "plotRelativeVariability(data, f4_ch$indices)\n", "\n", - "#Non pollué à gauche, pollué au milieu, autre pollué à droite" + "#Variabilité sur 60 courbes au hasard en rouge ; sur nos 60 voisins (+ lendemains) en noir" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "La plupart des poids très proches de zéro ; pas pour le jour 5 : autre type de jour, cf. ci-dessous." + "Il faudrait que la courbe noire soit nettement plus basse que la courbe rouge." ] }, { @@ -194,15 +185,17 @@ "outputs": [], "source": [ "par(mfrow=c(1,2))\n", - "plotPredReal(data, p_ch_nn, 5)\n", - "plotFilaments(data, p_ch_nn$getIndexInData(5))" + "plotSimils(p_ch_nn, 3)\n", + "plotSimils(p_ch_nn, 4)\n", + "\n", + "#Non pollué à gauche, pollué à droite" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "

Pollution par épandage

" + "Poids plus concentrés autour de 0 pour un jour plus pollué." ] }, { @@ -213,12 +206,16 @@ }, "outputs": [], "source": [ - "indices = seq(as.Date(\"2015-03-15\"),as.Date(\"2015-03-21\"),\"days\")\n", - "p_ep_nn = getForecast(data,indices,\"Neighbors\",\"Neighbors\",simtype=\"mix\",same_season=FALSE,mix_strategy=\"mult\")\n", - "p_ep_pz = getForecast(data, indices, \"Persistence\", \"Zero\", same_day=TRUE)\n", - "p_ep_az = getForecast(data, indices, \"Average\", \"Zero\") #, memory=183)\n", - "#p_ep_zz = getForecast(data, indices, \"Zero\", \"Zero\")\n", - "#p_ep_l = getForecast(data, indices, \"Level\", same_day=TRUE)" + "#Fenêtres sélectionnées dans ]0,10] / endo à gauche, exo à droite\n", + "p_ch_nn$getParams(3)$window\n", + "p_ch_nn$getParams(4)$window" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Pollution par épandage

" ] }, { @@ -229,7 +226,11 @@ }, "outputs": [], "source": [ - "class(p_ep_nn)" + "indices_ep = seq(as.Date(\"2015-03-15\"),as.Date(\"2015-03-21\"),\"days\")\n", + "p_ep_nn = computeForecast(data,indices_ep, \"Neighbors\", \"Neighbors\", simtype=\"mix\")\n", + "p_ep_pz = computeForecast(data, indices_ep, \"Persistence\", \"Zero\", same_day=TRUE)\n", + "p_ep_az = computeForecast(data, indices_ep, \"Average\", \"Zero\") #, memory=183)\n", + "#p_ep_zz = computeForecast(data, indices_ep, \"Zero\", \"Zero\")" ] }, { @@ -240,12 +241,11 @@ }, "outputs": [], "source": [ - "e_ep_nn = getError(data, p_ep_nn)\n", - "e_ep_pz = getError(data, p_ep_pz)\n", - "e_ep_az = getError(data, p_ep_az)\n", - "#e_ep_zz = getError(data, p_ep_zz)\n", - "#e_ep_l = getError(data, p_ep_l)\n", - "options(repr.plot.width=9, repr.plot.height=6)\n", + "e_ep_nn = computeError(data, p_ep_nn)\n", + "e_ep_pz = computeError(data, p_ep_pz)\n", + "e_ep_az = computeError(data, p_ep_az)\n", + "#e_ep_zz = computeError(data, p_ep_zz)\n", + "options(repr.plot.width=9, repr.plot.height=7)\n", "plotError(list(e_ep_nn, e_ep_pz, e_ep_az), cols=c(1,2,colors()[258]))\n", "\n", "#Noir: neighbors, rouge: persistence, vert: moyenne" @@ -255,7 +255,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Cette fois les deux méthodes naïves font en moyenne moins d'erreurs que Neighbors. Prédiction trop difficile ?" + "Neighbors et Average comparables, Persistence moins performante." ] }, { @@ -268,8 +268,8 @@ "source": [ "par(mfrow=c(1,2))\n", "options(repr.plot.width=9, repr.plot.height=4)\n", - "plotPredReal(data, p_ep_nn, 5)\n", - "plotPredReal(data, p_ep_nn, 2)\n", + "plotPredReal(data, p_ep_nn, 6)\n", + "plotPredReal(data, p_ep_nn, 3)\n", "\n", "#Bleu: prévue, noir: réalisée" ] @@ -278,7 +278,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "À gauche un jour \"bien\" prévu, à droite le pic d'erreur (jour 6)." + "À gauche un jour \"bien\" prévu, à droite le pic d'erreur (jour 3)." ] }, { @@ -290,15 +290,15 @@ "outputs": [], "source": [ "par(mfrow=c(1,2))\n", - "plotPredReal(data, p_ep_pz, 4)\n", - "plotPredReal(data, p_ep_pz, 6)" + "plotPredReal(data, p_ep_az, 6)\n", + "plotPredReal(data, p_ep_az, 3)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Bonnes performances de la persistence (par chance...)" + "Average : autre type de prévision." ] }, { @@ -310,8 +310,27 @@ "outputs": [], "source": [ "par(mfrow=c(1,2))\n", - "plotFilaments(data, p_ep_nn$getIndexInData(5))\n", - "plotFilaments(data, p_ep_nn$getIndexInData(2))" + "f6_ep = computeFilaments(data, p_ep_nn$getIndexInData(6), plot=TRUE)\n", + "f3_ep = computeFilaments(data, p_ep_nn$getIndexInData(3), plot=TRUE)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "par(mfrow=c(2,2))\n", + "options(repr.plot.width=9, repr.plot.height=7)\n", + "plotFilamentsBox(data, f6_ep$indices)\n", + "plotFilamentsBox(data, f6_ep$indices+1)\n", + "plotFilamentsBox(data, f3_ep$indices)\n", + "plotFilamentsBox(data, f3_ep$indices+1)\n", + "\n", + "#En haut : jour 4 + lendemain (5) ; en bas : jour 6 + lendemain (7)\n", + "#À gauche : premières 24h ; à droite : 24h suivantes" ] }, { @@ -323,8 +342,31 @@ "outputs": [], "source": [ "par(mfrow=c(1,2))\n", - "plotSimils(p_ep_nn, 5)\n", - "plotSimils(p_ep_nn, 2)" + "options(repr.plot.width=9, repr.plot.height=4)\n", + "plotRelativeVariability(data, f6_ep$indices)\n", + "plotRelativeVariability(data, f3_ep$indices)\n", + "\n", + "#Variabilité sur 60 courbes au hasard en rouge ; sur nos 60 voisins (+ lendemains) en noir" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Il faudrait que la courbe noire soit nettement plus basse que la courbe rouge..." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "par(mfrow=c(1,2))\n", + "plotSimils(p_ep_nn, 6)\n", + "plotSimils(p_ep_nn, 3)" ] }, { @@ -334,11 +376,24 @@ "Même observation concernant les poids : concentrés près de zéro pour les prédictions avec peu de voisins." ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "#Fenêtres sélectionnées dans ]0,10] / endo à gauche, exo à droite\n", + "p_ep_nn$getParams(6)$window\n", + "p_ep_nn$getParams(3)$window" + ] + }, { "cell_type": "markdown", "metadata": {}, "source": [ - "## Semaine non polluée" + "

Semaine non polluée

" ] }, { @@ -349,12 +404,11 @@ }, "outputs": [], "source": [ - "indices = seq(as.Date(\"2015-04-26\"),as.Date(\"2015-05-02\"),\"days\")\n", - "p_np_nn = getForecast(data,indices,\"Neighbors\",\"Neighbors\",simtype=\"mix\",same_season=FALSE,mix_strategy=\"mult\")\n", - "p_np_pz = getForecast(data, indices, \"Persistence\", \"Zero\", same_day=FALSE)\n", - "p_np_az = getForecast(data, indices, \"Average\", \"Zero\") #, memory=183)\n", - "#p_np_zz = getForecast(data, indices, \"Zero\", \"Zero\")\n", - "#p_np_l = getForecast(data, indices, \"Level\", same_day=FALSE)" + "indices_np = seq(as.Date(\"2015-04-26\"),as.Date(\"2015-05-02\"),\"days\")\n", + "p_np_nn = computeForecast(data,indices_np, \"Neighbors\", \"Neighbors\", simtype=\"mix\")\n", + "p_np_pz = computeForecast(data, indices_np, \"Persistence\", \"Zero\", same_day=FALSE)\n", + "p_np_az = computeForecast(data, indices_np, \"Average\", \"Zero\") #, memory=183)\n", + "#p_np_zz = computeForecast(data, indices_np, \"Zero\", \"Zero\")" ] }, { @@ -365,12 +419,11 @@ }, "outputs": [], "source": [ - "e_np_nn = getError(data, p_np_nn)\n", - "e_np_pz = getError(data, p_np_pz)\n", - "e_np_az = getError(data, p_np_az)\n", - "#e_np_zz = getError(data, p_np_zz)\n", - "#e_np_l = getError(data, p_np_l)\n", - "options(repr.plot.width=9, repr.plot.height=6)\n", + "e_np_nn = computeError(data, p_np_nn)\n", + "e_np_pz = computeError(data, p_np_pz)\n", + "e_np_az = computeError(data, p_np_az)\n", + "#e_np_zz = computeError(data, p_np_zz)\n", + "options(repr.plot.width=9, repr.plot.height=7)\n", "plotError(list(e_np_nn, e_np_pz, e_np_az), cols=c(1,2,colors()[258]))\n", "\n", "#Noir: neighbors, rouge: persistence, vert: moyenne" @@ -380,7 +433,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Performances des méthodes \"Average\" et \"Neighbors\" comparables ; mauvais résultats pour la persistence." + "Performances des méthodes \"Average\" et \"Neighbors\" identiques ; mauvais résultats pour la persistence." ] }, { @@ -393,17 +446,23 @@ "source": [ "par(mfrow=c(1,2))\n", "options(repr.plot.width=9, repr.plot.height=4)\n", + "plotPredReal(data, p_np_nn, 5)\n", "plotPredReal(data, p_np_nn, 3)\n", - "plotPredReal(data, p_np_nn, 6)\n", "\n", "#Bleu: prévue, noir: réalisée" ] }, { - "cell_type": "markdown", - "metadata": {}, + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], "source": [ - "Les \"bonnes\" prédictions (à gauche) sont tout de même trop lissées." + "par(mfrow=c(1,2))\n", + "plotPredReal(data, p_np_az, 5)\n", + "plotPredReal(data, p_np_az, 3)" ] }, { @@ -415,15 +474,34 @@ "outputs": [], "source": [ "par(mfrow=c(1,2))\n", - "plotPredReal(data, p_np_az, 3)\n", - "plotPredReal(data, p_np_az, 6)" + "f5_np = computeFilaments(data, p_np_nn$getIndexInData(5), plot=TRUE)\n", + "f3_np = computeFilaments(data, p_np_nn$getIndexInData(3), plot=TRUE)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Légèrement meilleur ajustement par la méthode \"Average\" ; très net à droite." + "Jours \"typiques\", donc beaucoup de voisins." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "par(mfrow=c(2,2))\n", + "options(repr.plot.width=9, repr.plot.height=7)\n", + "plotFilamentsBox(data, f5_np$indices)\n", + "plotFilamentsBox(data, f5_np$indices+1)\n", + "plotFilamentsBox(data, f3_np$indices)\n", + "plotFilamentsBox(data, f3_np$indices+1)\n", + "\n", + "#En haut : jour 3 + lendemain (4) ; en bas : jour 6 + lendemain (7)\n", + "#À gauche : premières 24h ; à droite : 24h suivantes" ] }, { @@ -435,15 +513,18 @@ "outputs": [], "source": [ "par(mfrow=c(1,2))\n", - "plotFilaments(data, p_np_nn$getIndexInData(3))\n", - "plotFilaments(data, p_np_nn$getIndexInData(6))" + "options(repr.plot.width=9, repr.plot.height=4)\n", + "plotRelativeVariability(data, f5_np$indices)\n", + "plotRelativeVariability(data, f3_np$indices)\n", + "\n", + "#Variabilité sur 60 courbes au hasard en rouge ; sur nos 60 voisins (+ lendemains) en noir" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Jours \"typiques\", donc beaucoup de voisins." + "Situation meilleure que dans les autres cas, mais assez difficile tout de même." ] }, { @@ -454,17 +535,29 @@ }, "outputs": [], "source": [ - "par(mfrow=c(1,3))\n", - "plotSimils(p_np_nn, 3)\n", - "plotSimils(p_np_nn, 4)\n", - "plotSimils(p_np_nn, 6)" + "par(mfrow=c(1,2))\n", + "plotSimils(p_np_nn, 5)\n", + "plotSimils(p_np_nn, 3)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Répartition idéale des poids : quelques uns au-delà de 0.3-0.4, le reste très proche de zéro." + "Répartition des poids difficile à interpréter." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "#Fenêtres sélectionnées dans ]0,10] / endo à gauche, exo à droite\n", + "p_np_nn$getParams(5)$window\n", + "p_np_nn$getParams(3)$window" ] }, { diff --git a/reports/report_2017-03-01.7h_average.ipynb b/reports/report_2017-03-01.7h_average.ipynb index 5da76eb..1776673 100644 --- a/reports/report_2017-03-01.7h_average.ipynb +++ b/reports/report_2017-03-01.7h_average.ipynb @@ -19,8 +19,9 @@ }, "outputs": [], "source": [ - "data = getData(ts_data=\"../pkg/data/pm10_mesures_H_loc.csv\", exo_data=\"../pkg/data/meteo_extra_noNAs.csv\",\n", - " input_tz = \"Europe/Paris\", working_tz=\"Europe/Paris\", predict_at=7)" + "ts_data = read.csv(system.file(\"extdata\",\"pm10_mesures_H_loc.csv\",package=\"talweg\"))\n", + "exo_data = read.csv(system.file(\"extdata\",\"meteo_extra_noNAs.csv\",package=\"talweg\"))\n", + "data = getData(ts_data, exo_data, input_tz = \"Europe/Paris\", working_tz=\"Europe/Paris\", predict_at=7)" ] }, { @@ -35,6 +36,8 @@ " * same_season=FALSE : les indices pour la validation croisée ne tiennent pas compte des saisons\n", " * mix_strategy=\"mult\" : on multiplie les poids (au lieu d'en éteindre)\n", "\n", + "(valeurs par défaut).\n", + "\n", "J'ai systématiquement comparé à deux autres approches : la persistence et la moyennes des lendemains des jours \"similaires\" dans tout le passé ; à chaque fois sans prédiction du saut (sauf pour Neighbors : prédiction basée sur les poids calculés).\n", "\n", "Ensuite j'affiche les erreurs, quelques courbes prévues/mesurées, quelques filaments puis les histogrammes de quelques poids. Concernant les graphes de filaments, la moitié gauche du graphe correspond aux jours similaires au jour courant, tandis que la moitié droite affiche les lendemains : ce sont donc les voisinages tels qu'utilisés dans l'algorithme.\n", @@ -51,10 +54,10 @@ "outputs": [], "source": [ "indices_ch = seq(as.Date(\"2015-01-18\"),as.Date(\"2015-01-24\"),\"days\")\n", - "p_ch_nn = getForecast(data,indices_ch,\"Neighbors\",\"Neighbors\",simtype=\"mix\",same_season=FALSE,mix_strategy=\"mult\")\n", - "p_ch_pz = getForecast(data, indices_ch, \"Persistence\", \"Zero\", same_day=TRUE)\n", - "p_ch_az = getForecast(data, indices_ch, \"Average\", \"Zero\") #, memory=183)\n", - "#p_ch_zz = getForecast(data, indices_ch, \"Zero\", \"Zero\")" + "p_ch_nn = computeForecast(data,indices_ch, \"Neighbors\", \"Neighbors\", simtype=\"mix\")\n", + "p_ch_pz = computeForecast(data, indices_ch, \"Persistence\", \"Zero\", same_day=TRUE)\n", + "p_ch_az = computeForecast(data, indices_ch, \"Average\", \"Zero\") #, memory=183)\n", + "#p_ch_zz = computeForecast(data, indices_ch, \"Zero\", \"Zero\")" ] }, { @@ -65,23 +68,16 @@ }, "outputs": [], "source": [ - "e_ch_nn = getError(data, p_ch_nn)\n", - "e_ch_pz = getError(data, p_ch_pz)\n", - "e_ch_az = getError(data, p_ch_az)\n", - "#e_ch_zz = getError(data, p_ch_zz)\n", + "e_ch_nn = computeError(data, p_ch_nn)\n", + "e_ch_pz = computeError(data, p_ch_pz)\n", + "e_ch_az = computeError(data, p_ch_az)\n", + "#e_ch_zz = computeError(data, p_ch_zz)\n", "options(repr.plot.width=9, repr.plot.height=7)\n", "plotError(list(e_ch_nn, e_ch_pz, e_ch_az), cols=c(1,2,colors()[258]))\n", "\n", "#Noir: neighbors, rouge: persistence, vert: moyenne" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "La méthode Neighbors fait assez nettement mieux que les autres dans ce cas." - ] - }, { "cell_type": "code", "execution_count": null, @@ -118,13 +114,6 @@ "plotPredReal(data, p_ch_az, 4)" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Les erreurs sont proches, mais les courbes prédites très différentes : avantage à \"Neighbors\"" - ] - }, { "cell_type": "code", "execution_count": null, @@ -184,7 +173,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Dans la situation idéale, il faudrait que la courbe noire soit nettement plus basse que la courbe rouge. Ce n'est pas très clair à J+1, surtout en soirée (de 21h à 0h)." + "Il faudrait que la courbe noire soit nettement plus basse que la courbe rouge." ] }, { @@ -223,6 +212,19 @@ "ignored <- computeFilaments(data, p_ch_nn$getIndexInData(5), plot=TRUE)" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "#Fenêtres sélectionnées dans ]0,10] / endo à gauche, exo à droite\n", + "p_ch_nn$getParams(3)$window\n", + "p_ch_nn$getParams(4)$window" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -239,10 +241,10 @@ "outputs": [], "source": [ "indices_ep = seq(as.Date(\"2015-03-15\"),as.Date(\"2015-03-21\"),\"days\")\n", - "p_ep_nn = getForecast(data,indices_ep,\"Neighbors\",\"Neighbors\",simtype=\"mix\",same_season=FALSE,mix_strategy=\"mult\")\n", - "p_ep_pz = getForecast(data, indices_ep, \"Persistence\", \"Zero\", same_day=TRUE)\n", - "p_ep_az = getForecast(data, indices_ep, \"Average\", \"Zero\") #, memory=183)\n", - "#p_ep_zz = getForecast(data, indices_ep, \"Zero\", \"Zero\")" + "p_ep_nn = computeForecast(data,indices_ep, \"Neighbors\", \"Neighbors\", simtype=\"mix\")\n", + "p_ep_pz = computeForecast(data, indices_ep, \"Persistence\", \"Zero\", same_day=TRUE)\n", + "p_ep_az = computeForecast(data, indices_ep, \"Average\", \"Zero\") #, memory=183)\n", + "#p_ep_zz = computeForecast(data, indices_ep, \"Zero\", \"Zero\")" ] }, { @@ -253,23 +255,16 @@ }, "outputs": [], "source": [ - "e_ep_nn = getError(data, p_ep_nn)\n", - "e_ep_pz = getError(data, p_ep_pz)\n", - "e_ep_az = getError(data, p_ep_az)\n", - "#e_ep_zz = getError(data, p_ep_zz)\n", + "e_ep_nn = computeError(data, p_ep_nn)\n", + "e_ep_pz = computeError(data, p_ep_pz)\n", + "e_ep_az = computeError(data, p_ep_az)\n", + "#e_ep_zz = computeError(data, p_ep_zz)\n", "options(repr.plot.width=9, repr.plot.height=7)\n", "plotError(list(e_ep_nn, e_ep_pz, e_ep_az), cols=c(1,2,colors()[258]))\n", "\n", "#Noir: neighbors, rouge: persistence, vert: moyenne" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Cette fois les deux méthodes naïves font en moyenne moins d'erreurs que Neighbors. Prédiction trop difficile ?" - ] - }, { "cell_type": "code", "execution_count": null, @@ -302,15 +297,8 @@ "outputs": [], "source": [ "par(mfrow=c(1,2))\n", - "plotPredReal(data, p_ep_pz, 4)\n", - "plotPredReal(data, p_ep_pz, 6)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Assez bonnes performances de la persistence (par chance...)" + "plotPredReal(data, p_ep_az, 4)\n", + "plotPredReal(data, p_ep_az, 6)" ] }, { @@ -349,7 +337,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "\"Voisinages\" catastrophiques : les jours 4 et 6 sont trop atypiques ; de façon étonnante les lendemains sont en revanche assez \"centraux\" parmi les lendemains des (mauvais) voisins." + "\"Voisinages\" catastrophiques : les jours 4 et 6 sont trop atypiques." ] }, { @@ -372,7 +360,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Dans la situation idéale, il faudrait que la courbe noire soit nettement plus basse que la courbe rouge. Ce n'est pas vérifié à J+1, sauf pour le jour 6 en début et fin de journée." + "Il faudrait que la courbe noire soit nettement plus basse que la courbe rouge." ] }, { @@ -395,6 +383,19 @@ "Poids très concentrés près de zéro pour les prédictions avec peu de voisins." ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "#Fenêtres sélectionnées dans ]0,10] / endo à gauche, exo à droite\n", + "p_ep_nn$getParams(4)$window\n", + "p_ep_nn$getParams(6)$window" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -411,10 +412,10 @@ "outputs": [], "source": [ "indices_np = seq(as.Date(\"2015-04-26\"),as.Date(\"2015-05-02\"),\"days\")\n", - "p_np_nn = getForecast(data,indices_np,\"Neighbors\",\"Neighbors\",simtype=\"mix\",same_season=FALSE,mix_strategy=\"mult\")\n", - "p_np_pz = getForecast(data, indices_np, \"Persistence\", \"Zero\", same_day=FALSE)\n", - "p_np_az = getForecast(data, indices_np, \"Average\", \"Zero\") #, memory=183)\n", - "#p_np_zz = getForecast(data, indices_np, \"Zero\", \"Zero\")" + "p_np_nn = computeForecast(data,indices_np, \"Neighbors\", \"Neighbors\", simtype=\"mix\")\n", + "p_np_pz = computeForecast(data, indices_np, \"Persistence\", \"Zero\", same_day=FALSE)\n", + "p_np_az = computeForecast(data, indices_np, \"Average\", \"Zero\") #, memory=183)\n", + "#p_np_zz = computeForecast(data, indices_np, \"Zero\", \"Zero\")" ] }, { @@ -425,10 +426,10 @@ }, "outputs": [], "source": [ - "e_np_nn = getError(data, p_np_nn)\n", - "e_np_pz = getError(data, p_np_pz)\n", - "e_np_az = getError(data, p_np_az)\n", - "#e_np_zz = getError(data, p_np_zz)\n", + "e_np_nn = computeError(data, p_np_nn)\n", + "e_np_pz = computeError(data, p_np_pz)\n", + "e_np_az = computeError(data, p_np_az)\n", + "#e_np_zz = computeError(data, p_np_zz)\n", "options(repr.plot.width=9, repr.plot.height=7)\n", "plotError(list(e_np_nn, e_np_pz, e_np_az), cols=c(1,2,colors()[258]))\n", "\n", @@ -452,19 +453,12 @@ "source": [ "par(mfrow=c(1,2))\n", "options(repr.plot.width=9, repr.plot.height=4)\n", - "plotPredReal(data, p_np_nn, 3)\n", + "plotPredReal(data, p_np_nn, 5)\n", "plotPredReal(data, p_np_nn, 6)\n", "\n", "#Bleu: prévue, noir: réalisée" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Les \"bonnes\" prédictions (à gauche) sont tout de même trop lissées." - ] - }, { "cell_type": "code", "execution_count": null, @@ -474,17 +468,10 @@ "outputs": [], "source": [ "par(mfrow=c(1,2))\n", - "plotPredReal(data, p_np_az, 3)\n", + "plotPredReal(data, p_np_az, 5)\n", "plotPredReal(data, p_np_az, 6)" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Légèrement meilleur ajustement par la méthode \"Average\" ; plutôt net à droite." - ] - }, { "cell_type": "code", "execution_count": null, @@ -494,7 +481,7 @@ "outputs": [], "source": [ "par(mfrow=c(1,2))\n", - "f3_np = computeFilaments(data, p_np_nn$getIndexInData(3), plot=TRUE)\n", + "f5_np = computeFilaments(data, p_np_nn$getIndexInData(5), plot=TRUE)\n", "f6_np = computeFilaments(data, p_np_nn$getIndexInData(6), plot=TRUE)" ] }, @@ -508,8 +495,8 @@ "source": [ "par(mfrow=c(2,2))\n", "options(repr.plot.width=9, repr.plot.height=7)\n", - "plotFilamentsBox(data, f3_np$indices)\n", - "plotFilamentsBox(data, f3_np$indices+1)\n", + "plotFilamentsBox(data, f5_np$indices)\n", + "plotFilamentsBox(data, f5_np$indices+1)\n", "plotFilamentsBox(data, f6_np$indices)\n", "plotFilamentsBox(data, f6_np$indices+1)\n", "\n", @@ -534,7 +521,7 @@ "source": [ "par(mfrow=c(1,2))\n", "options(repr.plot.width=9, repr.plot.height=4)\n", - "plotRelativeVariability(data, f3_np$indices)\n", + "plotRelativeVariability(data, f5_np$indices)\n", "plotRelativeVariability(data, f6_np$indices)\n", "\n", "#Variabilité sur 60 courbes au hasard en rouge ; sur nos 60 voisins (+ lendemains) en noir" @@ -544,7 +531,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Situation quasi-idéale : la courbe noire est toujours assez nettement en dessous." + "Bonne situation : la courbe noire est toujours assez nettement en dessous." ] }, { @@ -555,9 +542,8 @@ }, "outputs": [], "source": [ - "par(mfrow=c(1,3))\n", - "plotSimils(p_np_nn, 3)\n", - "plotSimils(p_np_nn, 4)\n", + "par(mfrow=c(1,2))\n", + "plotSimils(p_np_nn, 5)\n", "plotSimils(p_np_nn, 6)" ] }, @@ -568,6 +554,19 @@ "Répartition idéale des poids : quelques uns au-delà de 0.3-0.4, le reste très proche de zéro." ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "#Fenêtres sélectionnées dans ]0,10] / endo à gauche, exo à droite\n", + "p_np_nn$getParams(5)$window\n", + "p_np_nn$getParams(6)$window" + ] + }, { "cell_type": "markdown", "metadata": {},