Skip to content

Commit

Permalink
conversions and predict functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
neveritt committed May 18, 2017
1 parent 59ce3dc commit b17850f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
julia 0.4
Polynomials 0.1.0
Optim 0.6.0
ControlCore 0.0.1
SystemsBase
Compat 0.9.0
ToeplitzMatrices 0.1.1
GeneralizedSchurAlgorithm 0.0.2
34 changes: 34 additions & 0 deletions src/methods/pem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,51 @@ function _modelfit{T<:Real}(mse, y::AbstractMatrix{T})
modelfit = [100*(1 - mse[i]/cov(y[i,1:N])) for i in 1:ny] # TODO fix to correct order m y[m:N]
end

predict{T1,V1,V2}(data::IdDataObject{T1,V1,V2}, sys::IdMFD) =
_predict(data,sys.A,sys.B,sys.F,sys.C,sys.D,sys.info.model)


function predict{T1,V1,V2,S,U,M,T2,O}(data::IdDataObject{T1,V1,V2},
model::PolyModel{S,U,M}, Θ::AbstractVector{T2}, options::IdOptions{O}=IdOptions())
Θₚ,icbf,icdc,iccda = _split_params(model, Θ, options)
a,b,f,c,d = _getpolys(model, Θₚ)

return _predict(data,a,b,f,c,d,model,icbf,icdc,iccda)
na,nb,nf,nc,nd,nk = orders(model)

ny = data.ny
nbf = max(nb, nf)
ndc = max(nd, nc)
ncda = max(nc, nd+na)

# save unnecessary computations
temp = nbf > 0 ? filt(b, f, data.u, icbf) : data.u
temp2 = ndc > 0 ? filt(d, c, temp, icdc) : temp
temp3 = ncda > 0 ? temp2 + filt(c-d*a, c, data.y, iccda) : temp2
return temp3 # 10.53 [Ljung1999]
end

function _predict{T1,V1,V2,S,U,M}(data::IdDataObject{T1,V1,V2},a,b,f,c,d,
model::PolyModel{S,U,M},icbf=zeros(T1,0,0),
icdc=zeros(T1,0,0),iccda=zeros(T1,0,0))

na,nb,nf,nc,nd,nk = orders(model)

ny = data.ny
nbf = max(nb, nf)
ndc = max(nd, nc)
ncda = max(nc, nd+na)

if length(icbf) == 0
icbf = zeros(T1, ny*nk[1], nbf)
end
if length(icdc) == 0
icdc = zeros(T1, ny, ndc)
end
if length(iccda) == 0
iccda = zeros(T1, ny, ncda)
end

# save unnecessary computations
temp = nbf > 0 ? filt(b, f, data.u, icbf) : data.u
temp2 = ndc > 0 ? filt(d, c, temp, icdc) : temp
Expand Down
4 changes: 3 additions & 1 deletion src/types/idmfd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ function IdMFD{T<:AbstractFloat, S}(a::AbstractMatrix{T},
end

# conversion to tf
tf(s::IdMFD{Val{:siso},Val{:disc}}) = tf(coeffs(s.G.N), coeffs(s.G.D), s.G.Ts, :z̄)
tf{T}(s::IdMFD{T,Val{:siso},Val{:disc}}) = tf(coeffs(s.B[1]), coeffs(s.F[1]), s.G.Ts, :z̄)
lfd(s::IdMFD) = lfd(s.G)
ss{T}(s::IdMFD{T,Val{:siso},Val{:disc}}) = ss(tf(s))


samplingtime(s::IdMFD) = s.G.Ts
isdiscrete(s::IdMFD) = true
Expand Down

0 comments on commit b17850f

Please sign in to comment.