Exemplo n.º 1
0
def test_stat_point_minimisation():
    # Test that the minimisation works for very shallow minima

    energies_list = [
        np.array([0.0, 3.8, -9.1, -1.6, 0.3]),
        np.array([0.0, 10, -20, 10, -5])
    ]

    for energies in energies_list:

        result = minimize(plotting.error_on_stationary_points,
                          x0=energies,
                          args=(energies, ),
                          method='BFGS',
                          tol=0.1)

        assert result.success

        spline = interpolate.CubicSpline([0, 1, 2, 3, 4],
                                         result.x,
                                         bc_type='clamped')
        fine_zi_s = np.linspace(-0.2, 5.2, num=500)
        stationary_points = plotting.get_stationary_points(
            xs=fine_zi_s, dydx=spline.derivative())
        assert len(stationary_points) == 5
Exemplo n.º 2
0
def test_stat_points():

    # y = (x-2)^2  has a stationary point at x = 2

    stationary_points = plotting.get_stationary_points(xs=np.linspace(-1, 3, 100),
                                                       dydx=lambda x: 2*(x-2))

    assert len(stationary_points) == 1
    assert 1.9 < stationary_points[0] < 2.1