Skip to content
Snippets Groups Projects
Commit 2a65e98e authored by hgb's avatar hgb
Browse files

update small fixes all over

parent 228d2856
No related tags found
No related merge requests found
Showing
with 1007 additions and 85 deletions
......@@ -19,4 +19,6 @@ vignettes/*_files*
tmp/
onlineforecast.Rcheck
\ No newline at end of file
onlineforecast.Rcheck
images/
\ No newline at end of file
qmodel <- R6::R6Class("qmodel", public = list(
####### Store Data and information for algorithm #####
info = list(),
####### Store Coefficients Data #######
beta = list(),
####### Fixed Parameters ######
## Weighted
W = NA,
n_in_bin = NA,
## Number of predictiors
K = NA,
## Quantiles
tau = NA,
## Cold start size
N1 = NA,
debug = NA,
####### Quantile Information ########
## Index of the columns of the X matrix of Xny
IX = NA,
## Index of the column of y
Iy = NA,
## The design matrix
X = list(),
####### debug Information ########
listIH = list(),
####### Forecast Information ########
inputs = list(),
kseq = NA,
output = NA,
prm = NA,
regprmexpr = NA,
regprm = NA,
## Offline parameters
prmbounds = as.matrix(data.frame(lower=NA, init =NA, upper=NA)),
datatr = NA,
qrFIT = NA,
maxlagAR = NA,
yAR = NA,
Ypred = NA,
initialize = function(N1 = NULL, debug = FALSE){
if(is.null(N1)) stop("The number of data points for the cold start needs to be defined")
self$N1 <- N1
self$debug <- debug
},
####### Store Data and information for algorithm #####
info = list(),
####### Store Coefficients Data #######
beta = list(),
####### Fixed Parameters ######
## Weighted
W = NA,
n_in_bin = NA,
## Number of predictiors
K = NA,
## Quantiles
tau = NA,
## Cold start size
N1 = NA,
debug = NA,
####### Quantile Information ########
## Index of the columns of the X matrix of Xny
IX = NA,
## Index of the column of y
Iy = NA,
## The design matrix
X = list(),
####### debug Information ########
listIH = list(),
####### Forecast Information ########
inputs = list(),
kseq = NA,
output = NA,
prm = NA,
regprmexpr = NA,
regprm = NA,
## Offline parameters
prmbounds = as.matrix(data.frame(lower=NA, init =NA, upper=NA)),
datatr = NA,
qrFIT = NA,
maxlagAR = NA,
yAR = NA,
Ypred = NA,
## Initialise the model with the size of the cold start.
## We need some starting point for the iteration of the quantile fit, using simplex method.
initialize = function(N1 = NULL, debug = FALSE){
if(is.null(N1)) stop("The number of data points for the cold start needs to be defined")
self$N1 <- N1
self$debug <- debug
},
### Should be the same to forecastmodel.R.. maybe have an inheritance from that instead of rewrite.
#----------------------------------------------------------------
# Get the transformation parameters
......@@ -241,6 +247,4 @@ qmodel <- R6::R6Class("qmodel", public = list(
return(expr)
}
#----------------------------------------------------------------
))
......@@ -20,9 +20,11 @@ quantile_fit <- function(prm, model, q, data, printout = TRUE, returnanalysis =
# First insert the prm into the model input expressions
model$insert_prm(prm)
model$n_in_bin <- round(2*(1/(1-model$regprm$lambda)))
## Annoying!
## Compute the effective memory of lambda, the window size
model$n_in_bin <- round(2*(1/(1-model$regprm$lambda)))
## If the effective memory is less then the cold start window, then set it to the cold start window.
## HGB 11/02/2025: Unsure if this is correct
if(model$n_in_bin < model$N1){
model$n_in_bin = model$N1 + 1
}
......@@ -32,6 +34,7 @@ quantile_fit <- function(prm, model, q, data, printout = TRUE, returnanalysis =
# Since rls_fit is run from scratch, the init the stored inputs data (only needed when running iteratively)
#model$datatr <- NA
#model$yAR <- NA
# Reset the model state (e.g. inputs state, stored iterative data, ...)
model$reset_state()
......@@ -49,20 +52,21 @@ quantile_fit <- function(prm, model, q, data, printout = TRUE, returnanalysis =
Ypred <- NULL
for(k in model$kseq){
cat("horizon :", k, "\n")
cat("n_in_bin :", model$n_in_bin, "\n")
# cat("horizon :", k, "\n")
# cat("n_in_bin :", model$n_in_bin, "\n")
## Setup the design matrix for k step
X <- as.data.frame(subset(model$datatr, kseq=k))
## Lag them to match to the
## Lag them to match to the output, so the input forecast matches the output.
X <- onlineforecast:::lagdf.matrix(X, k)
X$y <- data[[model$output]]
X <- X[-1:-k,]
if (k > 0) {
X <- X[-(1:k), ]
}
fit <- rq(paste("y ~ -1 + ", paste(names(X[, -which(names(X) %in% c("y"))]), collapse = " + "), sep = ""), tau = q, data = X[1:(model$N1-k),])
beta <- as.matrix(fit$coefficients)
## Fill it from start (index 1) to the end of the cold start
beta <- fit$coefficients
model$beta[[paste0("q", q)]][[paste0("k", k)]] <- matrix(beta, nrow = model$N1, ncol = model$K, byrow = T)
r <- as.matrix(fit$residuals, ncol = length(q))
for(i in 1:dim(r)[2]){
......@@ -86,7 +90,7 @@ quantile_fit <- function(prm, model, q, data, printout = TRUE, returnanalysis =
## Compute the loss function, maybe the residuals are compute in different place
loss <- sapply(model$kseq, function(i) pinball_loss(r = model$info[[paste0("q", q)]][[paste0("k", i)]]$R[data$scoreperiod[(i+1):length(data$scoreperiod)]], q))
model$Ypred <- Ypred
if(!returnanalysis){
#Yhat <- quantile_prediction(model = model, multistep = model$kseq)
cat("Quantile, tau:", q, "\n")
......
......@@ -25,7 +25,7 @@ quantile_optim <- function(model, data){
# Parameters to pass to quantile_fit
model = model,
q = model$tau[i],
data = Dnew,
data = data,
returnanalysis = FALSE,
# Parameters to pass to optim
lower = lower,
......
......@@ -13,17 +13,11 @@ quantile_predict <- function(model, datatr){
## Setup the design matrix for k step
X <- as.data.frame(subset(datatr, kseq=k))
## Lag them to match to the
#X <- onlineforecast:::lagdf.matrix(X, k)
X <- onlineforecast:::lagdf.matrix(X, k)
yhat <- as.numeric(rep(NA, nrow(X)))
for(i in ((k):nrow(X))){
if(i <= (model$N1)) {
j <- 1
} else{
j <- i - model$N1
}
#browser()
yhat[i] <- t(as.numeric(X[i,])) %*% model$beta[[paste0("q",q)]][[paste0("k",k)]][j,]
for(i in ((1):nrow(X))){
yhat[i] <- t(as.numeric(X[i,])) %*% model$beta[[paste0("q",q)]][[paste0("k",k)]][i,]
}
return(yhat)
......
......@@ -25,7 +25,7 @@ update_rq <- function(Xny, tau, k, model = NULL, debug = TRUE){
Ypred <- matrix(as.numeric(NA), nrow = N, ncol = 1)
if(debug) {
print("yeah")
# print("yeah")
list_idx <- matrix(as.numeric(NA), nrow = 1, ncol = length(res$Ih)+1)
list_idx[1,] <- c(0,res$Ih)
}
......@@ -71,6 +71,19 @@ update_rq <- function(Xny, tau, k, model = NULL, debug = TRUE){
list_idx <- rbind(list_idx, c(counter, res$Ih))
}
# if(FALSE){
# invXh <- solve(Xold[res$Ih, 1:model$K])
# cB <- as.numeric(res$P < 0) + res$P * tau
# cC <- c(rep(tau, model$K), rep(1 - tau, model$K))
# #IB2 <- -(t(res$P %*% t(rep(1, model$K))) %*% Xold[res$Ihc+1, 1:model$K]) %*% invXh
# g <- t(IB2) %*% cB
# d <- cC - c(g, -g)
# d[abs(d) < 1e-15] <- 0
# s <- order(d)
# md <- sort(d)
# }
resAlg <- rq_simplex_cpp(X = Xold[,1:model$K],
Ih = res$Ih,
......
#----------------------------------------------------------------
# Init by deleting all variables and functions
rm(list=ls())
# Set the working directory
setwd("/home/hgb/git/onlineforecast/misc-R/quantile/")
#----------------------------------------------------------------
#----------------------------------------------------------------
# Exercise on RLS
# Init
rm(list = ls())
sapply(dir("functions",full.names=TRUE), source)
# A function for fitting a recursive least squares estimation
source("rls.R")
rls
#----------------------------------------------------------------
#----------------------------------------------------------------
# Generate some data from a linear model
n <- 200
x <- runif(n)
beta0 <- 2
beta1 <- -3
y <- beta0 + beta1 * x + rnorm(n, sd=0.1)
# Estimate the coefficients
fit <- lm(y ~ x)
plot(x, y)
abline(fit)
fit
# Generate again with other coefficient values
x1 <- runif(n)
beta0 <- -2
beta1 <- 3
y1 <- beta0 + beta1 * x1 + rnorm(n, sd=0.1)
# Estimate again
fit1 <- lm(y1 ~ x1)
plot(x1, y1)
abline(fit1)
fit
# Combine them as two "periods",
# such that at the start of the the second part, at i=201, the
# coefficients change and have different values
X <- data.frame(y=c(y,y1), x=c(x,x1))
# See clearly there is two "regimes"
plot(X$x, X$y)
# As a time series you only see the change in mean
plot(X$y)
# Fit a linear regression on the combined data
lm(y ~ x, X)
#----------------------------------------------------------------
#----------------------------------------------------------------
# Fit a recursive least squares (linear regression) on the combined data
val <- rls(y ~ x, lambda = 0.97, data = X, k = 1)
# Plot the tracked coefficients
colnames(val$Theta) <- c("beta0","beta1")
plot.ts(val$Theta)
plot.ts(val$y)
lines(val$y - val$residuals, col ="red")
#----------------------------------------------------------------
setwd("/home/hgb/git/onlineforecast/")
library(devtools)
library(splines)
library(quantreg)
load_all(".") # need to be under the package directory
## create an fcst matrix of the input data
createFCSTmatrix <- function(vec, kHor) {
# Create a matrix of the temperature measurements
# vec: vector of temperature measurements
# kHor: horizon of the forecast
# Return: matrix of the temperature measurements
N <- length(vec)
M <- length(kHor)
mat <- matrix(NA, nrow = N, ncol = M)
for (i in 1:(N - M)) {
mat[i, ] <- vec[i:(i + M - 1)]
}
colnames(mat) <- paste0("k", kHor)
return(mat)
}
inputX <- createFCSTmatrix(X$x, kHor = 0:24)
D <- list()
D$t <- seq_along(X$x)
D$x <- inputX
D$y <- X$y
## subset the data, as the algorithm does not handle NA! I had forgotten that.
## it is due to the calculation for the simplex, which is not defined for NA
#class(D) <- "data.list"
idx <- in_range(1,D$t,350)
Dtrain <- list()
Dtrain$t <- D$t[idx]
Dtrain$x <- inputX[idx,]
Dtrain$y <- X$y[idx]
## needs to have scoreperiod, for computing the loss
Dtrain$scoreperiod <- in_range(1,D$t,300)
class(Dtrain) <- "data.list"
str(Dtrain)
## Create the model, where N1 is the initial number of data points - for the cold start
model <- qmodel$new(N1 = 30)
## The output is the y
model$output = "y"
## The design matrix, intercept and the x
model$add_inputs(Xinput = "x",
mu = "one()")
## Add the regularization parameter, lambda, and the bounds
model$add_regprm("rls_prm(lambda=0.9)")
# model$add_prmbounds(lambda = c(0.99, 0.999, 0.9999))
### Setup of the booking keeping matrix -
##############################################################
####### THIS SHOULD BE DONE IN quantile_fit.R ################
##############################################################
## First 2 are the intercept and the x
model$IX <- 0:1
## The number of predictors, we could just use the length of the input matrix or the IX
model$K <- 2
## The output column is the 2nd one
model$Iy <- 2
## Select which quantiles we want to optimise and fit
model$tau <- c(0.05,0.2, 0.5, 0.8,0.95)
## Select which prediction horizon
model$kseq <- 0:24
#opt_model <- quantile_optim(model = model, data = Dtrain)
PAR <- c("lambda" = 0.999)
quantile_fit(prm = PAR, model = model, data = Dtrain, q = model$tau[1])
PAR <- c("lambda" = 0.999)
quantile_fit(prm = PAR, model = model, data = Dtrain, q = model$tau[2])
PAR <- c("lambda" = 0.97)
quantile_fit(prm = PAR, model = model, data = Dtrain, q = model$tau[3])
PAR <- c("lambda" = 0.999)
quantile_fit(prm = PAR, model = model, data = Dtrain, q = model$tau[4])
PAR <- c("lambda" = 0.999)
quantile_fit(prm = PAR, model = model, data = Dtrain, q = model$tau[5])
## compute the predictions from the input data and the estimated coefficeints.
Pred_model <- quantile_predict(model = model, datatr = model$datatr)
par(mfrow = c(2,1))
plot(1:length(Dtrain$y), rep(NA, length(Dtrain$y)), type = "l", ylim = range(Dtrain$y))
polygon(c(1:length(Pred_model$q0.05[,"k1"]), rev(1:length(Pred_model$q0.95[,"k1"]))), c(Pred_model$q0.05[,"k1"], rev(Pred_model$q0.95[,"k1"])), col = "grey80", border = NA)
lines(Dtrain$y, col = "black")
lines(Pred_model$q0.5[,"k1"], type = "l", col = "red")
lines(val$y - val$residuals, col ="blue")
legend("bottomleft", legend = c("y", "RLS pred", "Quantile Pred"), col = c("black", "blue", "red"), lty = 1, ncol = 3, bty = "n", cex = 1.4)
plot(val$Theta[,"beta0"], type = "l", col = "blue", ylim = range(val$Theta, na.rm = TRUE))
lines(model$beta$q0.5$k1[,2], lty = 1, col = "red")
lines(val$Theta[,"beta1"], type = "l", lty = 2, col = "blue")
lines(model$beta$q0.5$k1[,1], type = "l", lty = 2, col = "red")
legend(x = 50, y = 0, legend = c("RLS Intercept", "RLS Slope", "Quantile Intercept", "Quantile Slope"), col = c("blue", "blue", "red", "red"), lty = c(1,2,1,2), ncol = 2, bty = "n", cex = 1.4)
/* http://meyerweb.com/eric/tools/css/reset/ */
/* v1.0 | 20080212 */
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, font, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td {
margin: 0;
padding: 0;
border: 0;
outline: 0;
font-size: 100%;
vertical-align: baseline;
background: transparent;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
/* remember to define focus styles! */
:focus {
outline: 0;
}
/* remember to highlight inserts somehow! */
ins {
text-decoration: none;
}
del {
text-decoration: line-through;
}
/* tables still need 'cellspacing="0"' in the markup */
table {
border-collapse: collapse;
border-spacing: 0;
}
/**
* SciAnimator - Scientific Image Animator Plugin for jQuery
*
* Copyright (c) 2010 Brent Ertz
* Released under the MIT license.
* http://github.com/brentertz/scianimator
*/
/* Blue theme */
.scianimator.blue,
.scianimator.blue a,
.scianimator.blue a:visited {
color: #3985a8;
}
.scianimator.blue {
background: #ddeef6;
}
.scianimator.blue .controls,
.scianimator.blue .control {
background-color: #ddeef6;
border: 1px solid #89bad2;
color: #3985a8;
text-shadow: 0 1px #fff;
}
.scianimator.blue .controls {
box-shadow: inset 0 1px 3px #fff, inset 0 -17px #cbe6f2, 0 0 3px #89bad2;
-o-box-shadow: inset 0 1px 3px #fff, inset 0 -17px #cbe6f2, 0 0 3px #89bad2;
-webkit-box-shadow: inset 0 1px 3px #fff, inset 0 -17px #cbe6f2, 0 0 3px #89bad2;
-moz-box-shadow: inset 0 1px 3px #fff, inset 0 -17px #cbe6f2, 0 0 3px #89bad2;
}
.scianimator.blue .control {
box-shadow: inset 0 1px 3px #fff, inset 0 -10px #cbe6f2, 0 0 3px #89bad2;
-o-box-shadow: inset 0 1px 3px #fff, inset 0 -10px #cbe6f2, 0 0 3px #89bad2;
-webkit-box-shadow: inset 0 1px 3px #fff, inset 0 -10px #cbe6f2, 0 0 3px #89bad2;
-moz-box-shadow: inset 0 1px 3px #fff, inset 0 -10px #cbe6f2, 0 0 3px #89bad2;
}
.scianimator.blue a:hover {
box-shadow: inset 0 1px 3px #fff, inset 0 -10px #cbe6f2, 0 0 3px #3985a8;
-o-box-shadow: inset 0 1px 3px #fff, inset 0 -10px #cbe6f2, 0 0 3px #3985a8;
-webkit-box-shadow: inset 0 1px 3px #fff, inset 0 -10px #cbe6f2, 0 0 3px #3985a8;
-moz-box-shadow: inset 0 1px 3px #fff, inset 0 -10px #cbe6f2, 0 0 3px #3985a8;
color: #fff;
text-shadow: 0px 1px #3985a8;
}
\ No newline at end of file
/**
* SciAnimator - Scientific Image Animator Plugin for jQuery
*
* Copyright (c) 2010 Brent Ertz
* Released under the MIT license.
* http://github.com/brentertz/scianimator
*/
/* Comment out @imports for themes not in use */
@import url('scianimator.light.css');
@import url('scianimator.dark.css');
@import url('scianimator.blue.css');
.scianimator {
font-family: 'Lucida Grande', sans-serif;
font-size: 12px;
text-align: center;
margin: auto auto 1em auto;
position: relative;
}
.scianimator .controls,
.scianimator .control {
border: 1px solid;
border-radius: 4px;
-moz-border-radius: 4px;
font-family: 'Lucida Grande', sans-serif;
font-size: 10px;
text-shadow: 0 1px #fff;
margin: 2px;
position: relative;
}
.scianimator .controls {
margin: 0;
padding: 4px;
position: relative;
}
.scianimator a,
.scianimator a:visited {
cursor: pointer;
display: inline-block;
padding: 5px 10px;
text-decoration: none;
}
.scianimator a.small,
.scianimator a:visited.small {
padding: 1px 2px;
}
.scianimator a:active {
top: 1px;
}
.scianimator select.control,
.scianimator label {
margin: 1px;
vertical-align: middle;
}
.scianimator .control.box {
padding: 1px 5px;
display: inline-block;
vertical-align: top;
}
.scianimator .control.box .control {
margin-left: 0;
margin-right: 0;
}
.scianimator .box.control.navigator {
padding: 2px;
}
.scianimator .box a.control.navigator,
.scianimator .box a:hover.control.navigator {
display: inline-block;
height: 10px;
margin: 2px;
padding: 0;
width: 10px;
background: #00FF00;
box-shadow: 0 0 3px 1px #666666 inset, 0 0 1px #00FF00;
-o-box-shadow: 0 0 3px 1px #666666 inset, 0 0 1px #00FF00;
-webkit-box-shadow: 0 0 3px 1px #666666 inset, 0 0 1px #00FF00;
-moz-box-shadow: 0 0 3px 1px #666666 inset, 0 0 1px #00FF00;
}
.scianimator .box a.navigator.disabled,
.scianimator .box a:hover.navigator.disabled {
background: red;
box-shadow: 0 0 3px 1px #666666 inset, 0 0 1px red;
-o-box-shadow: 0 0 3px 1px #666666 inset, 0 0 1px red;
-webkit-box-shadow: 0 0 3px 1px #666666 inset, 0 0 1px red;
-moz-box-shadow: 0 0 3px 1px #666666 inset, 0 0 1px red;
}
.scianimator .box a.navigator.current,
.scianimator .box a:hover.navigator.current {
background: blue;
box-shadow: 0 0 3px 1px #666666 inset, 0 0 1px blue;
-o-box-shadow: 0 0 3px 1px #666666 inset, 0 0 1px blue;
-webkit-box-shadow: 0 0 3px 1px #666666 inset, 0 0 1px blue;
-moz-box-shadow: 0 0 3px 1px #666666 inset, 0 0 1px blue;
}
.scianimator .status {
background: red;
color: #fff;
right: 0;
padding: 5px;
position: absolute;
top: 0;
}
\ No newline at end of file
/**
* SciAnimator - Scientific Image Animator Plugin for jQuery
*
* Copyright (c) 2010 Brent Ertz
* Released under the MIT license.
* http://github.com/brentertz/scianimator
*/
/* Dark theme */
.scianimator.dark,
.scianimator.dark a,
.scianimator.dark a:visited {
color: #ccc;
}
.scianimator.dark {
background: #333;
}
.scianimator.dark .controls,
.scianimator.dark .control {
background-color: #333;
border-color: #666;
color: #ccc;
text-shadow: 0 1px #000;
}
.scianimator.dark .controls {
box-shadow: inset 0 1px 3px #fff, inset 0 -17px #000, 0 0 3px #000;
-o-box-shadow: inset 0 1px 3px #fff, inset 0 -17px #000, 0 0 3px #000;
-webkit-box-shadow: inset 0 1px 3px #fff, inset 0 -17px #000, 0 0 3px #000;
-moz-box-shadow: inset 0 1px 3px #fff, inset 0 -17px #000, 0 0 3px #000;
}
.scianimator.dark .control {
box-shadow: inset 0 1px 3px #fff, inset 0 -10px #000, 0 0 3px #000;
-o-box-shadow: inset 0 1px 3px #fff, inset 0 -10px #000, 0 0 3px #000;
-webkit-box-shadow: inset 0 1px 3px #fff, inset 0 -10px #000, 0 0 3px #000;
-moz-box-shadow: inset 0 1px 3px #fff, inset 0 -10px #000, 0 0 3px #000;
}
.scianimator.dark a:hover {
box-shadow: inset 0 1px 3px #fff, inset 0 -10px #000, 0 0 3px #555;
-o-box-shadow: inset 0 1px 3px #fff, inset 0 -10px #000, 0 0 3px #555;
-webkit-box-shadow: inset 0 1px 3px #fff, inset 0 -10px #000, 0 0 3px #555;
-moz-box-shadow: inset 0 1px 3px #fff, inset 0 -10px #333, 0 0 3px #555;
color: #fff;
text-shadow: 0px 1px #000;
}
\ No newline at end of file
/**
* SciAnimator - Scientific Image Animator Plugin for jQuery
*
* Copyright (c) 2010 Brent Ertz
* Released under the MIT license.
* http://github.com/brentertz/scianimator
*/
/* Light theme */
.scianimator.light,
.scianimator.light a,
.scianimator.light a:visited {
color: #555;
}
.scianimator.light {
background: #ddd;
}
.scianimator.light .controls,
.scianimator.light .control {
background-color: #ddd;
border-color: #999;
color: #555;
text-shadow: 0 1px #fff;
}
.scianimator.light .controls {
box-shadow: inset 0 1px 3px #fff, inset 0 -17px #ccc, 0 0 3px #999;
-o-box-shadow: inset 0 1px 3px #fff, inset 0 -17px #ccc, 0 0 3px #999;
-webkit-box-shadow: inset 0 1px 3px #fff, inset 0 -17px #ccc, 0 0 3px #999;
-moz-box-shadow: inset 0 1px 3px #fff, inset 0 -17px #ccc, 0 0 3px #999;
}
.scianimator.light .control {
box-shadow: inset 0 1px 3px #fff, inset 0 -10px #ccc, 0 0 3px #999;
-o-box-shadow: inset 0 1px 3px #fff, inset 0 -10px #ccc, 0 0 3px #999;
-webkit-box-shadow: inset 0 1px 3px #fff, inset 0 -10px #ccc, 0 0 3px #999;
-moz-box-shadow: inset 0 1px 3px #fff, inset 0 -10px #ccc, 0 0 3px #999;
}
.scianimator.light a:hover {
box-shadow: inset 0 1px 3px #fff, inset 0 -10px #ccc, 0 0 3px #555;
-o-box-shadow: inset 0 1px 3px #fff, inset 0 -10px #ccc, 0 0 3px #555;
-webkit-box-shadow: inset 0 1px 3px #fff, inset 0 -10px #ccc, 0 0 3px #555;
-moz-box-shadow: inset 0 1px 3px #fff, inset 0 -10px #ccc, 0 0 3px #555;
color: #fff;
text-shadow: 0px 1px #555;
}
\ No newline at end of file
body {
margin: 20px;
}
\ No newline at end of file
(function($) {
$(document).ready(function() {
$('#Rplot').scianimator({
'images': ['images/Rplot1.png', 'images/Rplot2.png', 'images/Rplot3.png', 'images/Rplot4.png', 'images/Rplot5.png', 'images/Rplot6.png', 'images/Rplot7.png', 'images/Rplot8.png', 'images/Rplot9.png', 'images/Rplot10.png', 'images/Rplot11.png', 'images/Rplot12.png', 'images/Rplot13.png', 'images/Rplot14.png', 'images/Rplot15.png', 'images/Rplot16.png', 'images/Rplot17.png', 'images/Rplot18.png', 'images/Rplot19.png', 'images/Rplot20.png', 'images/Rplot21.png', 'images/Rplot22.png', 'images/Rplot23.png', 'images/Rplot24.png', 'images/Rplot25.png', 'images/Rplot26.png', 'images/Rplot27.png', 'images/Rplot28.png', 'images/Rplot29.png', 'images/Rplot30.png', 'images/Rplot31.png', 'images/Rplot32.png', 'images/Rplot33.png', 'images/Rplot34.png', 'images/Rplot35.png', 'images/Rplot36.png', 'images/Rplot37.png', 'images/Rplot38.png', 'images/Rplot39.png', 'images/Rplot40.png', 'images/Rplot41.png', 'images/Rplot42.png', 'images/Rplot43.png', 'images/Rplot44.png', 'images/Rplot45.png', 'images/Rplot46.png', 'images/Rplot47.png', 'images/Rplot48.png', 'images/Rplot49.png', 'images/Rplot50.png', 'images/Rplot51.png', 'images/Rplot52.png', 'images/Rplot53.png', 'images/Rplot54.png', 'images/Rplot55.png', 'images/Rplot56.png', 'images/Rplot57.png', 'images/Rplot58.png', 'images/Rplot59.png', 'images/Rplot60.png', 'images/Rplot61.png', 'images/Rplot62.png', 'images/Rplot63.png', 'images/Rplot64.png', 'images/Rplot65.png', 'images/Rplot66.png', 'images/Rplot67.png', 'images/Rplot68.png', 'images/Rplot69.png', 'images/Rplot70.png', 'images/Rplot71.png', 'images/Rplot72.png', 'images/Rplot73.png', 'images/Rplot74.png', 'images/Rplot75.png', 'images/Rplot76.png', 'images/Rplot77.png', 'images/Rplot78.png', 'images/Rplot79.png', 'images/Rplot80.png', 'images/Rplot81.png', 'images/Rplot82.png', 'images/Rplot83.png', 'images/Rplot84.png', 'images/Rplot85.png', 'images/Rplot86.png', 'images/Rplot87.png', 'images/Rplot88.png', 'images/Rplot89.png', 'images/Rplot90.png', 'images/Rplot91.png', 'images/Rplot92.png', 'images/Rplot93.png', 'images/Rplot94.png', 'images/Rplot95.png', 'images/Rplot96.png', 'images/Rplot97.png', 'images/Rplot98.png', 'images/Rplot99.png', 'images/Rplot100.png', 'images/Rplot101.png', 'images/Rplot102.png', 'images/Rplot103.png', 'images/Rplot104.png', 'images/Rplot105.png', 'images/Rplot106.png', 'images/Rplot107.png', 'images/Rplot108.png', 'images/Rplot109.png', 'images/Rplot110.png', 'images/Rplot111.png', 'images/Rplot112.png', 'images/Rplot113.png', 'images/Rplot114.png', 'images/Rplot115.png', 'images/Rplot116.png', 'images/Rplot117.png', 'images/Rplot118.png', 'images/Rplot119.png', 'images/Rplot120.png', 'images/Rplot121.png', 'images/Rplot122.png', 'images/Rplot123.png', 'images/Rplot124.png', 'images/Rplot125.png', 'images/Rplot126.png', 'images/Rplot127.png', 'images/Rplot128.png', 'images/Rplot129.png', 'images/Rplot130.png', 'images/Rplot131.png', 'images/Rplot132.png', 'images/Rplot133.png', 'images/Rplot134.png', 'images/Rplot135.png', 'images/Rplot136.png', 'images/Rplot137.png', 'images/Rplot138.png', 'images/Rplot139.png', 'images/Rplot140.png', 'images/Rplot141.png', 'images/Rplot142.png', 'images/Rplot143.png', 'images/Rplot144.png', 'images/Rplot145.png', 'images/Rplot146.png', 'images/Rplot147.png', 'images/Rplot148.png', 'images/Rplot149.png', 'images/Rplot150.png', 'images/Rplot151.png', 'images/Rplot152.png', 'images/Rplot153.png', 'images/Rplot154.png', 'images/Rplot155.png', 'images/Rplot156.png', 'images/Rplot157.png', 'images/Rplot158.png', 'images/Rplot159.png', 'images/Rplot160.png', 'images/Rplot161.png', 'images/Rplot162.png', 'images/Rplot163.png', 'images/Rplot164.png', 'images/Rplot165.png', 'images/Rplot166.png', 'images/Rplot167.png', 'images/Rplot168.png', 'images/Rplot169.png', 'images/Rplot170.png', 'images/Rplot171.png', 'images/Rplot172.png', 'images/Rplot173.png', 'images/Rplot174.png', 'images/Rplot175.png', 'images/Rplot176.png', 'images/Rplot177.png', 'images/Rplot178.png', 'images/Rplot179.png', 'images/Rplot180.png', 'images/Rplot181.png', 'images/Rplot182.png', 'images/Rplot183.png', 'images/Rplot184.png', 'images/Rplot185.png', 'images/Rplot186.png', 'images/Rplot187.png', 'images/Rplot188.png', 'images/Rplot189.png', 'images/Rplot190.png', 'images/Rplot191.png', 'images/Rplot192.png', 'images/Rplot193.png', 'images/Rplot194.png', 'images/Rplot195.png', 'images/Rplot196.png', 'images/Rplot197.png', 'images/Rplot198.png', 'images/Rplot199.png', 'images/Rplot200.png', 'images/Rplot201.png', 'images/Rplot202.png', 'images/Rplot203.png', 'images/Rplot204.png', 'images/Rplot205.png', 'images/Rplot206.png', 'images/Rplot207.png', 'images/Rplot208.png', 'images/Rplot209.png', 'images/Rplot210.png', 'images/Rplot211.png', 'images/Rplot212.png', 'images/Rplot213.png', 'images/Rplot214.png', 'images/Rplot215.png', 'images/Rplot216.png', 'images/Rplot217.png', 'images/Rplot218.png', 'images/Rplot219.png', 'images/Rplot220.png', 'images/Rplot221.png', 'images/Rplot222.png', 'images/Rplot223.png', 'images/Rplot224.png', 'images/Rplot225.png', 'images/Rplot226.png', 'images/Rplot227.png', 'images/Rplot228.png', 'images/Rplot229.png', 'images/Rplot230.png', 'images/Rplot231.png', 'images/Rplot232.png', 'images/Rplot233.png', 'images/Rplot234.png', 'images/Rplot235.png', 'images/Rplot236.png', 'images/Rplot237.png', 'images/Rplot238.png', 'images/Rplot239.png', 'images/Rplot240.png', 'images/Rplot241.png', 'images/Rplot242.png', 'images/Rplot243.png', 'images/Rplot244.png', 'images/Rplot245.png', 'images/Rplot246.png', 'images/Rplot247.png', 'images/Rplot248.png', 'images/Rplot249.png', 'images/Rplot250.png', 'images/Rplot251.png', 'images/Rplot252.png', 'images/Rplot253.png', 'images/Rplot254.png', 'images/Rplot255.png', 'images/Rplot256.png', 'images/Rplot257.png', 'images/Rplot258.png', 'images/Rplot259.png', 'images/Rplot260.png', 'images/Rplot261.png', 'images/Rplot262.png', 'images/Rplot263.png', 'images/Rplot264.png', 'images/Rplot265.png', 'images/Rplot266.png', 'images/Rplot267.png', 'images/Rplot268.png', 'images/Rplot269.png', 'images/Rplot270.png', 'images/Rplot271.png', 'images/Rplot272.png', 'images/Rplot273.png', 'images/Rplot274.png', 'images/Rplot275.png', 'images/Rplot276.png', 'images/Rplot277.png', 'images/Rplot278.png', 'images/Rplot279.png', 'images/Rplot280.png', 'images/Rplot281.png', 'images/Rplot282.png', 'images/Rplot283.png', 'images/Rplot284.png', 'images/Rplot285.png', 'images/Rplot286.png', 'images/Rplot287.png', 'images/Rplot288.png', 'images/Rplot289.png', 'images/Rplot290.png', 'images/Rplot291.png', 'images/Rplot292.png', 'images/Rplot293.png', 'images/Rplot294.png', 'images/Rplot295.png', 'images/Rplot296.png', 'images/Rplot297.png', 'images/Rplot298.png', 'images/Rplot299.png', 'images/Rplot300.png', 'images/Rplot301.png', 'images/Rplot302.png', 'images/Rplot303.png', 'images/Rplot304.png', 'images/Rplot305.png', 'images/Rplot306.png', 'images/Rplot307.png', 'images/Rplot308.png', 'images/Rplot309.png', 'images/Rplot310.png', 'images/Rplot311.png', 'images/Rplot312.png', 'images/Rplot313.png', 'images/Rplot314.png', 'images/Rplot315.png', 'images/Rplot316.png', 'images/Rplot317.png', 'images/Rplot318.png', 'images/Rplot319.png', 'images/Rplot320.png', 'images/Rplot321.png', 'images/Rplot322.png', 'images/Rplot323.png', 'images/Rplot324.png', 'images/Rplot325.png', 'images/Rplot326.png', 'images/Rplot327.png', 'images/Rplot328.png', 'images/Rplot329.png', 'images/Rplot330.png', 'images/Rplot331.png', 'images/Rplot332.png', 'images/Rplot333.png', 'images/Rplot334.png', 'images/Rplot335.png', 'images/Rplot336.png', 'images/Rplot337.png', 'images/Rplot338.png', 'images/Rplot339.png', 'images/Rplot340.png', 'images/Rplot341.png', 'images/Rplot342.png', 'images/Rplot343.png', 'images/Rplot344.png', 'images/Rplot345.png', 'images/Rplot346.png', 'images/Rplot347.png', 'images/Rplot348.png', 'images/Rplot349.png', 'images/Rplot350.png', 'images/Rplot351.png', 'images/Rplot352.png', 'images/Rplot353.png', 'images/Rplot354.png', 'images/Rplot355.png', 'images/Rplot356.png', 'images/Rplot357.png', 'images/Rplot358.png', 'images/Rplot359.png', 'images/Rplot360.png', 'images/Rplot361.png', 'images/Rplot362.png', 'images/Rplot363.png', 'images/Rplot364.png', 'images/Rplot365.png', 'images/Rplot366.png', 'images/Rplot367.png', 'images/Rplot368.png', 'images/Rplot369.png', 'images/Rplot370.png', 'images/Rplot371.png', 'images/Rplot372.png', 'images/Rplot373.png', 'images/Rplot374.png', 'images/Rplot375.png', 'images/Rplot376.png', 'images/Rplot377.png', 'images/Rplot378.png', 'images/Rplot379.png', 'images/Rplot380.png', 'images/Rplot381.png', 'images/Rplot382.png', 'images/Rplot383.png', 'images/Rplot384.png', 'images/Rplot385.png', 'images/Rplot386.png', 'images/Rplot387.png', 'images/Rplot388.png', 'images/Rplot389.png', 'images/Rplot390.png', 'images/Rplot391.png', 'images/Rplot392.png', 'images/Rplot393.png', 'images/Rplot394.png', 'images/Rplot395.png', 'images/Rplot396.png', 'images/Rplot397.png', 'images/Rplot398.png', 'images/Rplot399.png', 'images/Rplot400.png', 'images/Rplot401.png', 'images/Rplot402.png', 'images/Rplot403.png', 'images/Rplot404.png', 'images/Rplot405.png', 'images/Rplot406.png', 'images/Rplot407.png', 'images/Rplot408.png', 'images/Rplot409.png', 'images/Rplot410.png', 'images/Rplot411.png', 'images/Rplot412.png', 'images/Rplot413.png', 'images/Rplot414.png', 'images/Rplot415.png', 'images/Rplot416.png', 'images/Rplot417.png', 'images/Rplot418.png', 'images/Rplot419.png', 'images/Rplot420.png', 'images/Rplot421.png', 'images/Rplot422.png', 'images/Rplot423.png', 'images/Rplot424.png', 'images/Rplot425.png', 'images/Rplot426.png', 'images/Rplot427.png', 'images/Rplot428.png', 'images/Rplot429.png', 'images/Rplot430.png', 'images/Rplot431.png', 'images/Rplot432.png', 'images/Rplot433.png', 'images/Rplot434.png', 'images/Rplot435.png', 'images/Rplot436.png', 'images/Rplot437.png', 'images/Rplot438.png', 'images/Rplot439.png', 'images/Rplot440.png', 'images/Rplot441.png', 'images/Rplot442.png', 'images/Rplot443.png', 'images/Rplot444.png', 'images/Rplot445.png', 'images/Rplot446.png', 'images/Rplot447.png', 'images/Rplot448.png', 'images/Rplot449.png', 'images/Rplot450.png', 'images/Rplot451.png', 'images/Rplot452.png', 'images/Rplot453.png', 'images/Rplot454.png', 'images/Rplot455.png', 'images/Rplot456.png', 'images/Rplot457.png', 'images/Rplot458.png', 'images/Rplot459.png', 'images/Rplot460.png', 'images/Rplot461.png', 'images/Rplot462.png', 'images/Rplot463.png', 'images/Rplot464.png', 'images/Rplot465.png', 'images/Rplot466.png', 'images/Rplot467.png', 'images/Rplot468.png', 'images/Rplot469.png', 'images/Rplot470.png', 'images/Rplot471.png', 'images/Rplot472.png', 'images/Rplot473.png', 'images/Rplot474.png', 'images/Rplot475.png', 'images/Rplot476.png', 'images/Rplot477.png', 'images/Rplot478.png', 'images/Rplot479.png', 'images/Rplot480.png', 'images/Rplot481.png', 'images/Rplot482.png', 'images/Rplot483.png', 'images/Rplot484.png', 'images/Rplot485.png', 'images/Rplot486.png', 'images/Rplot487.png', 'images/Rplot488.png', 'images/Rplot489.png', 'images/Rplot490.png', 'images/Rplot491.png', 'images/Rplot492.png', 'images/Rplot493.png', 'images/Rplot494.png', 'images/Rplot495.png', 'images/Rplot496.png', 'images/Rplot497.png', 'images/Rplot498.png', 'images/Rplot499.png', 'images/Rplot500.png', 'images/Rplot501.png', 'images/Rplot502.png', 'images/Rplot503.png', 'images/Rplot504.png', 'images/Rplot505.png', 'images/Rplot506.png', 'images/Rplot507.png', 'images/Rplot508.png', 'images/Rplot509.png', 'images/Rplot510.png', 'images/Rplot511.png', 'images/Rplot512.png', 'images/Rplot513.png', 'images/Rplot514.png', 'images/Rplot515.png', 'images/Rplot516.png', 'images/Rplot517.png', 'images/Rplot518.png', 'images/Rplot519.png', 'images/Rplot520.png', 'images/Rplot521.png', 'images/Rplot522.png', 'images/Rplot523.png', 'images/Rplot524.png', 'images/Rplot525.png', 'images/Rplot526.png', 'images/Rplot527.png', 'images/Rplot528.png', 'images/Rplot529.png', 'images/Rplot530.png', 'images/Rplot531.png', 'images/Rplot532.png', 'images/Rplot533.png', 'images/Rplot534.png', 'images/Rplot535.png', 'images/Rplot536.png', 'images/Rplot537.png', 'images/Rplot538.png', 'images/Rplot539.png', 'images/Rplot540.png', 'images/Rplot541.png', 'images/Rplot542.png', 'images/Rplot543.png', 'images/Rplot544.png', 'images/Rplot545.png', 'images/Rplot546.png', 'images/Rplot547.png', 'images/Rplot548.png', 'images/Rplot549.png', 'images/Rplot550.png', 'images/Rplot551.png', 'images/Rplot552.png', 'images/Rplot553.png', 'images/Rplot554.png', 'images/Rplot555.png', 'images/Rplot556.png', 'images/Rplot557.png', 'images/Rplot558.png', 'images/Rplot559.png', 'images/Rplot560.png', 'images/Rplot561.png', 'images/Rplot562.png', 'images/Rplot563.png', 'images/Rplot564.png', 'images/Rplot565.png', 'images/Rplot566.png', 'images/Rplot567.png', 'images/Rplot568.png', 'images/Rplot569.png', 'images/Rplot570.png', 'images/Rplot571.png', 'images/Rplot572.png', 'images/Rplot573.png', 'images/Rplot574.png', 'images/Rplot575.png', 'images/Rplot576.png', 'images/Rplot577.png', 'images/Rplot578.png', 'images/Rplot579.png', 'images/Rplot580.png', 'images/Rplot581.png', 'images/Rplot582.png', 'images/Rplot583.png', 'images/Rplot584.png', 'images/Rplot585.png', 'images/Rplot586.png', 'images/Rplot587.png', 'images/Rplot588.png', 'images/Rplot589.png', 'images/Rplot590.png', 'images/Rplot591.png', 'images/Rplot592.png', 'images/Rplot593.png', 'images/Rplot594.png', 'images/Rplot595.png', 'images/Rplot596.png', 'images/Rplot597.png', 'images/Rplot598.png', 'images/Rplot599.png', 'images/Rplot600.png', 'images/Rplot601.png', 'images/Rplot602.png', 'images/Rplot603.png', 'images/Rplot604.png', 'images/Rplot605.png', 'images/Rplot606.png', 'images/Rplot607.png', 'images/Rplot608.png', 'images/Rplot609.png', 'images/Rplot610.png', 'images/Rplot611.png', 'images/Rplot612.png', 'images/Rplot613.png', 'images/Rplot614.png', 'images/Rplot615.png', 'images/Rplot616.png', 'images/Rplot617.png', 'images/Rplot618.png', 'images/Rplot619.png', 'images/Rplot620.png', 'images/Rplot621.png', 'images/Rplot622.png', 'images/Rplot623.png', 'images/Rplot624.png', 'images/Rplot625.png', 'images/Rplot626.png', 'images/Rplot627.png', 'images/Rplot628.png', 'images/Rplot629.png', 'images/Rplot630.png', 'images/Rplot631.png', 'images/Rplot632.png', 'images/Rplot633.png', 'images/Rplot634.png', 'images/Rplot635.png', 'images/Rplot636.png', 'images/Rplot637.png', 'images/Rplot638.png', 'images/Rplot639.png', 'images/Rplot640.png', 'images/Rplot641.png', 'images/Rplot642.png', 'images/Rplot643.png', 'images/Rplot644.png', 'images/Rplot645.png', 'images/Rplot646.png', 'images/Rplot647.png', 'images/Rplot648.png', 'images/Rplot649.png', 'images/Rplot650.png', 'images/Rplot651.png', 'images/Rplot652.png', 'images/Rplot653.png', 'images/Rplot654.png', 'images/Rplot655.png', 'images/Rplot656.png', 'images/Rplot657.png', 'images/Rplot658.png', 'images/Rplot659.png', 'images/Rplot660.png', 'images/Rplot661.png', 'images/Rplot662.png', 'images/Rplot663.png', 'images/Rplot664.png', 'images/Rplot665.png', 'images/Rplot666.png', 'images/Rplot667.png', 'images/Rplot668.png', 'images/Rplot669.png', 'images/Rplot670.png', 'images/Rplot671.png', 'images/Rplot672.png', 'images/Rplot673.png', 'images/Rplot674.png'],
'width': 1600,
'delay': 1000,
'loopMode': 'loop',
'controls': ['first', 'previous', 'play', 'next', 'last', 'loop', 'speed']
});
$('#Rplot').scianimator('play');
});
})(jQuery);
This diff is collapsed.
/**
* SciAnimator - Scientific Image Animator Plugin for jQuery
*
* Copyright (c) 2010 Brent Ertz
* Released under the MIT license.
* http://github.com/brentertz/scianimator
*/
(function(e){var c={CONTROLS_ALL:"all",CONTROLS_NONE:"none",DIRECTION_FORWARD:0,DIRECTION_REVERSE:1,LOOP_MODE_NONE:"none",LOOP_MODE_LOOP:"loop",LOOP_MODE_SWEEP:"sweep",PLAY_MODE_STOPPED:0,PLAY_MODE_PLAYING:1,POSITION_TOP:0,POSITION_BOTTOM:1};e.fn.scianimator=function(g){if(b[g]){return b[g].apply(this,Array.prototype.slice.call(arguments,1))}else{if(typeof g==="object"||!g){return b.init.apply(this,arguments)}else{e.error("Method "+g+" does not exist on jQuery.scianimator")}}};e.fn.scianimator.defaults={autoRefresh:false,keyboard:true,debug:false,images:[],controlContainer:null,controlPosition:c.POSITION_BOTTOM,controls:c.CONTROLS_ALL,defaultFrame:0,delay:250,delayStep:50,delayMin:25,delayMax:5000,dwellMultiplier:2,theme:"light",width:null,utf8:true,loopMode:c.LOOP_MODE_LOOP,labels:{text:{first:"First",previous:"Previous",play:"Play",stop:"Stop",next:"Next",last:"Last",loop:{tip:"Click to toggle loop mode",loop:"Loop",sweep:"Sweep",none:"None"},speed:{speed:"Speed",down:"-",up:"+"},navigator:{tip:"Click to go to frame; &lt;ctrl&gt;+click to enable/disable frame."},status:{preload:"Preloading images...",refresh:"Refreshing images from source..."}},utf8:{first:"|&#8592;",previous:"&#8592;",play:"&#9658;",stop:"&#9632;",next:"&#8594;",last:"&#8594;|"}}};var d={};var b={init:function(g){d=e.extend(true,{},e.fn.scianimator.defaults,g);a("init");return this.each(function(){var i=e(this);var h=i.data("scianimator");e(this).data("scianimator",{id:i[0].id,target:i,image:null,animationTimer:null,autoRefreshTimer:null,playMode:c.PLAY_MODE_STOPPED,frames:[],currentFrame:d.defaultFrame,firstFrame:0,lastFrame:null,disabledFrames:[],direction:c.DIRECTION_FORWARD,dwell:0,settings:d,controls:{}});i.scianimator("loadImages","preload").scianimator("container").scianimator("image").scianimator("controls").scianimator("calculateDwell")})},destroy:function(){a("destroy");return this.each(function(){var h=e(this);var g=h.data("scianimator");e(window).unbind(".scianimator");h.removeData("scianimator");window.clearTimeout(g.animationTimer);h.remove()})},drawImage:function(j){a("drawImage");var i=e(this);var g=i.data("scianimator");j=parseInt(j,10);var h=g.frames[j];e(g.image).load(function(){a("Loaded image for frame #"+j+" : "+h.src)}).error(function(){a("Image failed to load for frame #"+j+" : "+h.src);i.scianimator("enableDisable",{frame:j,state:"disable"})}).attr("src",h.src);return i},container:function(){a("container");var h=e(this);var g=h.data("scianimator");h.addClass("scianimator");if(g.settings.theme!==undefined){h.addClass(g.settings.theme)}if(g.settings.width!==undefined){h.css("width",g.settings.width)}return h},image:function(){a("image");var i=e(this);var h=i.data("scianimator");var g=e("<img />");i.append(g[0]);h.image=g[0];if("number"===typeof h.settings.defaultFrame){i.scianimator("goto",h.settings.defaultFrame)}else{if("last"===h.settings.defaultFrame){i.scianimator("last")}else{i.scianimator("first")}}return i},controls:function(){a("controls");var k=e(this);var j=k.data("scianimator");var h=e('<div id="'+j.id+'-controls" class="scianimator controls"></div>');if(j.settings.theme!==undefined){h.addClass(j.settings.theme)}var i=e("<form></form>");var g={first:function(){var l=(j.settings.utf8)?j.settings.labels.utf8.first:j.settings.labels.text.first;return e('<a id="'+j.id+'-first" class="control first" href="#">'+l+"</a>")},previous:function(){var l=(j.settings.utf8)?j.settings.labels.utf8.previous:j.settings.labels.text.previous;return e('<a id="'+j.id+'-previous" class="control previous" href="#">'+l+"</a>")},play:function(){var l=(j.settings.utf8)?j.settings.labels.utf8.play:j.settings.labels.text.play;return e('<a id="'+j.id+'-play" class="control play" href="#">'+l+"</a>")},next:function(){var l=(j.settings.utf8)?j.settings.labels.utf8.next:j.settings.labels.text.next;return e('<a id="'+j.id+'-next" class="control next" href="#">'+l+"</a>")},last:function(){var l=(j.settings.utf8)?j.settings.labels.utf8.last:j.settings.labels.text.last;return e('<a id="'+j.id+'-last" class="control last" href="#">'+l+"</a>")},navigator:function(){var l=e('<span id="'+j.id+'-navigator" class="control navigator box"></span>');var m=j.settings.labels.text.navigator.tip;e.each(j.frames,function(n,o){l.append('<a id="'+j.id+"-navigator-"+n+'" title="'+m+'" href="#" class="control navigator">&nbsp;</a>')});return l},loop:function(){var l=(j.settings.utf8&&j.settings.labels.utf8.loop!==undefined)?j.settings.labels.utf8.loop[j.settings.loopMode]:j.settings.labels.text.loop[j.settings.loopMode];var m=j.settings.labels.text.loop.tip;return e('<a id="'+j.id+'-loop" class="control loop '+j.settings.loopMode+'" title="'+m+'" href="#">'+l+"</a>")},speed:function(){var m=(j.settings.utf8&&j.settings.labels.utf8.speed!==undefined)?j.settings.labels.utf8.speed.speed:j.settings.labels.text.speed.speed;var l=(j.settings.utf8&&j.settings.labels.utf8.speed!==undefined)?j.settings.labels.utf8.speed.up:j.settings.labels.text.speed.up;var n=(j.settings.utf8&&j.settings.labels.utf8.speed!==undefined)?j.settings.labels.utf8.speed.down:j.settings.labels.text.speed.down;return e('<span id="'+j.id+'-speed" class="control speed box"><a id="'+j.id+'-speed-down" class="control speed-down small" href="#">'+n+"</a> <label>"+m+'</label> <a id="'+j.id+'-speed-up" class="control speed-up small" href="#">'+l+"</a></span>")}};h.delegate("form","submit",function(l){l.preventDefault()}).delegate("a","click",function(l){l.preventDefault();switch(l.target.id){case j.id+"-first":k.scianimator("first");break;case j.id+"-previous":k.scianimator("previous");break;case j.id+"-play":k.scianimator("playOrStop");break;case j.id+"-next":k.scianimator("next");break;case j.id+"-last":k.scianimator("last");break;case j.id+"-loop":k.scianimator("loopMode");break;case j.id+"-speed-down":k.scianimator("speedDown");break;case j.id+"-speed-up":k.scianimator("speedUp");break}}).delegate("a.navigator","click",function(l){l.preventDefault();var n=j.id+"-navigator-";if((l.target.id).indexOf(n)!=-1){var m=parseInt((l.target.id).substring(n.length),10);if(l.metaKey){k.scianimator("enableDisable",{frame:m})}else{k.scianimator("goto",m)}}});if(e.isArray(j.settings.controls)&&j.settings.controls.length>0){e.each(j.settings.controls,function(l,m){i.append(g[m]);j.controls[m]=g[m]()[0].id})}else{if(c.CONTROLS_ALL===j.settings.controls){e.each(g,function(l,m){i.append(m);j.controls[l]=m()[0].id})}else{a("Display no controls")}}if(!e(i).is(":empty")){h.append(i);if(j.settings.controlContainer!==null){if(c.POSITION_TOP===j.settings.controlPosition){e(j.settings.controlContainer).prepend(container)}else{e(j.settings.controlContainer).append(container)}}else{if(c.POSITION_TOP===j.settings.controlPosition){k.prepend(h)}else{k.append(h)}}}if(j.settings.keyboard===true){k.scianimator("keyboard")}k.scianimator("onControlsComplete");return k},keyboard:function(){a("keyboard");var h=e(this);var g=h.data("scianimator");e(document).bind("keydown.scianimator.controls",function(i){if(i.target.tagName!="INPUT"&&i.target.tagName!="TEXTAREA"){switch(i.keyCode){case 13:case 32:h.scianimator("playOrStop");break;case 37:if(i.shiftKey){h.scianimator("first")}else{h.scianimator("previous")}break;case 39:if(i.shiftKey){h.scianimator("last")}else{h.scianimator("next")}break}}})},onControlsComplete:function(){a("onControlsComplete");var h=e(this);var g=h.data("scianimator");h.scianimator("hilightCurrent")},playOrStop:function(){a("playOrStop");var h=e(this);var g=h.data("scianimator");if(c.PLAY_MODE_PLAYING===g.playMode){h.scianimator("stop")}else{if(c.PLAY_MODE_STOPPED===g.playMode){h.scianimator("play")}}return h},play:function(){a("play");var j=e(this);var i=j.data("scianimator");i.playMode=c.PLAY_MODE_PLAYING;var h=i.settings.delay;if(c.DIRECTION_FORWARD===i.direction){if(i.currentFrame===i.firstFrame||i.currentFrame===i.lastFrame){h=i.dwell}}a("delay: "+h);i.animationTimer=self.setTimeout(function(){j.scianimator("animate")},h);var g=(i.settings.utf8)?i.settings.labels.utf8.stop:i.settings.labels.text.stop;e("#"+i.controls.play).removeClass("play").addClass("stop").html(g);return j},stop:function(){a("stop");var i=e(this);var h=i.data("scianimator");h.animationTimer=window.clearTimeout(h.animationTimer);h.playMode=c.PLAY_MODE_STOPPED;var g=(h.settings.utf8)?h.settings.labels.utf8.play:h.settings.labels.text.play;e("#"+h.controls.play).removeClass("stop").addClass("play").html(g);return i},animate:function(){a("animate");var h=e(this);var g=h.data("scianimator");if(c.DIRECTION_FORWARD===g.direction){h.scianimator("next")}else{if(c.DIRECTION_REVERSE===g.direction){h.scianimator("previous")}}if(c.PLAY_MODE_PLAYING===g.playMode){h.scianimator("play")}return h},previous:function(){a("previous");var h=e(this);var g=h.data("scianimator");g.currentFrame--;if(e.inArray(g.currentFrame,g.disabledFrames)!=-1){h.scianimator("previous");return h}a(g.firstFrame+":"+g.currentFrame+":"+g.lastFrame);if(g.currentFrame<g.firstFrame){if(c.PLAY_MODE_PLAYING===g.playMode){if(c.LOOP_MODE_LOOP===g.settings.loopMode){h.scianimator("last")}else{if(c.LOOP_MODE_SWEEP===g.settings.loopMode){g.direction=c.DIRECTION_FORWARD;h.scianimator("next")}else{if(c.LOOP_MODE_NONE===g.settings.loopMode){h.scianimator("stop")}}}}else{if(c.PLAY_MODE_STOPPED===g.playMode){h.scianimator("last")}}}else{h.scianimator("goto",g.currentFrame)}return h},next:function(){a("next");var h=e(this);var g=h.data("scianimator");g.currentFrame++;a(g.firstFrame+":"+g.currentFrame+":"+g.lastFrame);if(e.inArray(g.currentFrame,g.disabledFrames)!=-1){h.scianimator("next");return h}if(g.currentFrame>g.lastFrame){if(c.PLAY_MODE_PLAYING===g.playMode){if(c.LOOP_MODE_LOOP===g.settings.loopMode){h.scianimator("first")}else{if(c.LOOP_MODE_SWEEP===g.settings.loopMode){g.direction=c.DIRECTION_REVERSE;h.scianimator("previous")}else{if(c.LOOP_MODE_NONE===g.settings.loopMode){h.scianimator("stop")}}}}else{if(c.PLAY_MODE_STOPPED===g.playMode){h.scianimator("first")}}}else{h.scianimator("goto",g.currentFrame)}return h},first:function(){a("first");var h=e(this);var g=h.data("scianimator");h.scianimator("goto",g.firstFrame);return h},last:function(){a("last");var h=e(this);var g=h.data("scianimator");h.scianimator("goto",g.lastFrame);return h},"goto":function(i){a("goto");var h=e(this);var g=h.data("scianimator");var i=parseInt(i,10);if(i>g.lastFrame){i=g.lastFrame}else{if(i<g.firstFrame){i=g.firstFrame}}a(i);g.currentFrame=i;h.scianimator("drawImage",g.currentFrame);h.scianimator("hilightCurrent");return h},loopMode:function(){a("loop mode");var j=e(this);var i=j.data("scianimator");var g=i.settings.loopMode;if(c.LOOP_MODE_NONE===i.settings.loopMode){i.settings.loopMode=c.LOOP_MODE_LOOP}else{if(c.LOOP_MODE_LOOP===i.settings.loopMode){i.settings.loopMode=c.LOOP_MODE_SWEEP}else{if(c.LOOP_MODE_SWEEP===i.settings.loopMode){i.direction=c.DIRECTION_FORWARD;i.settings.loopMode=c.LOOP_MODE_NONE}}}var h=(i.settings.utf8&&i.settings.labels.utf8.loop!==undefined)?i.settings.labels.utf8.loop[i.settings.loopMode]:i.settings.labels.text.loop[i.settings.loopMode];e("#"+i.controls.loop).removeClass(g).addClass(i.settings.loopMode).html(h);a(i.settings.loopMode);return j},speedUp:function(){a("speed up");var h=e(this);var g=h.data("scianimator");g.settings.delay-=g.settings.delayStep;g.settings.delay=(g.settings.delay<g.settings.delayMin)?g.settings.delayMin:g.settings.delay;h.scianimator("calculateDwell");if(c.PLAY_MODE_PLAYING==g.playMode){h.scianimator("stop").scianimator("play")}a("Delay: "+g.settings.delay);return h},speedDown:function(){a("speed down");var h=e(this);var g=h.data("scianimator");g.settings.delay=(g.settings.delay<=g.settings.delayMin)?0:g.settings.delay;g.settings.delay+=g.settings.delayStep;g.settings.delay=(g.settings.delay>g.settings.delayMax)?g.settings.delayMax:g.settings.delay;h.scianimator("calculateDwell");if(c.PLAY_MODE_PLAYING==g.playMode){h.scianimator("stop").scianimator("play")}a("delay: "+g.settings.delay);return h},calculateDwell:function(){a("calculateDwell");var i=e(this);var h=i.data("scianimator");var g=h.settings.delay*h.settings.dwellMultiplier;if(g<h.settings.delayMin){g=h.settings.delayMin}if(g>h.settings.delayMax){g=h.settings.delayMax}h.dwell=g;a("dwell: "+h.dwell);return i},enableDisable:function(m){a("enableDisable");var j=m.state||"toggle";var k=e(this);var i=k.data("scianimator");var l=parseInt(m.frame,10);var g=e("#"+i.controls.navigator+"-"+l);var h=e.inArray(l,i.disabledFrames);switch(j){case"enable":if(h!=-1){a("enable: "+l);i.disabledFrames.splice(h,1);e(g).removeClass("disabled")}break;case"disable":if(h==-1){a("disable: "+l);i.disabledFrames.push(l);e(g).addClass("disabled")}break;case"toggle":default:if(h!=-1){a("enable: "+l);i.disabledFrames.splice(h,1);e(g).removeClass("disabled")}else{a("disable: "+l);i.disabledFrames.push(l);e(g).addClass("disabled")}}a("disabledFrames:"+i.disabledFrames);return k},hilightCurrent:function(){a("hilightCurrent");var i=e(this);var h=i.data("scianimator");var g=h.controls.navigator;var j=g+"-"+h.currentFrame;e("a","#"+g).removeClass("current");e("#"+j,"#"+g).addClass("current")},loadImages:function(g){a("loadImages");var j=e(this);var i=j.data("scianimator");if("preload"===g){j.scianimator("showStatus",{status:i.settings.labels.text.status.preload})}else{if("refresh"===g){j.scianimator("showStatus",{status:i.settings.labels.text.status.refresh})}}i.frames=[];var h=0;e.each(i.settings.images,function(m,l){var k=e("<img />").load(function(){if(++h===i.settings.images.length){j.scianimator("onLoadImagesComplete")}}).error(function(){a("Image failed to load for frame #"+m+" : "+l);j.scianimator("enableDisable",{frame:m,state:"disable"});if(++h===i.settings.images.length){j.scianimator("onLoadImagesComplete")}});if("refresh"===g){k.attr("src",f(l))}else{k.attr("src",l)}i.frames.push(k[0])});i.lastFrame=i.frames.length-1;return j},onLoadImagesComplete:function(){a("onLoadImagesComplete");var h=e(this);var g=h.data("scianimator");if(g.settings.autoRefresh!==false){g.autoRefreshTimer=self.setTimeout(function(){h.scianimator("refresh")},parseInt(g.settings.autoRefresh,10))}h.scianimator("hideStatus")},refresh:function(){a("refresh");var h=e(this);var g=h.data("scianimator");h.scianimator("loadImages","refresh")},showStatus:function(j){a("showStatus");var i=e(this);var h=i.data("scianimator");i.scianimator("hideStatus");var g=e('<div class="status">'+j.status+"</div>");g.hide().appendTo(i).fadeIn("slow");if(j.timeout!==undefined){self.setTimeout(function(){i.scianimator("hideStatus")},parseInt(j.timeout,10))}return i},hideStatus:function(){a("hideStatus");var h=e(this);var g=h.data("scianimator");e(".status",h).fadeOut("slow",function(){e(this).remove()});return h},listImages:function(){a("list images");var h=e(this);var g=h.data("scianimator");return g.settings.images}};function a(g){if(d.debug&&window.console&&window.console.log){window.console.log(g)}}function f(i){var h=i;var j=i.indexOf("?");var g="";if(j!=-1){h=i.substring(0,j);g=i.substring(j);g=g.replace(/[(?|&)]rand=[^&]+/g,"")}i=h+((g.length)?g+"&":g+"?");i+="rand="+Math.random();return i}})(jQuery);
\ No newline at end of file
<html>
<head>
<meta charset="utf-8" />
<meta name="generator" content="R package animation 2.7">
<title>Animations Using the R Language</title>
<link rel="stylesheet" href="css/reset.css" />
<link rel="stylesheet" href="css/styles.css" />
<link rel="stylesheet" href="css/scianimator.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/styles/github.min.css">
<script src="js/jquery-1.4.4.min.js"></script>
<script src="js/jquery.scianimator.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/highlight.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/languages/r.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
</head>
<body>
<div class="scianimator"><div id="Rplot" style="display: inline-block;"></div></div>
<div class="scianimator" style="width: 1600px; text-align: left"><pre><code class="r">## Animations generated in R version 4.4.1 (2024-06-14) using the package animation
library(animation)
library(RColorBrewer)
library(onlineforecast)
library(quantreg)
library(SparseM)
library(testthat)
library(devtools)
library(usethis)
for (i in k:(60)) {
par(mfrow = c(2, 1))
par(mar = c(2, 4, 2, 2))
with(Pred_model, {
plot(Dtrain$t[(i - 10):(i + k)], Dtrain$Ps[(i - 10):(i +
k)], bty = "l", lwd = 2, col = "black", pch = 19,
cex = 0.5, axes = FALSE, xaxt = "n", type = "n",
ylim = range(Dtrain$Ps[(i - 10):(i + k)], q0.5[i,
], q0.95[i, ], q0.05[i, ], na.rm = T), main = "TimeAdaptive with Weights",
xlab = "Time", ylab = "Ps")
axis(2)
polygon(c(Dtrain$t[(i + 1):(i + k)], rev(Dtrain$t[(i +
1):(i + k)])), c(Pred_model$q0.05[i, ], rev(Pred_model$q0.2[i,
])), col = colSeq[3], border = NA)
polygon(c(Dtrain$t[(i + 1):(i + k)], rev(Dtrain$t[(i +
1):(i + k)])), c(Pred_model$q0.8[i, ], rev(Pred_model$q0.95[i,
])), col = colSeq[3], border = NA)
polygon(c(Dtrain$t[(i + 1):(i + k)], rev(Dtrain$t[(i +
1):(i + k)])), c(Pred_model$q0.2[i, ], rev(Pred_model$q0.5[i,
])), col = colSeq[4], border = NA)
polygon(c(Dtrain$t[(i + 1):(i + k)], rev(Dtrain$t[(i +
1):(i + k)])), c(Pred_model$q0.5[i, ], rev(Pred_model$q0.8[i,
])), col = colSeq[4], border = NA)
lines(Dtrain$t[(i - 10):(i + k)], Dtrain$Ps[(i -
10):(i + k)], col = "black", type = "b", lwd = 2)
lines(Dtrain$t[(i + 1):(i + k)], q0.5[i, ], type = "b",
col = "grey", lwd = 2)
axis.POSIXct(side = 1, x = Dtrain$t[(i - 10):(i +
k)], at = seq(from = Dtrain$t[(i - 10):(i + k)][1],
to = Dtrain$t[(i - 10):(i + k)][length(Dtrain$t[(i -
10):(i + k)])], by = "1 hour"), format = "%Y/%m/%d %H:%M \n %a",
las = 1, cex.axis = 1, srt = 45)
plot(Dtrain$t[(i - 10):(i + k)], c(rep(NA, 11), as.numeric(Dtrain$I[i,
1:k])), type = "b", col = "steelblue", axes = FALSE,
xlab = "Time", ylab = "Temp", lwd = 2, ylim = range(Dtrain$I[i,
1:k], Dtrain$Iobs[(i + 1):(i + k)]))
lines(Dtrain$t[(i + 1):(i + k)], Dtrain$Iobs[(i +
1):(i + k)], type = "b", col = "red", lwd = 2)
axis(2)
abline(h = 0, v = Dtrain$t[i], lty = 2, col = "lightgrey",
lwd = 2)
legend("topleft", legend = c("Ta Obs", "Ta Pred"),
col = c("red", "steelblue"), lty = 1, cex = 1,
lwd = 2)
i
axis.POSIXct(side = 1, x = Dtrain$t[(i - 10):(i +
k)], at = seq(from = Dtrain$t[(i - 10):(i + k)][1],
to = Dtrain$t[(i - 10):(i + k)][length(Dtrain$t[(i -
10):(i + k)])], by = "1 hour"), format = "%Y/%m/%d %H:%M \n %a",
las = 1, cex.axis = 1, srt = 45)
})
}
## R version 4.4.1 (2024-06-14)
## Platform: x86_64-pc-linux-gnu
## Other packages: animation 2.7, RColorBrewer 1.1-3, onlineforecast
## 1.0.2, quantreg 5.99, SparseM 1.84-2, testthat 3.2.1.1, devtools 2.4.5,
## usethis 3.0.0</code></pre></div>
<script src="js/Rplot.js"></script>
<!-- highlight R code -->
</body>
</html>
......@@ -47,29 +47,32 @@ D$scoreperiod <- in_range("2009-06-10", D$t)
Dtrain <- subset(D, in_range(tstart,D$t,tend))
## Create the model, where N1 is the initial number of data points - for the cold start
model <- qmodel$new(N1 = 50)
## The output is the Ps from the Dsolar data
model$output = "Ps"
## The design matrix, here we are using 5 bsplines fixed at 5 and 18 hour of the day - ie when sun is up and down.
model$add_inputs(I = "bspline(tday, df=5, Boundary.knots=c(5,18)) %**% I")
## Add the regularization parameter, lambda, and the bounds
model$add_regprm("rls_prm(lambda=0.9)")
model$add_prmbounds(lambda = c(0.99, 0.999, 0.9999))
### Setup of the booking keeping matrix -
##############################################################
####### THIS SHOULD BE DONE IN quantile_fit.R ################
##############################################################
## First 5 columns are the input Matrix
model$IX <- 0:4
## The number of predictors, we could just use the length of the input matrix or the IX
model$K <- 5
## The output column is the 6th one
model$Iy <- 5
model$K <- 5
## Just quick fun to see the transformation
## maybe have splines that sum to one always..
model$datatr <- model$transform_data(Dtrain)
model$tau <- c(0.05,0.2, 0.5, 0.8,0.95)
model$kseq <- 1:24
#opt_model <- quantile_optim(model = model, data = Dnew)
plot(Dtrain$I$k1[1:100], type = "l")
lines(model$datatr$I.bs1$k1, col = "red")
lines(model$datatr$I.bs2$k1, col = "red")
......@@ -78,6 +81,15 @@ lines(model$datatr$I.bs4$k1, col = "red")
lines(model$datatr$I.bs5$k1, col = "red")
## Select which quantiles we want to optimise and fit
model$tau <- c(0.05,0.2, 0.5, 0.8,0.95)
## Select which prediction horizon
model$kseq <- c(1,4,8,12,24)
model$kseq <- 1:24
#opt_model <- quantile_optim(model = model, data = Dtrain)
PAR <- c("lambda" = 0.999)
quantile_fit(prm = PAR, model = model, data = Dtrain, q = model$tau[1])
PAR <- c("lambda" = 0.999)
......@@ -93,7 +105,11 @@ quantile_fit(prm = PAR, model = model, data = Dtrain, q = model$tau[5])
Pred_model <- quantile_predict(model = model, datatr = model$datatr)
plot(Dtrain$Ps, type = "l")
lines(Pred_model$q0.05[,"k24"], type = "l", col = "green")
lines(Pred_model$q0.5[,"k24"], type = "l", col = "blue")
#lines(Pred_model$q0.5[,"k1"], type = "l", col = "green")
lines(Pred_model$q0.95[,"k24"], type = "l", col = "red")
......@@ -164,3 +180,82 @@ i
}
library(animation)
k <- 24
colSeq <- grey(seq(0.9,0.1,len=3))
#colSeq <- colorJet(nPolygons)
require( RColorBrewer )
colSeq <- brewer.pal(11 , "Spectral" )
saveHTML({
for(i in k:(60)){
par(mfrow = c(2,1))
par(mar = c(2,4,2,2)) # bottom left top right
with(Pred_model, {
plot(Dtrain$t[(i-10):(i+k)], Dtrain$Ps[(i-10):(i+k)], bty = "l", lwd = 2, col = "black", pch=19, cex=0.5, axes = FALSE, xaxt = "n",
type="n", ylim = range(Dtrain$Ps[(i-10):(i+k)], q0.5[i,], q0.95[i,], q0.05[i,], na.rm = T), main = "TimeAdaptive with Weights", xlab = "Time", ylab = "Ps")
axis(2)
polygon(c(Dtrain$t[(i+1):(i+k)], rev(Dtrain$t[(i+1):(i+k)])),
c(Pred_model$q0.05[i,],rev(Pred_model$q0.2[i,])), col= colSeq[3], border = NA)
polygon(c(Dtrain$t[(i+1):(i+k)], rev(Dtrain$t[(i+1):(i+k)])),
c(Pred_model$q0.8[i,],rev(Pred_model$q0.95[i,])), col= colSeq[3], border = NA)
polygon(c(Dtrain$t[(i+1):(i+k)], rev(Dtrain$t[(i+1):(i+k)])),
c(Pred_model$q0.2[i,],rev(Pred_model$q0.5[i,])), col= colSeq[4], border = NA)
polygon(c(Dtrain$t[(i+1):(i+k)], rev(Dtrain$t[(i+1):(i+k)])),
c(Pred_model$q0.5[i,],rev(Pred_model$q0.8[i,])), col= colSeq[4], border = NA)
lines(Dtrain$t[(i-10):(i+k)], Dtrain$Ps[(i-10):(i+k)], col = "black", type = "b", lwd = 2)
lines(Dtrain$t[(i+1):(i+k)], q0.5[i,], type = "b", col = "grey", lwd = 2)
axis.POSIXct(side = 1, x = Dtrain$t[(i-10):(i+k)],
at = seq(from = Dtrain$t[(i-10):(i+k)][1],
to = Dtrain$t[(i-10):(i+k)][length(Dtrain$t[(i-10):(i+k)])],
by = "1 hour"), format = "%Y/%m/%d %H:%M \n %a",
las = 1, cex.axis = 1, srt = 45)
#lines(Pred_model$q0.05[i,], type = "b", col = "blue")
#lines(Pred_model$q0.95[i,], type = "b", col = "blue")
plot(Dtrain$t[(i-10):(i+k)], c(rep(NA,11), as.numeric(Dtrain$I[i, 1:k])), type = "b", col = "steelblue", axes = FALSE, xlab = "Time", ylab = "Temp", lwd = 2, ylim = range(Dtrain$I[i, 1:k], Dtrain$Iobs[(i+1):(i+k)]))
#lines(Dtrain$t[i], Dtrain$Iobs[i+1,1], type = "b", col = "red", axes = FALSE)
lines(Dtrain$t[(i+1):(i+k)], Dtrain$Iobs[(i+1):(i+k)], type = "b", col = "red", lwd = 2)
axis(2)
abline(h=0,v=Dtrain$t[i],lty=2, col = "lightgrey", lwd = 2)
legend("topleft", legend=c("Ta Obs", "Ta Pred"),
col=c("red", "steelblue"), lty=1, cex=1, lwd = 2)
i
axis.POSIXct(side = 1, x = Dtrain$t[(i-10):(i+k)],
at = seq(from = Dtrain$t[(i-10):(i+k)][1],
to = Dtrain$t[(i-10):(i+k)][length(Dtrain$t[(i-10):(i+k)])],
by = "1 hour"), format = "%Y/%m/%d %H:%M \n %a",
las = 1, cex.axis = 1, srt = 45)
})
}}, htmlfile = "misc-R/quantile/model.html", ani.height = 800, ani.width = 1600)
rls <- function(frml, lambda, data, k) {
# R build-in function for setting up linear regression model
mf <- model.frame(as.formula(frml), data, na.action = na.pass)
# The model output
y <- mf[ ,1]
# The design matrix
X <- model.matrix(as.formula(frml), mf)
# The number of observations
n <- nrow(X)
# The number of parameters
p <- ncol(X)
# Parameter matrix
Theta <- matrix(as.numeric(NA), nrow = n, ncol = p)
# The predictions
yhat <- as.numeric(rep(NA,n))
# The parameter vector
theta <- matrix(rep(0,p), ncol = 1)
# Start value for the parameter covariance P
P <- 10000 * diag(1, p)
# Use the inverse in the RLS
R <- solve(P)
# Iterate through and estimate the parameters
for (i in 1:(n-k)) {
x <- matrix(X[i, ])
# Check for NAs in inputs and output
if(all(!is.na(x)) & !is.na(y[i])){
# Update
R <- lambda * R + x %*% t(x)
theta <- theta + solve(R, x) %*% (y[i] - t(x) %*% theta)
Theta[i, ] <- t(theta)
}
# Predict
x <- matrix(X[i+k, ])
if(all(!is.na(x))){
yhat[i+k] <- t(x) %*% theta
}
}
# Return a list
L <- list()
L$residuals <- y - yhat
L$X <- X
L$y <- y
L$Theta <- Theta
return(L)
}
......@@ -18,7 +18,7 @@ Rcpp::List rq_init_cpp(arma::mat X,
if(Lr0 > beta.n_elem){
Rcout << "Worked" << "\n";
// Rcout << "Worked" << "\n";
arma::uvec Irs = sort_index(abs(R));
Irs = Irs.subvec(0,Lr0-1);
arma::mat Xh = X.rows(Irs);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment