1 #' @include b_Algorithm.R
3 #' @title Linear Algorithm
5 #' @description Generic class to represent a linear algorithm.
6 #' TODO: not needed in production environment; weights growing infinitely.
7 #' Inherits \code{\link{Algorithm}}
9 #' @field weights The matrix of weights (in rows) associated to each expert (in columns)
11 LinearAlgorithm = setRefClass(
12 Class = "LinearAlgorithm",
18 contains = "Algorithm",
21 initialize = function(...)
24 weights <<- matrix(nrow=0, ncol=ncol(data)-3)
27 appendWeight = function(weight)
29 "Append the last computed weights to the weights matrix, for further plotting"
32 nx = n - nrow(subset(data, subset = (Date == data[n,"Date"])))
33 x = data[(nx+1):n, !names(data) %in% c("Date","Measure","Station")]
34 iy = getNoNAindices(x, 2)
36 completedWeight = rep(NA, ncol(x))
37 completedWeight[iy] = weight
38 weights <<- rbind(weights, completedWeight)
41 plotWeights = function(station=1, start=1, ...)
43 "Plot the weights of each expert over time"
45 if (is.character(station))
46 station = match(station, stations)
48 #keep only full weights (1 to K)
49 weights_ = weights[getNoNAindices(weights),]
50 weights_ = weights_[start:nrow(weights_),]
52 yRange = range(weights_, na.rm=TRUE)
55 par(mar=c(5,4.5,1,1), cex=1.5)
58 plot(weights_[,i], type="l", xaxt="n", ylim=yRange, col=cols[i], xlab="", ylab="",cex.axis=1.5, ...)
61 axis(side=1, at=seq(from=1,to=nrow(weights_),by=30), labels=seq(from=0,to=nrow(weights_),by=30) + start, cex.axis=1.5)
62 title(xlab="Time",ylab="Weight", cex.lab=1.6)