Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F73828008
optimizer.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Jul 24, 17:27
Size
902 B
Mime Type
text/x-python
Expires
Fri, Jul 26, 17:27 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
19276816
Attached To
R9482 SP4E_Homework_Ashtari_Sieber
optimizer.py
View Options
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Oct 10 10:19:11 2019
Authors: Omid Ashtari and Armand Sieber
Description: Scripts intended to minimize a quadratic function using scipy.optimize built-in function.
The function to minimize is defined as S(X)= X'AX - X'B, with X = [x, y], X' the transform of X
A is a 2x2 matrix and B 2X1 vector
"""
import
numpy
as
np
from
scipy.optimize
import
minimize
def
objective
(
x
,
*
args
):
#objective function to be minimized
A
=
args
[
0
]
B
=
args
[
1
]
.
T
S
=
np
.
dot
(
x
.
T
,
np
.
dot
(
A
,
x
))
-
np
.
dot
(
x
.
T
,
B
)
return
S
# Parameters of the unction to minimize
A
=
np
.
array
([[
4
,
0
],
[
1
,
3
]])
B
=
np
.
array
([
0
,
1
])
# Initial guess
X0
=
np
.
array
([
3
,
2
])
print
(
objective
(
X0
,
A
,
B
))
solution
=
minimize
(
objective
,
X0
,
args
=
(
A
,
B
),
method
=
'BFGS'
,
options
=
{
'xtol'
:
1e-12
,
'maxiter'
:
100
})
print
(
solution
)
Event Timeline
Log In to Comment