當前位置: 首頁>>代碼示例>>Python>>正文


Python testing.assert_array_less方法代碼示例

本文整理匯總了Python中numpy.testing.assert_array_less方法的典型用法代碼示例。如果您正苦於以下問題:Python testing.assert_array_less方法的具體用法?Python testing.assert_array_less怎麽用?Python testing.assert_array_less使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在numpy.testing的用法示例。


在下文中一共展示了testing.assert_array_less方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_matching_function

# 需要導入模塊: from numpy import testing [as 別名]
# 或者: from numpy.testing import assert_array_less [as 別名]
def test_matching_function():
    from astropy.coordinates import ICRS
    from astropy.coordinates.matching import match_coordinates_3d
    # this only uses match_coordinates_3d because that's the actual implementation

    cmatch = ICRS([4, 2.1]*u.degree, [0, 0]*u.degree)
    ccatalog = ICRS([1, 2, 3, 4]*u.degree, [0, 0, 0, 0]*u.degree)

    idx, d2d, d3d = match_coordinates_3d(cmatch, ccatalog)
    npt.assert_array_equal(idx, [3, 1])
    npt.assert_array_almost_equal(d2d.degree, [0, 0.1])
    assert d3d.value[0] == 0

    idx, d2d, d3d = match_coordinates_3d(cmatch, ccatalog, nthneighbor=2)
    assert np.all(idx == 2)
    npt.assert_array_almost_equal(d2d.degree, [1, 0.9])
    npt.assert_array_less(d3d.value, 0.02) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:19,代碼來源:test_matching.py

示例2: test_sample_diag_gaussian

# 需要導入模塊: from numpy import testing [as 別名]
# 或者: from numpy.testing import assert_array_less [as 別名]
def test_sample_diag_gaussian():
    """ Test sampling from a multivariate gaussian distribution with a diagonal covariance matrix """
    head = DiagGaussianActionHead(1, 5)

    array = np.zeros((10000, 5, 2))

    sample = head.sample(torch.from_numpy(array))

    result_array = sample.detach().cpu().numpy()

    nt.assert_array_less(np.abs(result_array.mean(axis=0)), 0.1)
    nt.assert_array_less(result_array.std(axis=0), 1.1)
    nt.assert_array_less(0.9, result_array.std(axis=0))

    array2 = np.zeros((10000, 5, 2))
    array2[:, 0, 0] = 5.0
    array2[:, 0, 1] = np.log(10)

    sample2 = head.sample(torch.from_numpy(array2))

    result_array2 = sample2.detach().cpu().numpy()
    nt.assert_array_less(result_array2.mean(axis=0), np.array([5.3, 0.1, 0.1, 0.1, 0.1]))
    nt.assert_array_less(np.array([4.7, -0.1, -0.1, -0.1, -0.1]), result_array2.mean(axis=0)) 
開發者ID:MillionIntegrals,項目名稱:vel,代碼行數:25,代碼來源:test_action_head.py

示例3: test_sample_categorical

# 需要導入模塊: from numpy import testing [as 別名]
# 或者: from numpy.testing import assert_array_less [as 別名]
def test_sample_categorical():
    """
    Test sampling from a categorical distribution
    """
    head = CategoricalActionHead(1, 5)

    array = np.zeros((10000, 5))

    sample = head.sample(torch.from_numpy(array))

    result_array = sample.detach().cpu().numpy()

    nt.assert_array_less(np.abs(result_array.mean(axis=0)), 2.1)
    nt.assert_array_less(1.9, np.abs(result_array.mean(axis=0)))

    array2 = np.zeros((10000, 5))
    array2[:, 0:4] = -10.0
    array2[:, 4] = 10.0

    sample2 = head.sample(F.log_softmax(torch.from_numpy(array2), dim=1))
    result_array2 = sample2.detach().cpu().numpy()

    nt.assert_array_less(np.abs(result_array2.mean(axis=0)), 4.1)
    nt.assert_array_less(3.9, np.abs(result_array2.mean(axis=0))) 
開發者ID:MillionIntegrals,項目名稱:vel,代碼行數:26,代碼來源:test_action_head.py

示例4: assert_maxabs

