Skip to content

Commit 1e2713e

Browse files
jhoofwijkbasnijholt
authored andcommitted
add an example of using a ConvexHull to the tutorial
1 parent 0e15482 commit 1e2713e

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

docs/source/tutorial/tutorial.LearnerND.rst

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,37 @@ is a result of the fact that the learner chooses points in 3 dimensions
9090
and the simplices are not in the same face as we try to interpolate our
9191
lines. However, as always, when you sample more points the graph will
9292
become gradually smoother.
93+
94+
Using any convex shape as domain
95+
--------------------------------
96+
97+
Suppose you do not simply want to sample your function on a square (in 2D) or in
98+
a cube (in 3D). The LearnerND supports using a `scipy.spatial.ConvexHull` as
99+
your domain. This is best illustrated in the following example.
100+
101+
Suppose you would like to sample you function in a cube split in half diagonally.
102+
You could use the following code as an example:
103+
104+
.. jupyter-execute::
105+
106+
import scipy
107+
108+
def f(xyz):
109+
x, y, z = xyz
110+
return x**4 + y**4 + z**4 - (x**2+y**2+z**2)**2
111+
112+
# set the bound points, you can change this to be any shape
113+
b = [(-1, -1, -1),
114+
(-1, 1, -1),
115+
(-1, -1, 1),
116+
(-1, 1, 1),
117+
( 1, 1, -1),
118+
( 1, -1, -1)]
119+
120+
# you have to convert the points into a scipy.spatial.ConvexHull
121+
hull = scipy.spatial.ConvexHull(b)
122+
123+
learner = adaptive.LearnerND(f, hull)
124+
adaptive.BlockingRunner(learner, goal=lambda l: l.npoints > 2000)
125+
126+
learner.plot_isosurface(-0.5)

0 commit comments

Comments
 (0)