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
39f96b24
Commit
39f96b24
authored
Sep 06, 2015
by
Fredrik Bagge Carlson
Browse files
Implemented minimization of 1-norm for ar arx
parent
b2dfad97
Changes
2
Show whitespace changes
Inline
Side-by-side
src/PCA.jl
View file @
39f96b24
""" Performs PCA PCA(W
,doplot=false
)"""
function
PCA
(
W
,
doplot
=
false
)
""" Performs PCA PCA(W)"""
function
PCA
(
W
)
W0
=
mean
(
W
,
1
);
W
=
W
-
repmat
(
W0
,
size
(
W
,
1
),
1
);
(
score
,
latent
,
C
)
=
svd
(
W
)
score
=
score
*
diagm
(
latent
)
if
doplot
newplot
(
cumsum
(
latent
)
./
sum
(
latent
),
"o"
)
title
(
"Fraction of variance explained"
)
ylim
([
0
,
1
])
end
C
,
score
,
latent
,
W0
end
src/armax.jl
View file @
39f96b24
using
Convex
using
SCS
"""`ar(y, na; λ = 0)`"""
function
ar
(
y
::
Vector
{
Float64
},
na
;
λ
=
0
)
function
ar
(
y
::
Vector
{
Float64
},
na
;
λ
=
0
,
normtype
=
2
,
verbose
=
false
)
y_train
,
A
=
getARregressor
(
y
,
na
)
n_points
=
size
(
A
,
1
)
if
normtype
==
2
if
λ
==
0
w
=
A
\
y_train
else
w
=
(
A
'
A
+
λ
*
eye
(
size
(
A
,
2
)))
\
A
'
y_train
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
[
:
]
end
prediction
=
A
*
w
error
=
y_train
-
prediction
model
=
AR
(
w
,
na
)
...
...
@@ -16,14 +25,21 @@ end
ar
(
iddata
::
IdData
,
na
;
λ
=
0
)
=
ar
(
iddata
.
y
,
na
;
λ
=
0
)
"""arx(y, u, na, nb; λ = 0)"""
function
arx
(
y
::
Vector
{
Float64
},
u
::
VecOrMat
{
Float64
},
na
,
nb
;
λ
=
0
)
function
arx
(
y
::
Vector
{
Float64
},
u
::
VecOrMat
{
Float64
},
na
,
nb
;
λ
=
0
,
normtype
=
2
,
verbose
=
false
)
y_train
,
A
=
getARXregressor
(
y
,
u
,
na
,
nb
)
n_points
=
size
(
A
,
1
)
if
normtype
==
2
if
λ
==
0
w
=
A
\
y_train
else
w
=
(
A
'
A
+
λ
*
eye
(
size
(
A
,
2
)))
\
A
'
y_train
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
[
:
]
end
prediction
=
A
*
w
error
=
y_train
-
prediction
...
...
Write
Preview
Supports
Markdown
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