# 需要導入模塊: from numpy import testing [as 別名]
# 或者: from numpy.testing import assert_array_less [as 別名]
def assert_maxabs(actual, expected, value):
    npt.assert_array_less(em.maxabs(actual, expected, None), value) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:4,代碼來源:test_random_panel.py

示例5: check_minimizer_bounds

# 需要導入模塊: from numpy import testing [as 別名]
# 或者: from numpy.testing import assert_array_less [as 別名]
def check_minimizer_bounds(result, n_calls):
    # no values should be below or above the bounds
    eps = 10e-9  # check for assert_array_less OR equal
    assert_array_less(result.x_iters, np.tile([10+eps, 15+eps], (n_calls, 1)))
    assert_array_less(np.tile([-5-eps, 0-eps], (n_calls, 1)), result.x_iters) 
開發者ID:scikit-optimize,項目名稱:scikit-optimize,代碼行數:7,代碼來源:test_common.py

示例6: test_estimate_theta_E

# 需要導入模塊: from numpy import testing [as 別名]
# 或者: from numpy.testing import assert_array_less [as 別名]
def test_estimate_theta_E():

    x = np.array([-0.45328229, 0.57461556, 0.53757501, -0.42312438])
    y = np.array([0.69582971, -0.51226356, 0.37577509, -0.40245467])

    approx = util.approx_theta_E(x, y)
    npt.assert_array_less(approx - 1, 0.2) 
開發者ID:sibirrer,項目名稱:lenstronomy,代碼行數:9,代碼來源:test_util.py

示例7: test_regularized_nonlinear

# 需要導入模塊: from numpy import testing [as 別名]
# 或者: from numpy.testing import assert_array_less [as 別名]
def test_regularized_nonlinear(self):
        """
        Test gradient descent solver with regularized non-linear acceleration,
        solving problems with L2-norm functions.

        """
        dim = 25
        np.random.seed(0)
        x0 = np.random.rand(dim)
        xstar = np.random.rand(dim)
        x0 = xstar + 5. * (x0 - xstar) / np.linalg.norm(x0 - xstar)

        A = np.random.rand(dim, dim)
        step = 1 / np.linalg.norm(np.dot(A.T, A))

        accel = acceleration.regularized_nonlinear(k=5)
        solver = solvers.gradient_descent(step=step, accel=accel)
        param = {'solver': solver, 'rtol': 0,
                 'maxit': 200, 'verbosity': 'NONE'}

        # L2-norm prox and dummy gradient.
        f1 = functions.norm_l2(lambda_=0.5, A=A, y=np.dot(A, xstar))
        f2 = functions.dummy()
        ret = solvers.solve([f1, f2], x0, **param)
        pctdiff = 100 * np.sum((xstar - ret['sol'])**2) / np.sum(xstar**2)
        nptest.assert_array_less(pctdiff, 1.91)

        # Sanity checks
        accel = acceleration.regularized_nonlinear()
        self.assertRaises(ValueError, accel.__init__, 10, ['not', 'good'])
        self.assertRaises(ValueError, accel.__init__, 10, 'nope') 
開發者ID:epfl-lts2,項目名稱:pyunlocbox,代碼行數:33,代碼來源:test_acceleration.py

示例8: test_g_z_relative_error

# 需要導入模塊: from numpy import testing [as 別名]
# 或者: from numpy.testing import assert_array_less [as 別名]
def test_g_z_relative_error():
    """
    Test the relative error in computing the g_z component
    """
    # Define a single point mass
    point_mass = (1, -67, -300.7)
    mass = 250
    coordinates_p = (0, -39, -13)
    # Compute the z component
    exact_deriv = point_mass_gravity(
        coordinates_p, point_mass, mass, "g_z", "cartesian"
    )
    # Compute the numerical derivative of potential
    delta = 0.1
    easting = np.zeros(2) + coordinates_p[0]
    northing = np.zeros(2) + coordinates_p[1]
    upward = np.array([coordinates_p[2] - delta, coordinates_p[2] + delta])
    coordinates = (easting, northing, upward)
    potential = point_mass_gravity(
        coordinates, point_mass, mass, "potential", "cartesian"
    )
    # Remember that the ``g_z`` field returns the downward component of the
    # gravitational acceleration. As a consequence, the numerical
    # derivativative is multiplied by -1.
    approximated_deriv = -1e5 * (potential[1] - potential[0]) / (2.0 * delta)

    # Compute the relative error
    relative_error = np.abs((approximated_deriv - exact_deriv) / exact_deriv)

    # Bound value
    distance = distance_cartesian(coordinates_p, point_mass)
    bound_value = 1.5 * (delta / distance) ** 2

    # Compare the results
    npt.assert_array_less(relative_error, bound_value) 
