How to use the adaptive.learner.IntegratorLearner function in adaptive

To help you get started, we’ve selected a few adaptive examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github python-adaptive / adaptive / test_cquad.py View on Github external
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)
github python-adaptive / adaptive / test_cquad.py View on Github external
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)
github python-adaptive / adaptive / test_cquad.py View on Github external
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)