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
6db679f2
Commit
6db679f2
authored
Jan 28, 2016
by
Fredrik Bagge Carlson
Browse files
implemented Tkhonov regularized least-squares using SVD
parent
e6c4b901
Changes
1
Show whitespace changes
Inline
Side-by-side
src/least_squares.jl
0 → 100644
View file @
6db679f2
"""
Calculates the Tikhonov regularized estimate min. ||Ax-b|| + λ||x|| using SVD
for a vector with different values of λ
`x, normE, normX = dsvd(A,U,S,V,b,λ)`
`x, normE, normX = dsvd(A,b,λ)`
"""
function
dsvd
(
A
,
U
,
S
,
V
,
b
,
λ
)
if
minimum
(
λ
)
<
0
error
(
"Illegal regularization parameter λ"
)
end
UTb
=
U
'
b
N
=
size
(
U
,
1
)
n
=
size
(
V
,
1
)
nl
=
length
(
λ
)
x
=
zeros
(
n
,
nl
)
normE
=
zeros
(
nl
)
normX
=
zeros
(
nl
)
print
(
"dsvd: "
)
for
(
i
,
λi
)
in
enumerate
(
λ
)
x
[
:
,
i
]
=
V
*
diagm
(
S
./
(
S
.^
2
+
λi
))
*
UTb
normX
[
i
]
=
norm
(
x
[
:
,
i
])
normE
[
i
]
=
norm
(
A
*
x
[
:
,
i
]
-
b
)
print
(
"[
$
(round(i/length(λ),2)),
$
(round(λi,2))] "
)
end
println
(
"Done "
)
return
x
,
normE
,
normX
end
function
dsvd
(
A
,
b
,
λ
)
if
minimum
(
λ
)
<
0
error
(
"Illegal regularization parameter λ"
)
end
U
,
S
,
V
=
svd
(
A
)
dsvd
(
A
,
U
,
S
,
V
,
b
,
λ
)
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
(
λ
)]
annotate!
(
annotations
)
xlabel!
(
"RMSE"
);
ylabel!
(
"||k||"
);
title!
(
"L-curve"
)
end
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