Commit 372f1c4b authored by Fredrik Bagge Carlson's avatar Fredrik Bagge Carlson
Browse files

Removed some pltting functions from ar arx

parent 04f71332
"""`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"""
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment