diff --git a/src/SystemIdentification.jl b/src/SystemIdentification.jl index eb88e0425e46ddc33397e64becf826ee07a70a98..4aeb5c3eeda60056cf1ea7953b15c8594d4df48d 100644 --- a/src/SystemIdentification.jl +++ b/src/SystemIdentification.jl @@ -8,8 +8,9 @@ ARX, RBFARX, FitStatistics, FitResult, +IdData, # Functions -ar,arx,getARRegressor,getARXRegressor,findNa +ar,arx,getARregressor,getARXregressor,find_na ## Fit Methods ================= :LS @@ -59,26 +60,26 @@ type RBFARX <: Network normalized::Bool end -type Fitstatistics +type FitStatistics RMS::Float64 FIT::Float64 AIC::Float64 - Fitstatistics(e::Vector{Float64}) = new(rms(e),fit(e),aic(e)) + FitStatistics(e::Vector{Float64}) = new(rms(e),fit(e),aic(e)) end -type Fitresult +type FitResult error::VecOrMat{Float64} - fit::Fitstatistics + fit::FitStatistics method::Symbol end -type Iddata +type IdData y::VecOrMat{Float64} u::VecOrMat{Float64} Ts::Float64 - Iddata(y::VecOrMat{Float64}) = new(y,[],0) - Iddata(y::VecOrMat{Float64} ,Ts::Float64) = new(y,[],Ts) - Iddata(y::VecOrMat{Float64}, u::VecOrMat{Float64}) = new(y,u,0) + IdData(y::VecOrMat{Float64}) = new(y,[],0) + IdData(y::VecOrMat{Float64} ,Ts::Float64) = new(y,[],Ts) + IdData(y::VecOrMat{Float64}, u::VecOrMat{Float64}) = new(y,u,0) end diff --git a/src/armax.jl b/src/armax.jl index a9dbf119496ea4d48cefcde809e7ac0d1487e4c3..01ab5b546caa513685bbb9af2c212cfce1c7c043 100644 --- a/src/armax.jl +++ b/src/armax.jl @@ -1,5 +1,5 @@ """`ar(y, na; λ = 0, doplot=false, bias=false)`""" -function 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) n_points = size(A,1) if λ == 0 @@ -18,10 +18,10 @@ function ar(y, na; λ = 0, doplot=false, bias=false) end return w, error end -ar(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, doplot=doplot, bias=bias) """arx(y, u, na, nb; λ = 0, doplot=false, bias=false)""" -function 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) n_points = size(A,1) if λ == 0 @@ -40,11 +40,11 @@ function arx(y, u, na, nb; λ = 0, doplot=false, bias=false) end return w, error end -arx(iddata, na, nb; λ = 0, doplot=false, bias=false) = arx(iddata.y, iddata.u, na, nb; λ = 0, doplot=doplot, bias=bias) +arx(iddata::IdData, na, nb; λ = 0, doplot=false, bias=false) = arx(iddata.y, iddata.u, na, nb; λ = 0, doplot=doplot, bias=bias) -function getARRegressor(y,na;bias=false) +function getARregressor(y::Vector{Float64},na;bias=false) A = toeplitz(y[na+1:end],y[na+1:-1:1]) y = copy(A[:,1]) A = A[:,2:end] @@ -54,9 +54,9 @@ function getARRegressor(y,na;bias=false) end return y,A end -getARRegressor(iddata, na, bias=false) = getARXRegressor(iddatay, na, bias=bias) +getARregressor(iddata::IdData, na, bias=false) = getARXRegressor(iddata.y, na, bias=bias) -function getARXRegressor(y,u, na, nb; bias=false) +function getARXregressor(y::Vector{Float64},u::VecOrMat{Float64}, na, nb; bias=false) assert(length(nb) == size(u,2)) @show m = max(na+1,maximum(nb)) @show n = length(y) - m+1 @@ -75,11 +75,11 @@ function getARXRegressor(y,u, na, nb; bias=false) end return y,A end -getARXRegressor(iddata, na, nb; bias=false) = getARXRegressor(iddatay,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""" -function findNa(y,n) +function find_na(y::Vector{Float64},n::Int) error = zeros(n,2) for i = 1:n w,e = ar(y,i)