From 372f1c4bcd231eabfac54a1feaef0537bde7f3a9 Mon Sep 17 00:00:00 2001 From: Fredrik Bagge Carlsson <cont-frb@ulund.org> Date: Fri, 4 Sep 2015 10:53:11 +0200 Subject: [PATCH] Removed some pltting functions from ar arx --- src/armax.jl | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/src/armax.jl b/src/armax.jl index 01ab5b5..b3aafce 100644 --- a/src/armax.jl +++ b/src/armax.jl @@ -1,6 +1,6 @@ """`ar(y, na; λ = 0, doplot=false, bias=false)`""" -function ar(y::Vector{Float64}, na; λ = 0, doplot=false, bias=false) - y_train, A = getARRegressor(y,na;bias=bias) +function ar(y::Vector{Float64}, na; λ = 0, bias=false) + y_train, A = getARregressor(y,na;bias=bias) n_points = size(A,1) if λ == 0 w = A\y_train @@ -9,20 +9,13 @@ function ar(y::Vector{Float64}, na; λ = 0, doplot=false, bias=false) end prediction = A*w error = y_train - prediction - if doplot - newplot(y_train,"k") - plot(prediction,"b") - plot(error,"r"); title("Fitresult, AR, na: $na, RMSE: $(round(rms(error),4)) Fit = $(round(fit(y_train,prediction),4))") - # Exit =============================================== - println("AR done. na: $na + 1 bias, RMSE: $(round(rms(error),4))") - end - return w, error + return AR(w,na,bias,λ), FitResult(error,:LS) end -ar(iddata::IdData, na; λ = 0, doplot=false, bias=false) = ar(iddata.y, na; λ = 0, doplot=doplot, bias=bias) +ar(iddata::IdData, na; λ = 0, doplot=false, bias=false) = ar(iddata.y, na; λ = 0, bias=bias) """arx(y, u, na, nb; λ = 0, doplot=false, bias=false)""" function arx(y::Vector{Float64}, u::VecOrMat{Float64}, na, nb; λ = 0, doplot=false, bias=false) - y_train, A = getARXRegressor(y,u, na, nb; bias=bias) + y_train, A = getARXregressor(y,u, na, nb; bias=bias) n_points = size(A,1) if λ == 0 w = A\y_train @@ -31,17 +24,10 @@ function arx(y::Vector{Float64}, u::VecOrMat{Float64}, na, nb; λ = 0, doplot=fa end prediction = A*w error = y_train - prediction - if doplot - newplot(y_train,"k") - plot(prediction,"b") - plot(error,"r"); title("Fitresult, ARX, na: $na, nb: $nb, $(bias ? "+ 1 bias," : "") RMSE: $(round(rms(error),4)) Fit = $(round(fit(y_train,prediction),4))") - # Exit =============================================== - println("ARX done. na: $na, nb: $nb, $(bias ? "+ 1 bias," : "") RMSE: $(round(rms(error),4))") - end - return w, error -end -arx(iddata::IdData, na, nb; λ = 0, doplot=false, bias=false) = arx(iddata.y, iddata.u, na, nb; λ = 0, doplot=doplot, bias=bias) + return AR(w,na,bias,λ), FitResult(error,:LS) +end +arx(iddata::IdData, na, nb; λ = 0, bias=false) = arx(iddata.y, iddata.u, na, nb; λ = 0, bias=bias) function getARregressor(y::Vector{Float64},na;bias=false) @@ -54,7 +40,7 @@ function getARregressor(y::Vector{Float64},na;bias=false) end return y,A end -getARregressor(iddata::IdData, na, bias=false) = getARXRegressor(iddata.y, na, bias=bias) +getARregressor(iddata::IdData, na, bias=false) = getARXregressor(iddata.y, na, bias=bias) function getARXregressor(y::Vector{Float64},u::VecOrMat{Float64}, na, nb; bias=false) assert(length(nb) == size(u,2)) @@ -75,7 +61,7 @@ function getARXregressor(y::Vector{Float64},u::VecOrMat{Float64}, na, nb; bias=f end return y,A end -getARXregressor(iddata::IdData, na, nb; bias=false) = getARXRegressor(iddata.y,iddata.u, na, nb, bias=bias) +getARXregressor(iddata::IdData, na, nb; bias=false) = getARXregressor(iddata.y,iddata.u, na, nb, bias=bias) """Plots the RMSE and AIC for model orders up to `n`. Useful for model selection""" -- GitLab