開發者ID:fatiando,項目名稱:harmonica,代碼行數:37,代碼來源:test_point_mass.py

示例9: test_g_northing_relative_error

# 需要導入模塊: from numpy import testing [as 別名]
# 或者: from numpy.testing import assert_array_less [as 別名]
def test_g_northing_relative_error():
    """
    Test the relative error in computing the g_northing component
    """
    # Define a single point mass
    point_mass = (1, -67, -300.7)
    mass = 250
    coordinates_p = (0, -39, -13)
    # Compute the northing component
    exact_deriv = point_mass_gravity(
        coordinates_p, point_mass, mass, "g_northing", "cartesian"
    )
    # Compute the numerical derivative of potential
    delta = 0.1
    easting = np.zeros(2) + coordinates_p[0]
    northing = np.array([coordinates_p[1] - delta, coordinates_p[1] + delta])
    upward = np.zeros(2) + coordinates_p[2]
    coordinates = (easting, northing, upward)
    potential = point_mass_gravity(
        coordinates, point_mass, mass, "potential", "cartesian"
    )
    approximated_deriv = 1e5 * (potential[1] - potential[0]) / (2.0 * delta)

    # Compute the relative error
    relative_error = np.abs((approximated_deriv - exact_deriv) / exact_deriv)

    # Bound value
    distance = distance_cartesian(coordinates_p, point_mass)
    bound_value = 1.5 * (delta / distance) ** 2

    # Compare the results
    npt.assert_array_less(relative_error, bound_value) 
開發者ID:fatiando,項目名稱:harmonica,代碼行數:34,代碼來源:test_point_mass.py

示例10: test_g_easting_relative_error

# 需要導入模塊: from numpy import testing [as 別名]
# 或者: from numpy.testing import assert_array_less [as 別名]
def test_g_easting_relative_error():
    """
    Test the relative error in computing the g_easting component
    """
    # Define a single point mass
    point_mass = (20, 54, -500.7)
    mass = 200
    coordinates_p = (-3, 24, -10)
    # Compute the easting component
    exact_deriv = point_mass_gravity(
        coordinates_p, point_mass, mass, "g_easting", "cartesian"
    )
    # Compute the numerical derivative of potential
    delta = 0.1
    easting = np.array([coordinates_p[0] - delta, coordinates_p[0] + delta])
    northing = np.zeros(2) + coordinates_p[1]
    upward = np.zeros(2) + coordinates_p[2]
    coordinates = (easting, northing, upward)
    potential = point_mass_gravity(
        coordinates, point_mass, mass, "potential", "cartesian"
    )
    approximated_deriv = 1e5 * (potential[1] - potential[0]) / (2.0 * delta)

    # Compute the relative error
    relative_error = np.abs((approximated_deriv - exact_deriv) / exact_deriv)

    # Bound value
    distance = distance_cartesian(coordinates_p, point_mass)
    bound_value = 1.5 * (delta / distance) ** 2

    # Compare the results
    npt.assert_array_less(relative_error, bound_value) 
開發者ID:fatiando,項目名稱:harmonica,代碼行數:34,代碼來源:test_point_mass.py

示例11: test_array_precession

# 需要導入模塊: from numpy import testing [as 別名]
# 或者: from numpy.testing import assert_array_less [as 別名]
def test_array_precession():
    """
    Ensures that FK5 coordinates as arrays precess their equinoxes
    """
    j2000 = Time('J2000')
    j1975 = Time('J1975')

    fk5 = FK5([1, 1.1]*u.radian, [0.5, 0.6]*u.radian)
    assert fk5.equinox.jyear == j2000.jyear
    fk5_2 = fk5.transform_to(FK5(equinox=j1975))
    assert fk5_2.equinox.jyear == j1975.jyear

    npt.assert_array_less(0.05, np.abs(fk5.ra.degree - fk5_2.ra.degree))
    npt.assert_array_less(0.05, np.abs(fk5.dec.degree - fk5_2.dec.degree)) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:16,代碼來源:test_arrays.py

