I have the following R code:
library("forecast")
library("rbenchmark")
v <- c(95.3, 96.8, 97.2, 97.9, 98.2, 98.5, 99.3, 99.9, 102.7, 104.2, 107.2, 109.3, 109.8, 110.5, 111.2, 111.6, 112.6, 113.5, 114.3, 115, 117.4, 119, 119.3, 120.1, 120.7, 121.1, 121.9, 122.2, 122.9, 124.6, 129.1, 128.8, 129.3, 130.3, 131.1, 131.8, 132.9, 133.5, 134.5, 135.6, 139.4, 138.9, 140.9, 141.8, 142.8, 142.4, 142.8, 143.9, 144.8, 145.5, 149.6, 151, 152.1, 152.7, 154.5, 153.9, 153.8, 153.8, 154.5, 155.5, 158.9, 159, 158.7, 159.7, 159.7, 159.7, 160.1, 159.9, 161.3, 161.9, 164.4, 164.4, 164.7, 165.1, 165.2, 164.9, 166.9, 167.8, 169.4, 170.1, 171.6, 172.9, 173.7, 175.2, 175.8, 176.3, 177.1, 177.5, 178.8, 180.2, 183, 184, 184.7, 186.5, 187.3, 187.9, 187.9, 188.7, 190.2, 191.8, 199, 199.9, 205.4, 205.2, 206.4, 206.2, 208.2, 209.6, 212, 213.4, 218.9, 225, 225.8, 227.1, 227.3, 227, 227.1, 226.7, 229.2, 230.1, 230.2, 230.3, 231.3, 231.9, 232, 231.5, 231.2, 231.3, 234.6, 235.1, 241, 241.6, 242.7, 243.7, 243.1, 242.3, 241.9, 242.3, 244.5, 245.2, 245.1, 245.9, 246.8, 247.8, 248.3, 248.4, 248.4, 248.5, 250.7, 251, 251.3, 252.3, 253.3, 255, 255.3, 255.1, 254.8, 254.5, 256.2, 256.9, 255.6, 255.8, 257, 257.6, 257.3, 256.3, 255.7, 254.5, 256, 255.9, 254.6, 254.2, 255.2, 257, 257, 257.4, 257.3, 257.4, 259.8, 259.6, 256.9, 256.6, 257, 257.7, 258.1, 257.6, 257, 255.7, 256.8, 257.3, 256.2, 256.3, 257.3, 257.9, 258.3, 258.7, 257.6, 257.6, 259.4, 259.7, 257.5, 258.7, 259.9, 260, 261.3, 261.2, 260, 260.2, 262, 262.6, 261.7, 262.6, 264.6, 266.9, 268.7, 268.3, 266.9, 267.6, 269.9, 269.1, 268.8, 269.4, 271.8, 272.9, 273.6, 273.2, 272.3, 272.4, 274.5, 275.4, 276, 278.4, 279.8, 278.8, 278.5, 277.7, 276.8, 276.7, 278.7, 278.9, 278, 277.3, 279.4, 279.4, 280.1, 278.9, 278.5, 278.2, 280.2, 281, 277.9, 279.2, 279.8, 280.2, 280.3, 280.4, 279.4, 279.9, 281.9, 282.4)
t <- ts(v, frequency = 12)
o <- function(a){
accuracy(croston(t,h=12,alpha=a))["MAE"]
}
startTime <- proc.time()
optimize(o, 0.1, lower=0.1, upper=0.9, tol=0.1)
proc.time() - startTime
This yields an acceptable result however the optimization process is taking around 35 seconds. I really need to get it down to something more like 3 or 4 seconds. I tried playing around with the tolerance, but even with tol=0.5
the optimization still takes 15 seconds (and no longer yields very useful results).
I imagine the optimize
function is using something like a Nelder-Mead algorithm. Is there maybe a better/faster optimization algorithm that could be used specifically to optimize the alpha parameter of the croston
function?