Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
adaptive
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Quantum Tinkerer
adaptive
Merge requests
!124
Resolve "(LearnerND) add iso-surface plot feature"
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Resolve "(LearnerND) add iso-surface plot feature"
112-learnernd-add-iso-surface-plot-feature
into
master
Overview
21
Commits
1
Pipelines
33
Changes
3
Merged
Jorn Hoofwijk
requested to merge
112-learnernd-add-iso-surface-plot-feature
into
master
6 years ago
Overview
16
Commits
1
Pipelines
33
Changes
3
Expand
Closes
#112 (closed)
Edited
6 years ago
by
Jorn Hoofwijk
2
0
Merge request reports
Compare
master
version 55
5708c4ca
6 years ago
version 54
143b29fd
6 years ago
version 53
72449d98
6 years ago
version 52
0547a7d9
6 years ago
version 51
0547a7d9
6 years ago
version 50
0547a7d9
6 years ago
version 49
0547a7d9
6 years ago
version 48
bcc4be84
6 years ago
version 47
bcc4be84
6 years ago
version 46
e13e1d52
6 years ago
version 45
190db37a
6 years ago
version 44
190db37a
6 years ago
version 43
e22f2dc2
6 years ago
version 42
c4deea80
6 years ago
version 41
2fdfaa58
6 years ago
version 40
6c22ce7e
6 years ago
version 39
82605cfe
6 years ago
version 38
82605cfe
6 years ago
version 37
82605cfe
6 years ago
version 36
82605cfe
6 years ago
version 35
82605cfe
6 years ago
version 34
82605cfe
6 years ago
version 33
82605cfe
6 years ago
version 32
f6f2ef27
6 years ago
version 31
1810e2bf
6 years ago
version 30
260df457
6 years ago
version 29
260df457
6 years ago
version 28
260df457
6 years ago
version 27
260df457
6 years ago
version 26
260df457
6 years ago
version 25
260df457
6 years ago
version 24
260df457
6 years ago
version 23
260df457
6 years ago
version 22
260df457
6 years ago
version 21
260df457
6 years ago
version 20
260df457
6 years ago
version 19
260df457
6 years ago
version 18
260df457
6 years ago
version 17
260df457
6 years ago
version 16
dff5c5d9
6 years ago
version 15
3f611327
6 years ago
version 14
f518d872
6 years ago
version 13
3e660922
6 years ago
version 12
9ed15f76
6 years ago
version 11
c1c1b872
6 years ago
version 10
9aaa6c38
6 years ago
version 9
354002ea
6 years ago
version 8
b38edef8
6 years ago
version 7
63175598
6 years ago
version 6
a2b5aca6
6 years ago
version 5
85243d94
6 years ago
version 4
b47cbb40
6 years ago
version 3
e52a6325
6 years ago
version 2
4761fd7e
6 years ago
version 1
46f2d8d4
6 years ago
master (base)
and
version 10
latest version
49ad3c6c
1 commit,
6 years ago
version 55
5708c4ca
1 commit,
6 years ago
version 54
143b29fd
1 commit,
6 years ago
version 53
72449d98
1 commit,
6 years ago
version 52
0547a7d9
1 commit,
6 years ago
version 51
0547a7d9
1 commit,
6 years ago
version 50
0547a7d9
1 commit,
6 years ago
version 49
0547a7d9
1 commit,
6 years ago
version 48
bcc4be84
5 commits,
6 years ago
version 47
bcc4be84
5 commits,
6 years ago
version 46
e13e1d52
2 commits,
6 years ago
version 45
190db37a
5 commits,
6 years ago
version 44
190db37a
2 commits,
6 years ago
version 43
e22f2dc2
2 commits,
6 years ago
version 42
c4deea80
2 commits,
6 years ago
version 41
2fdfaa58
1 commit,
6 years ago
version 40
6c22ce7e
1 commit,
6 years ago
version 39
82605cfe
7 commits,
6 years ago
version 38
82605cfe
7 commits,
6 years ago
version 37
82605cfe
7 commits,
6 years ago
version 36
82605cfe
7 commits,
6 years ago
version 35
82605cfe
7 commits,
6 years ago
version 34
82605cfe
7 commits,
6 years ago
version 33
82605cfe
6 commits,
6 years ago
version 32
f6f2ef27
5 commits,
6 years ago
version 31
1810e2bf
4 commits,
6 years ago
version 30
260df457
6 commits,
6 years ago
version 29
260df457
6 commits,
6 years ago
version 28
260df457
6 commits,
6 years ago
version 27
260df457
6 commits,
6 years ago
version 26
260df457
6 commits,
6 years ago
version 25
260df457
6 commits,
6 years ago
version 24
260df457
6 commits,
6 years ago
version 23
260df457
6 commits,
6 years ago
version 22
260df457
6 commits,
6 years ago
version 21
260df457
6 commits,
6 years ago
version 20
260df457
6 commits,
6 years ago
version 19
260df457
6 commits,
6 years ago
version 18
260df457
6 commits,
6 years ago
version 17
260df457
6 commits,
6 years ago
version 16
dff5c5d9
4 commits,
6 years ago
version 15
3f611327
3 commits,
6 years ago
version 14
f518d872
2 commits,
6 years ago
version 13
3e660922
2 commits,
6 years ago
version 12
9ed15f76
2 commits,
6 years ago
version 11
c1c1b872
2 commits,
6 years ago
version 10
9aaa6c38
1 commit,
6 years ago
version 9
354002ea
1 commit,
6 years ago
version 8
b38edef8
1 commit,
6 years ago
version 7
63175598
1 commit,
6 years ago
version 6
a2b5aca6
3 commits,
6 years ago
version 5
85243d94
2 commits,
6 years ago
version 4
b47cbb40
2 commits,
6 years ago
version 3
e52a6325
2 commits,
6 years ago
version 2
4761fd7e
1 commit,
6 years ago
version 1
46f2d8d4
1 commit,
6 years ago
3 files
+
140
−
2
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
3
Search (e.g. *.vue) (Ctrl+P)
adaptive/learner/learnerND.py
+
117
−
1
Options
@@ -10,7 +10,7 @@ import scipy.spatial
from
.base_learner
import
BaseLearner
from
..notebook_integration
import
ensure_holoviews
from
..notebook_integration
import
ensure_holoviews
,
ensure_plotly
from
.triangulation
import
(
Triangulation
,
point_in_simplex
,
circumsphere
,
simplex_volume_in_embedding
)
from
..utils
import
restore
,
cache_latest
@@ -576,3 +576,119 @@ class LearnerND(BaseLearner):
return
im
.
opts
(
style
=
dict
(
cmap
=
'
viridis
'
))
else
:
raise
ValueError
(
"
Only 1 or 2-dimensional plots can be generated.
"
)
def
_get_isosurface
(
self
,
level
=
0.0
):
if
self
.
ndim
!=
3
or
self
.
vdim
!=
1
:
raise
Exception
(
'
Isosurface plotting is only supported
'
'
for a 3D input and 1D output
'
)
vertices
=
[]
# index -> (x,y,z)
faces
=
[]
# tuple of indices of the corner points
from_line_to_vertex
=
{}
# the interpolated vertex (index) between two known points
def
_get_vertex_index
(
a
,
b
):
if
(
a
,
b
)
in
from_line_to_vertex
:
return
from_line_to_vertex
[(
a
,
b
)]
# Otherwise compute it and cache the result.
vertex_a
=
self
.
tri
.
vertices
[
a
]
vertex_b
=
self
.
tri
.
vertices
[
b
]
value_a
=
self
.
data
[
vertex_a
]
value_b
=
self
.
data
[
vertex_b
]
da
=
abs
(
value_a
-
level
)
db
=
abs
(
value_b
-
level
)
dab
=
da
+
db
new_pt
=
db
/
dab
*
np
.
array
(
vertex_a
)
+
da
/
dab
*
np
.
array
(
vertex_b
)
new_index
=
len
(
vertices
)
vertices
.
append
(
new_pt
)
from_line_to_vertex
[(
a
,
b
)]
=
new_index
return
new_index
for
simplex
in
self
.
tri
.
simplices
:
plane
=
[]
for
a
,
b
in
itertools
.
combinations
(
simplex
,
2
):
va
=
self
.
data
[
self
.
tri
.
vertices
[
a
]]
vb
=
self
.
data
[
self
.
tri
.
vertices
[
b
]]
if
min
(
va
,
vb
)
<
level
<=
max
(
va
,
vb
):
vi
=
_get_vertex_index
(
a
,
b
)
should_add
=
True
for
pi
in
plane
:
if
np
.
allclose
(
vertices
[
vi
],
vertices
[
pi
]):
should_add
=
False
if
should_add
:
plane
.
append
(
vi
)
if
len
(
plane
)
==
3
:
faces
.
append
(
plane
)
elif
len
(
plane
)
==
4
:
faces
.
append
(
plane
[:
3
])
faces
.
append
(
plane
[
1
:])
if
len
(
faces
)
==
0
:
r_min
=
min
(
self
.
data
[
v
]
for
v
in
self
.
tri
.
vertices
)
r_max
=
max
(
self
.
data
[
v
]
for
v
in
self
.
tri
.
vertices
)
raise
ValueError
(
f
"
Could not draw isosurface for level=
{
level
}
, as
"
"
this value is not inside the function range. Please choose a level
"
f
"
strictly inside interval (
{
r_min
}
,
{
r_max
}
)
"
)
return
vertices
,
faces
def
plot_isosurface
(
self
,
level
=
0.0
,
hull_opacity
=
0.2
):
"""
Plots the linearly interpolated iso-surface of the function, based on
the currently evaluated points. This is the 3d analog of an iso-line.
Parameters
----------
level : float
the function value which you are interested in. Defaults to 0.0.
hull_opacity : float
the opacity of the hull of the domain. Defaults to 0.2
"""
plotly
=
ensure_plotly
()
vertices
,
faces
=
self
.
_get_isosurface
(
level
)
x
,
y
,
z
=
zip
(
*
vertices
)
fig
=
plotly
.
figure_factory
.
create_trisurf
(
x
=
x
,
y
=
y
,
z
=
z
,
plot_edges
=
False
,
simplices
=
faces
,
title
=
"
Isosurface
"
)
if
hull_opacity
<
1e-3
:
# Do not compute the hull_mesh.
return
plotly
.
offline
.
iplot
(
fig
)
hull_mesh
=
self
.
_get_hull_mesh
(
opacity
=
hull_opacity
)
return
plotly
.
offline
.
iplot
([
fig
.
data
[
0
],
hull_mesh
])
def
_get_hull_mesh
(
self
,
opacity
=
0.2
):
plotly
=
ensure_plotly
()
hull
=
scipy
.
spatial
.
ConvexHull
(
self
.
_bounds_points
)
# Find the colors of each plane, giving triangles which are coplanar the
# same color, such that a square face has the same color.
color_dict
=
{}
def
_get_plane_color
(
simplex
):
simplex
=
tuple
(
simplex
)
# If the volume of the two triangles combined is zero then they
# belong to the same plane.
for
simplex_key
,
color
in
color_dict
.
items
():
points
=
np
.
array
([
hull
.
points
[
i
]
for
i
in
set
(
simplex_key
+
simplex
)])
if
np
.
linalg
.
matrix_rank
(
points
[
1
:]
-
points
[
0
])
<
3
:
return
color
if
scipy
.
spatial
.
ConvexHull
(
points
).
volume
<
1e-5
:
return
color
color_dict
[
simplex
]
=
tuple
(
random
.
randint
(
0
,
255
)
for
_
in
range
(
3
))
return
color_dict
[
simplex
]
colors
=
[
_get_plane_color
(
simplex
)
for
simplex
in
hull
.
simplices
]
x
,
y
,
z
=
zip
(
*
self
.
_bounds_points
)
i
,
j
,
k
=
hull
.
simplices
.
T
return
plotly
.
graph_objs
.
Mesh3d
(
x
=
x
,
y
=
y
,
z
=
z
,
i
=
i
,
j
=
j
,
k
=
k
,
facecolor
=
colors
,
opacity
=
opacity
)
Loading