示例12: setUpClass

# 需要導入模塊: from numpy import testing [as 別名]
# 或者: from numpy.testing import assert_array_less [as 別名]
def setUpClass(cls):
        cls.cell = cell = Cell()
        # Lift some degeneracies
        cell.atom = '''
        C 0.000000000000   0.000000000000   0.000000000000
        C 1.67   1.68   1.69
        '''
        cell.basis = {'C': [[0, (0.8, 1.0)],
                            [1, (1.0, 1.0)]]}
        # cell.basis = 'gth-dzvp'
        cell.pseudo = 'gth-pade'
        cell.a = '''
        0.000000000, 3.370137329, 3.370137329
        3.370137329, 0.000000000, 3.370137329
        3.370137329, 3.370137329, 0.000000000'''
        cell.unit = 'B'
        cell.verbose = 5
        cell.build()

        k = cell.make_kpts([cls.k, 1, 1], scaled_center=cls.k_c)

        # K-points
        cls.model_krhf = model_krhf = KRHF(cell, k).density_fit()
        model_krhf.conv_tol = 1e-14
        model_krhf.kernel()

        ke = numpy.concatenate(model_krhf.mo_energy)
        ke.sort()

        # Make sure no degeneracies are present
        testing.assert_array_less(1e-4, ke[1:] - ke[:-1])

        # TD
        cls.td_model_srhf = td_model_srhf = std.TDRHF(model_krhf)
        td_model_srhf.kernel()

        cls.td_model_krhf = td_model_krhf = ktd.TDRHF(model_krhf)
        td_model_krhf.kernel()

        # adjust_td_phase(td_model_srhf, td_model_krhf)

        # GW
        cls.gw = sgw.GW(td_model_srhf)
        cls.kgw = kgw.GW(td_model_krhf) 
開發者ID:pyscf,項目名稱:pyscf,代碼行數:46,代碼來源:test_kgw_slow.py

示例13: setUpClass

# 需要導入模塊: from numpy import testing [as 別名]
# 或者: from numpy.testing import assert_array_less [as 別名]
def setUpClass(cls):
        cls.cell = cell = Cell()
        # Lift some degeneracies
        cell.atom = '''
        C 0.000000000000   0.000000000000   0.000000000000
        C 1.67   1.68   1.69
        '''
        cell.basis = {'C': [[0, (0.8, 1.0)],
                            [1, (1.0, 1.0)]]}
        # cell.basis = 'gth-dzvp'
        cell.pseudo = 'gth-pade'
        cell.a = '''
        0.000000000, 3.370137329, 3.370137329
        3.370137329, 0.000000000, 3.370137329
        3.370137329, 3.370137329, 0.000000000'''
        cell.unit = 'B'
        cell.verbose = 5
        cell.build()

        k = cell.make_kpts([cls.k, 1, 1], scaled_center=cls.k_c)

        # The Gamma-point reference
        cls.model_rhf = model_rhf = RHF(super_cell(cell, [cls.k, 1, 1]), kpt=k[0]).density_fit()
        model_rhf.conv_tol = 1e-14
        model_rhf.kernel()

        # K-points
        cls.model_krhf = model_krhf = KRHF(cell, k).density_fit()
        model_krhf.conv_tol = 1e-14
        model_krhf.kernel()

        adjust_mf_phase(model_rhf, model_krhf)

        ke = numpy.concatenate(model_krhf.mo_energy)
        ke.sort()

        # Make sure mo energies are the same
        testing.assert_allclose(model_rhf.mo_energy, ke)

        # Make sure no degeneracies are present
        testing.assert_array_less(1e-4, ke[1:] - ke[:-1])

        cls.ov_order = ov_order(model_krhf)

        # The Gamma-point TD
        cls.td_model_rhf = td_model_rhf = td.TDRHF(model_rhf)
        td_model_rhf.kernel()
        cls.ref_m = td_model_rhf.eri.tdhf_full_form() 
開發者ID:pyscf,項目名稱:pyscf,代碼行數:50,代碼來源:test_krhf_slow_supercell.py


注:本文中的numpy.testing.assert_array_less方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。