Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def split(self):
points = self.points()
m = points[len(points) // 2]
ivals = [
_Interval(self.a, m, 0, self.rdepth + 1),
_Interval(m, self.b, 0, self.rdepth + 1),
]
self.children = ivals
for ival in ivals:
ival.parent = self
ival.ndiv = self.ndiv
ival.err = self.err / 2
return ivals
def split(self):
points = self.points()
m = points[len(points) // 2]
ivals = [_Interval(self.a, m, 0, self.rdepth + 1),
_Interval(m, self.b, 0, self.rdepth + 1)]
self.children = ivals
for ival in ivals:
ival.parent = self
ival.ndiv = self.ndiv
ival.err = self.err / 2
return ivals
def split(self):
points = self.points()
m = points[len(points) // 2]
ivals = [_Interval(self.a, m, 0, self.rdepth + 1),
_Interval(m, self.b, 0, self.rdepth + 1)]
self.children = ivals
for ival in ivals:
ival.parent = self
ival.ndiv = self.ndiv
ival.err = self.err / 2
return ivals
def split(self):
points = self.points()
m = points[len(points) // 2]
ivals = [
_Interval(self.a, m, 0, self.rdepth + 1),
_Interval(m, self.b, 0, self.rdepth + 1),
]
self.children = ivals
for ival in ivals:
ival.parent = self
ival.ndiv = self.ndiv
ival.err = self.err / 2
return ivals
def same_ivals_up_to(f, a, b, tol):
igral, err, nr_points, ivals = algorithm_4(f, a, b, tol)
learner = IntegratorLearner(f, bounds=(a, b), tol=tol)
j = 0
equal_till = 0
for i in range(nr_points):
points, loss_improvement = learner.choose_points(1)
learner.add_data(points, map(learner.function, points))
if not learner._stack:
try:
j += 1
if learner.equal(ivals):
equal_till = i + 1
except:
all_equal = False
return 'equal_till nr_points={} of {}'.format(equal_till, nr_points)
def same_ivals(f, a, b, tol, verbose):
igral, err, nr_points, ivals = algorithm_4(f, a, b, tol)
learner = IntegratorLearner(f, bounds=(a, b), tol=tol)
for i in range(nr_points):
points, loss_improvement = learner.choose_points(1)
learner.add_data(points, map(learner.function, points))
if verbose:
print('igral diff, ', learner.igral-igral, 'err diff', learner.err - err)
return learner.equal(ivals, verbose=verbose)
print('\nFunction {}'.format(i))
if same_ivals(*args, verbose=True):
print(True)
else:
print(same_ivals_up_to(*args))
# This function should raise a DivergentIntegralError.
print('Function ', i+1)
f, a, b, tol = [fdiv, 0, 1, 1e-6]
try:
igral, err, nr_points, ivals = algorithm_4(f, a, b, tol)
except Exception:
print('The integral is diverging.')
try:
learner = IntegratorLearner(f, bounds=(a, b), tol=tol)
for i in range(nr_points):
points, loss_improvement = learner.choose_points(1)
learner.add_data(points, map(learner.function, points))
except Exception:
print('The integral is diverging.')
np.seterr(**old_settings)
def _plot_1d(self):
assert isinstance(self.domain, Interval)
hv = ensure_holoviews()
xs, ys = zip(*sorted(self.data.items())) if self.data else ([], [])
if self.vdim == 1:
p = hv.Path([]) * hv.Scatter((xs, ys))
else:
p = hv.Path((xs, ys)) * hv.Scatter([])
# Plot with 5% empty margins such that the boundary points are visible
a, b = self.domain.bounds
margin = 0.05 * (b - a)
plot_bounds = (a - margin, b + margin)
return p.redim(x=dict(range=plot_bounds))
def _plot_nd(self, n=None, tri_alpha=0):
# XXX: Copied from LearnerND. At the moment we reach deep into internal
# datastructures of self.domain. We should see what data we need and
# add APIs to 'Domain' to support this.
hv = ensure_holoviews()
if self.vdim > 1:
raise NotImplementedError(
"holoviews currently does not support", "3D surface plots in bokeh."
)
if self.ndim != 2:
raise NotImplementedError(
"Only 2D plots are implemented: You can "
"plot a 2D slice with 'plot_slice'."
)
x, y = self.domain.bounding_box
lbrt = x[0], y[0], x[1], y[1]
if len(self.data) >= 4:
if n is None:
# Calculate how many grid points are needed.
# factor from A=√3/4 * a² (equilateral triangle)
The value of the function at which you would like to see
the isoline.
n : int
The number of boxes in the interpolation grid along each axis.
This is passed to `plot`.
tri_alpha : float
The opacity of the overlaying triangulation. This is passed
to `plot`.
Returns
-------
`holoviews.core.Overlay`
The plot of the isoline(s). This overlays a `plot` with a
`holoviews.element.Path`.
"""
hv = ensure_holoviews()
if n == -1:
plot = hv.Path([])
else:
plot = self.plot(n=n, tri_alpha=tri_alpha)
if isinstance(level, Iterable):
for l in level:
plot = plot * self.plot_isoline(level=l, n=-1)
return plot
vertices, lines = self._get_iso(level, which="line")
paths = [[vertices[i], vertices[j]] for i, j in lines]
contour = hv.Path(paths)
contour_opts = dict(color="black")
contour = contour.opts(style=contour_opts)