Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Fredrik Bagge Carlson
SystemIdentification
Commits
a490a644
Commit
a490a644
authored
Sep 07, 2015
by
Fredrik Bagge Carlson
Browse files
poked armax
parent
b0371830
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/armax.jl
View file @
a490a644
...
...
@@ -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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment