Arima
c<-auto.arima(fil[[1]],start.p=0,start.q=0,start.P=0,start.Q=0,stepwise=TRUE,stationary=FALSE,trace=TRUE)
system.time(fit.500<-auto.arima(ts, d = NA, D = NA, max.p = 2, max.q = 2,max.P = 1, max.Q = 1, max.order = 5,
start.p=0, start.q=0, start.P=0, start.Q=0,stationary = FALSE, ic = c("aic","aicc", "bic"),stepwise=FALSE,trace=TRUE))
tsdiag(b)
x<-scan("trace")
x_arima<-arima(x, order=c(1,0,1),seasonal=list( order=c(1,1,1),period=12));
b_arima<-forecast(x_arima)
#attributes(b)
#summary(a)0
ets(data)#exponential smoothening
accuracy(b_arima$fitted,b_arima$x)
predict continuously
#library
library(forecast)
require(graphics)
require(stats)
zro <- array(0, dim=c(1,400))
#constants
Data_rate <- 20756 #byte per 5 mili sec
#Inputs
gap<-50
start<-0
end<-200
sum<-0
#read file
input_file<-"riverbed.txt"
output_file<-"Predected_riverbed.txt"
unlink(output_file)
trace=scan(input_file)
size<-length(trace)
arr<-trace[start:end]
write(c(arr), file = output_file,append = TRUE, sep = "\n")
while(end+gap<size)
{
#trace=scan("a")
end2<-0
arr<-trace[start:end]
end2<-end+gap
end3<-end+1
arr2<-trace[end3:end2]
#forecast
x_arima<-arima(arr, order=c(1,0,1),seasonal=list( order=c(1,1,1),period=16),method = c("CSS"))
b_arima<-forecast(x_arima,gap)
#accuracy(b_arima$fitted,b_arima$x)
#attributes(b_arima)
#summary(s_arima)
#framing
wframe <- array(0, dim=c(1,400))
framing <-c(b_arima$mean)
#framing <-arr2
i=1;
j=1;
count=0
while (j <=gap){
a<-framing[j]
sum1=a
if(sum1 < Data_rate){ wframe[i]=sum1;sum1=0;wframe[i+1:i+8]=0; i=i+8}
else if(sum1 == Data_rate){ wframe[i]=Data_rate;wframe[i+1:i+8]=0; sum1=0;i=i+8}
else if(sum1 > Data_rate){
while(sum1>Data_rate)
{
sum1=sum1-Data_rate
wframe[i]=Data_rate
i=i+1
count=count+1
}
wframe[i]=sum1; sum1=arr[start+i];i=i+8-count-1; sum1=0;count=0}
j=j+1;
#print(wframe[i])
#write(i, file = "ufhfui",append = TRUE, sep = "\n")
}
#1/0
abc<-wframe
wframe <- array(0, dim=c(1,400))
for (k in 1:400) {
dd=abc[k]
#write(dd, file = "ufhfui",append = TRUE, sep = "\n")
if(dd==0){zro[k]=5; wframe[k]<-0}
else if (dd>0) {wframe[k]<-10; zro[k]=0}
else if (dd<0) {wframe[k]<-10; zro[k]=0}
}
#plot
op <- par(mfrow = c(2, 1))
plot(c(b_arima$mean),type ="o",col = "red",ylab="Frame Size",xlab="Frame Index",main="Video Frame Predection")
lines(arr2,type ="o",col = "blue")
legend("topright",c("Original","Predected"), cex=0.8,col=c("blue","red"), pch=21:22, lty=1:2);
plot(c(wframe),type ="h",col = "red",ylab="Frame Size",xlab="Wireless Frame Index",main="Wireless Frames ")
lines(c(zro),type ="h",col = "green")
legend("topright",c("Occupied Frames","Empty Frames"), cex=0.8,col=c("red","green"), pch=21:22, lty=1:2);
start<-start+gap
end<-end+gap
cat("Predected: ",end,"\n",file = "")
#Sys.sleep(1)
par(op)
write(c(b_arima$mean), file = output_file,append = TRUE, sep = "\n")
}
cat("!@#$%^&*()_+!@#$%^&*()_+","\n","done","\n",file = "")
cat(" Bandwidth 10 MHz","\n",file = "")
cat(" Downlink 29","\n",file = "")
cat(" Uplink 18","\n",file = "")
cat(" Preamble 1","\n",file = "")
cat(" fft Size 1024","\n",file = "")
cat(" Modulation QPSK","\n",file = "")
cat(" Code Rate 0.75","\n",file = "")
cat(" Data Sub Carrier 720","\n",file = "")
cat(" No of Subchannels 30","\n",file = "")
cat(" Symbol Perslot 2","\n",file = "")
cat(" Symbol Period 102.9 micro sec","\n",file = "")
cat(" frame_duration 5 micro sec","\n",file = "")
cat(" headers 51 Slots","\n",file = "")
cat(" Loading Factor 0.00625(160 fraction of BW is available) ","\n",file = "")
cat(" Video Frame Rate 25 frame/sec","\n",file = "")
cat(" Symbol/frame 0.048591","\n",file = "")
cat(" No of slots 24","\n",file = "")
cat(" DL slot / frame 420","\n",file = "")
cat(" Useful slots 369","\n",file = "")
cat(" Bits/slot 72","\n",file = "")
cat(" Data rate per DL 26568","\n",file = "")
cat(" Data rate per 5 mili sec 20756.25 byte","\n",file = "")
library(forecast)
require(graphics)
require(stats)
gap<-50
start<-0
end<-241
trace=scan("file.txt")
size<-length(trace)
arr<-trace[start:end]
unlink("data")
write(c(arr), file = "data",append = TRUE, sep = "\n")
while(end+gap<size)
{
#trace=scan("a")
arr<-trace[start:end]
end2=end+gap
arr2<-trace[end+1:end2]
#png(filename="start.png", height=600, width=600,bg="white")
x_arima<-arima(arr, order=c(1,0,1),seasonal=list( order=c(1,1,1),period=16),method = c("CSS"))
b_arima<-forecast(x_arima,gap)
#accuracy(b_arima$fitted,b_arima$x)
#attributes(b_arima)
#summary(s_arima)
#plot(forecast(x_arima,50),col = "red",main="Frame Trace Predection",ylab="Frame Size",xlab="Frame Index")
plot(c(b_arima$mean),type ="b",col = "red",ylab="Frame Size",xlab="Frame Index")
legend(length(x)*15,0.95,c("Original","Predected"), cex=0.8,col=c("red","blue"), pch=21:22, lty=1:2);
lines(arr2,type ="b",col = "blue")
#plot(arr2,type ="b",col = "blue")
#lines(x,type ="b",col = "red")
start=start+gap
end=end+gap
cat("Predected: ",start,"\n",file = "")
write(c(b_arima$mean),"\t",arr2,file = "data",append = TRUE, sep = "\n")
#dev.off()
Sys.sleep(1)
}
library(forecast)
require(graphics)
require(stats)
start<-0
end<-200
trace=scan("trace200")
size<-length(trace)
while(end+50<size)
{
trace=scan("trace200")
arr<-trace[start:end]
end2=end+50
arr2<-trace[start:end2]
x_arima<-arima(arr, order=c(1,0,1),seasonal=list( order=c(1,1,1),period=16));
b_arima<-forecast(x_arima,50)
#accuracy(b_arima$fitted,b_arima$x)
#attributes(b_arima)
#summary(s_arima)
#plot(forecast(x_arima,50),col = "red",main="Frame Trace Predection",ylab="Frame Size",xlab="Frame Index")
plot(arr,type ="l",col = "red")
lines(arr2,type ="o")
start=start+50
end=end+50
cat(start,"___________________________________________________________________________","\n",file = "")
#Sys.sleep(1)
}
arima.sim(model, n=, rand.gen = rnorm, innov = rand.gen(n, ...),n.start = NA, start.innov = rand.gen(n.start, ...),...)
arima.sim(c(1,0,1), n=, rand.gen = rnorm, innov = rand.gen(n, ...),n.start = NA, start.innov = rand.gen(n.start, ...),...)
arima.sim(n = 63, list(ar = c(0.8897, -0.4858), ma = c(-0.2279, 0.2488)),sd = sqrt(0.1796))
garsim(n, phi, X = matrix(0, nrow = n), beta = as.matrix(0), sd = 1, family = "gaussian",transform.Xbeta = "identity", link = "identity", minimum = 0, zero.correction = "zq1", c = 1, theta = 0)
a=arrep(notation = "arima", phi = c(0.88780450), d = 0, theta = c(-0.64850050), Phi = c(0.05159824), D = 1,Theta = c(-0.67678839), frequency = 12)
a=arrep(notation = "arima", phi = c(1), d = 0, theta = c(1), Phi = c(1), D = 1,Theta = c(1), frequency = 12)
phi:p vector of autoregressive coefficient. (0.8878,0.0027)
d:difference operator, implemented: d element of (0,1,2).
theta:q vector of moving average coefficients.
Phi:P vector of seasonal autoregressive coefficients.
D:Seasonal difference operator, implemented: D element of(0,1,2).
Theta:Q vector of seasonal moving average coefficients.
frequency:The frequency of the seasonality (e.g. frequency = 12 for monthly series with annual periodicity).
auto.arima(x, d = NA, D = NA, max.p = 5, max.q = 5,max.P = 2, max.Q = 2, max.order = 5,start.p=2, start.q=2, start.P=1, start.Q=1,stationary = FALSE, ic = c("aic","aicc", "bic"),stepwise=TRUE, trace=FALSE,approximation=length(x)>100 | frequency(x)>12, xreg=NULL,test=c("kpss","adf","pp"), allowdrift=TRUE)
HoltWinters(x) Computes Holt-Winters Filtering of a given time series
rwf(x) Returns forecasts and prediction intervals for a random walk with drift model applied to x
ets(x) Returns Exponential smoothing state space model for series x
accuracy(x) Accuracy measures for forecast model (ME,RMSE,MAE,MPE,MAPE,MASE)
forecast generic function for forecasting from time series
forecast.Arima forecasts based on the results produced by ‘arima’
forecast.ts forecasts using exponential smoothing state space models
auto.arima Returns best ARIMA model according to either AIC, AICc or BIC value
arima.sim Simulate from an ARIMA model
garsim Simulate a time series using a general autoregressive model
arrep Invert (invertible) SARIMA(p, d, q, P, D, Q) models to AR representation
Arima
arima
ar
meanf
splinef
thetaf
croston
ses
holt
hw
forecast(object, h=ifelse(object$arma[5]>1,2*object$arma[5],10),level=c(80,95), fan=FALSE, xreg=NULL,...)
forecast(object, h=10, level=c(80,95), fan=FALSE, ...)
forecast(object, h=10, level=c(80,95), fan=FALSE, ...)
data <- c(67, 81, 93, 65, 18, 44, 31, 103, 64, 19, 27, 57, 63, 25, 22, 150,31, 58, 93, 6, 86, 43, 17, 9, 78, 23, 75, 28, 37, 23, 108, 14, 137,69, 58, 81, 62, 25, 54, 57, 65, 72, 17, 22, 170, 95, 38, 33, 34, 68,38, 117, 28, 17, 19, 25, 24, 15, 103, 31, 33, 77, 38, 8, 48, 32, 48,26, 63, 16, 70, 87, 31, 36, 31, 38, 91, 117, 16, 40, 7, 26, 15, 89,67, 7, 39, 33, 58)
rmse=rmse <- function(obs, pred) sqrt(mean((b_arima$fitted-b_arima$x)^2))