Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F86096207
post_processing.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
Fri, Oct 4, 06:23
Size
2 KB
Mime Type
text/x-python
Expires
Sun, Oct 6, 06:23 (2 d)
Engine
blob
Format
Raw Data
Handle
21278414
Attached To
R9482 SP4E_Homework_Ashtari_Sieber
post_processing.py
View Options
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Oct 14 15:19:11 2019
Authors: Omid Ashtari and Armand Sieber
Description: Scripts intended to display minimization proplems results
"""
import
numpy
as
np
import
matplotlib.pyplot
as
plt
from
mpl_toolkits.mplot3d
import
Axes3D
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
def
plot_results
(
X_int
,
A
,
B
,
method
):
# Pre-processing the data to be dispalyed
##########################################
# Set domain size and coordinates according to intermediate solution of minimization problem
x1
=
np
.
max
(
np
.
abs
(
X_int
[:,
0
]))
x2
=
np
.
max
(
np
.
abs
(
X_int
[:,
1
]))
X_domain
=
np
.
linspace
(
-
1.5
*
x1
,
1.5
*
x1
,
100
)
Y_domain
=
np
.
linspace
(
-
1.5
*
x2
,
1.5
*
x2
,
100
)
xx
,
yy
=
np
.
meshgrid
(
X_domain
,
Y_domain
)
# Compute S for the computational domain (S_post) and intermediate minimization solution (S_int)
S_post
=
np
.
array
([
objective
(
np
.
array
([
x
,
y
]),
A
,
B
)
for
x
,
y
in
zip
(
np
.
ravel
(
xx
),
np
.
ravel
(
yy
))])
# Value of S for 3D plot (whole X-Y domain)
S_post
=
S_post
.
reshape
(
xx
.
shape
)
S_int
=
np
.
array
([
objective
(
np
.
array
([
x
,
y
]),
A
,
B
)
for
x
,
y
in
zip
(
X_int
[:,
0
],
X_int
[:,
1
])])
# Value of S at intermediate minimization steps
# Dispalying the results
########################
fig
=
plt
.
figure
(
1
)
# 3D plot
ax
=
plt
.
axes
(
projection
=
'3d'
)
ax
.
plot3D
(
X_int
[:,
0
],
X_int
[:,
1
],
S_int
,
'r--o'
,
alpha
=
1.0
,
zorder
=
10
)
surface
=
ax
.
plot_surface
(
xx
,
yy
,
S_post
,
cmap
=
'Greys'
,
edgecolor
=
'none'
,
alpha
=
1.0
,
zorder
=
0
)
# zorder 'best' solution found to plot S_int over S_post
# --> alternative using mayavi
ax
.
set_xlabel
(
'$x$'
,
fontsize
=
14
)
ax
.
set_ylabel
(
'$y$'
,
fontsize
=
14
)
ax
.
set_zlabel
(
'$S$'
,
fontsize
=
14
)
ax
.
view_init
(
elev
=
60.0
,
azim
=
130.0
)
ax
.
set_title
(
'Minimization method:
%s
'
%
method
,
fontsize
=
14
,
pad
=
32
)
plt
.
savefig
(
'3D_representration.pdf'
,
bbox_inches
=
'tight'
)
fig
=
plt
.
figure
(
2
)
# 2D contour plot
ax
=
fig
.
add_subplot
(
111
)
ax
.
contour
(
xx
,
yy
,
S_post
,
colors
=
'k'
,
levels
=
20
)
contour
=
ax
.
contourf
(
xx
,
yy
,
S_post
,
cmap
=
'Greys'
,
levels
=
20
)
ax
.
plot
(
X_int
[:,
0
],
X_int
[:,
1
],
'r--o'
)
ax
.
set_xlabel
(
'$x$'
,
fontsize
=
14
)
ax
.
set_ylabel
(
'$y$'
,
fontsize
=
14
)
ax
.
set_title
(
'Minimization method:
%s
'
%
method
,
fontsize
=
14
)
fig
.
colorbar
(
contour
,
ax
=
ax
)
plt
.
savefig
(
'2D_projection.pdf'
,
bbox_inches
=
'tight'
)
plt
.
show
()
return
0
Event Timeline
Log In to Comment