def test_default_generator(): step_gen = nd.MaxStepGenerator(num_steps=10) h = np.array([h for h in step_gen(0)]) desired = 2.0 * 2.0**(-np.arange(10) + 0) assert_array_almost_equal((h - desired) / desired, 0)
def test_max_step_generator_with_base_step01(): desired = 0.1 step_gen = nd.MaxStepGenerator(base_step=desired, num_steps=1, offset=0) methods = ['forward', 'backward', 'central', 'complex'] lengths = [2, 2, 1, 1] for n, method in zip(lengths, methods): h = [h for h in step_gen(0, method=method)] assert_array_almost_equal((h[0] - desired) / desired, 0) assert_equal(n, len(h))
def test_run_hamiltonian(self): # Important to restrict the step in order to avoid the # discontinutiy at x=[0,0] of the hamiltonian for method in ['central', 'complex']: step = nd.MaxStepGenerator(base_step=1e-4) hessian = nd.Hessian(None, step=step, method=method) h, _error_estimate, true_h = run_hamiltonian(hessian, verbose=False) assert (np.abs((h - true_h) / true_h) < 1e-4).all()
def test_default_base_step(): step_gen = nd.MaxStepGenerator(num_steps=1, offset=0) h = [h for h in step_gen(0)] desired = 2.0 assert_array_almost_equal((h[0] - desired) / desired, 0)