Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F119989324
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
Tue, Jul 1, 02:51
Size
902 B
Mime Type
text/x-python
Expires
Thu, Jul 3, 02:51 (2 d)
Engine
blob
Format
Raw Data
Handle
27122397
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