Skip to content
Snippets Groups Projects
Commit a490a644 authored by Fredrik Bagge Carlson's avatar Fredrik Bagge Carlson
Browse files

poked armax

parent b0371830
No related branches found
No related tags found
1 merge request!1Dev
......@@ -7,19 +7,22 @@ function ar(y::Vector{Float64}, na; λ = 0, normtype=2, verbose=false)
if normtype == 2
if λ == 0
w = A\y_train
method = :LS
else
w = (A'A + λ*eye(size(A,2)))\A'y_train
method = :LS_reg
end
elseif normtype == 1
w = Variable(size(A,2),1)
problem = minimize(sum(abs(A*w-y_train )) + λ*norm(w))
solve!(problem, SCSSolver(verbose=Int(verbose)))
w = w.value[:]
method = :L1
end
prediction = A*w
error = y_train - prediction
model = AR(w,na)
result = FitResult(y_train,prediction,na, λ>0?(:LS_reg) :(:LS),λ)
result = FitResult(y_train,prediction,na, method,λ)
return model, result
end
ar(iddata::IdData, na; λ = 0) = ar(iddata.y, na; λ = 0)
......@@ -31,14 +34,17 @@ function arx(y::Vector{Float64}, u::VecOrMat{Float64}, na, nb; λ = 0, normtype=
if normtype == 2
if λ == 0
w = A\y_train
method = :LS
else
w = (A'A + λ*eye(size(A,2)))\A'y_train
method = :LS_reg
end
elseif normtype == 1
w = Variable(size(A,2),1)
problem = minimize(sum(abs(A*w-y_train )) + λ*norm(w))
solve!(problem, SCSSolver(verbose=Int(verbose)))
w = w.value[:]
method = :L1
end
prediction = A*w
error = y_train - prediction
......@@ -51,7 +57,7 @@ function arx(y::Vector{Float64}, u::VecOrMat{Float64}, na, nb; λ = 0, normtype=
si += nb[i]
end
model = ARX(w[1:na],b,na,nb)
result = FitResult(y_train,prediction,na, λ>0?(:LS_reg) :(:LS), λ)
result = FitResult(y_train,prediction,na, method, λ)
return model, result
end
arx(iddata::IdData, na, nb; λ = 0) = arx(iddata.y, iddata.u, na, nb; λ = 0)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment