-
Notifications
You must be signed in to change notification settings - Fork 62
Wrong sign for right boundary with Sympy #338
Copy link
Copy link
Closed
Labels
Description
Let's consider the following simple example. First, I'm going to show the correct result when using Numpy:
import numpy as np
from adaptive import notebook_extension, Learner1D
from adaptive.runner import simple
import dill
notebook_extension()
def func(x):
return np.imag(np.sqrt(-(x + 0j)))
def goal(learner):
return learner.loss() < 0.1
learner = Learner1D(func, bounds=(-1, 1))
simple(learner, goal)
learner.plot()Now, I'm going to use Sympy to generate a function which is going to be evaluated with Numpy:
from sympy import *
var("x")
f = im(sqrt(-x))
# func is going to use Numpy
func = lambdify(x, f)
def goal(learner):
return learner.loss() < 0.1
learner = Learner1D(func, bounds=(-1, 1))
learner_bytes = dill.dumps(learner)
learner_loaded = dill.loads(learner_bytes)
simple(learner_loaded, goal)
learner_loaded.plot()As you can see, the last evaluation point (the right boundary) has the wrong sign. Even if I change the boundaries, the last point will always have the wrong sign. Why does it happen? Is it something that I can fix with some option in the learner/runner or is it an internal bug?
Reactions are currently unavailable

