Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F102767448
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
Mon, Feb 24, 00:02
Size
1 KB
Mime Type
text/x-python
Expires
Wed, Feb 26, 00:02 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
24424356
Attached To
R7571 SP4E-TB-TL-FR
optimizer.py
View Options
#!/usr/bin/env python3
import
matplotlib.pyplot
as
plt
import
numpy
as
np
import
scipy.optimize
from
mpl_toolkits.mplot3d
import
Axes3D
def
plot
(
func
,
iterations
,
title
):
'Plotting function for plane and iterations'
x
=
np
.
linspace
(
-
3
,
3
,
100
)
y
=
np
.
linspace
(
-
3
,
3
,
100
)
x
,
y
=
np
.
meshgrid
(
x
,
y
)
X
=
np
.
stack
([
x
.
flatten
(),
y
.
flatten
()],
axis
=
1
)
z
=
func
(
X
)
.
reshape
((
100
,
100
))
xy
=
np
.
array
(
iterations
)
zs
=
func
(
xy
)
fig
=
plt
.
figure
()
ax
=
Axes3D
(
fig
)
ax
.
plot_surface
(
x
,
y
,
z
,
linewidth
=
0
,
antialiased
=
True
,
cmap
=
plt
.
cm
.
viridis
,
alpha
=
0.2
)
ax
.
contour
(
x
,
y
,
z
,
10
,
colors
=
"k"
,
linestyles
=
"solid"
)
ax
.
plot
(
xy
[:,
0
],
xy
[:,
1
],
zs
,
'ro--'
)
ax
.
grid
(
False
)
ax
.
set_title
(
title
)
plt
.
xlabel
(
'$x$'
)
plt
.
ylabel
(
'$y$'
)
plt
.
show
()
def
solve
(
fun
,
x0
,
tol
=
'1e-8'
,
callback
=
None
,
**
kwargs
):
'Minimize function with BFGS'
res
=
scipy
.
optimize
.
minimize
(
fun
,
x0
,
method
=
'BFGS'
,
callback
=
callback
,
tol
=
tol
)
return
res
.
x
Event Timeline
Log In to Comment