From 9702b42f6f8d66f478e564bec37d05d157b4172e Mon Sep 17 00:00:00 2001 From: Fredrik Bagge Carlson <cont-frb@ulund.org> Date: Tue, 13 Sep 2016 15:52:07 +0200 Subject: [PATCH] updates --- src/SystemIdentification.jl | 6 +++--- src/kalman.jl | 18 ++++++++++++++++-- src/least_squares.jl | 2 +- src/particle_filters/pf_bootstrap.jl | 2 +- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/SystemIdentification.jl b/src/SystemIdentification.jl index c74e368..7841796 100644 --- a/src/SystemIdentification.jl +++ b/src/SystemIdentification.jl @@ -13,7 +13,7 @@ FitResult, IdData, # Functions ar,arx,getARregressor,getARXregressor,find_na, -toeplitz, kalman, kalman_smoother, forward_kalman +toeplitz, kalman, kalman_smoother, forward_kalman, PCA ## Fit Methods ================= :LS @@ -26,8 +26,8 @@ abstract Model abstract LinearModel <: Model abstract NonLinearModel <: Model abstract Network <: NonLinearModel -typealias Polynom{T<:Real} Union(Array{T,1} , T) -typealias PolynomMatrix{T} Union(Array{Polynom{T},1},Polynom{T}, T) +typealias Polynom{T<:Real} Union{Array{T,1} , T} +typealias PolynomMatrix{T} Union{Array{Polynom{T},1},Polynom{T}, T} diff --git a/src/kalman.jl b/src/kalman.jl index b78b88b..345fa13 100644 --- a/src/kalman.jl +++ b/src/kalman.jl @@ -1,8 +1,8 @@ """ + `kalman(R1,R2,theta, y, A, P)` One dimensional Kalman filter for parameter estimates -`kalman(R1,R2,theta, y, A, P)` """ -function kalman(R1,R2,theta, y, A, P) +function kalman1(R1,R2,theta, y, A, P) ATP = A'P K = (P*A)/(R2+ATP*A) P = P - (P*A*ATP)./(R2 + ATP*A) + R1 @@ -12,6 +12,20 @@ function kalman(R1,R2,theta, y, A, P) return theta, P, e, yp end +""" + `kalman(R1,R2,R12,theta, y, A, P)` +General Kalman filter for parameter estimates +""" +function kalman(R1,R2,R12,theta, y, A, P) + ATP = A'P + K = (P*A+R12)/(R2+ATP*A) + P = P - (P*A+R12)/(R2 + ATP*A)*(ATP+R12') + R1 + yp = (A'theta)[1] + e = y-yp + theta = theta + K*e + return theta, P, e, yp +end + function forward_kalman(y,A,R1,R2, P0) diff --git a/src/least_squares.jl b/src/least_squares.jl index 23cf705..4a0395d 100644 --- a/src/least_squares.jl +++ b/src/least_squares.jl @@ -38,7 +38,7 @@ end function Lcurve(normE, normX, λ) plot(normE,normX,xscale=:log10,yscale=:log10,m=:o) - annotations = [(normE[i],normX[i],"λ=$(round(λ[i],4))") for i in 1:length(λ)] + annotations = [(normE[i],normX[i],"λ=$(round(λ[i],8))") for i in 1:length(λ)] annotate!(annotations) xlabel!("RMSE"); ylabel!("||k||"); title!("L-curve") end diff --git a/src/particle_filters/pf_bootstrap.jl b/src/particle_filters/pf_bootstrap.jl index 931280d..4caacc8 100644 --- a/src/particle_filters/pf_bootstrap.jl +++ b/src/particle_filters/pf_bootstrap.jl @@ -130,7 +130,7 @@ function pf_aux_nn(xp, w, wnn, y, N, g_density, f) for t = 2:T xpT = xp[:,t-1] - f(xpT,t-1) + f(xpT,t-1) # This is now incorrect. particles should be propagated without noise in this step. wT = copy(w[:,t-1]) lambda = g_density(y[t],xpT) -- GitLab