Here are the examples of the python api numpy.testing.assert_array_almost_equal taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
174 Examples
5
Example 1
def test_array_conversion(self):
"""
ArrayQuantity: test that the value and uncertainty get converted to the proper si value.
"""
numpy.testing.assert_array_almost_equal(self.v.value_si, self.v.value*1e-2)
numpy.testing.assert_array_almost_equal(self.v.uncertainty_si, self.v.uncertainty)
numpy.testing.assert_array_almost_equal(self.v_array.value_si, self.v.value*1e-2)
numpy.testing.assert_array_almost_equal(self.v_array.uncertainty_si, self.v.uncertainty)
numpy.testing.assert_array_almost_equal(self.Cp.value_si, self.Cp.value*4.184)
numpy.testing.assert_array_almost_equal(self.Cp.uncertainty_si, self.Cp.uncertainty*4.184)
numpy.testing.assert_array_almost_equal(self.Cp_array.value_si, self.Cp.value*4.184)
numpy.testing.assert_array_almost_equal(self.Cp_array.uncertainty_si, self.Cp.uncertainty*4.184)
5
Example 2
Project: oq-hazardlib Source File: gc2_test.py
def test_downsample_mesh(self):
# Use the simple fault case with a tolerance of 1.0 degree
numpy.testing.assert_array_almost_equal(
downsample_mesh(SFLT1.mesh, 1.0).lons[0, :],
AS_ARRAY[:, 0],
5)
numpy.testing.assert_array_almost_equal(
downsample_mesh(SFLT1.mesh, 1.0).lats[0, :],
AS_ARRAY[:, 1],
5)
numpy.testing.assert_array_almost_equal(
downsample_mesh(SFLT1.mesh, 1.0).depths[0, :],
AS_ARRAY[:, 2],
5)
5
Example 3
Project: oq-hazardlib Source File: gc2_test.py
def test_downsample_trace(self):
# Use the simple fault case with a tolerance of 1.0 degree
downsampled_trace = downsample_trace(SFLT1.mesh, 1.0)
# Top edge of downsampled mesh should correspond to the five
# points of the simple fault
# Check longitudes
numpy.testing.assert_array_almost_equal(downsampled_trace[:, 0],
AS_ARRAY[:, 0],
5)
# Check latitude
numpy.testing.assert_array_almost_equal(downsampled_trace[:, 1],
AS_ARRAY[:, 1],
5)
# Check depths
numpy.testing.assert_array_almost_equal(downsampled_trace[:, 2],
AS_ARRAY[:, 2],
5)
3
Example 4
Project: lifelines Source File: test_estimation.py
def test_penalized_output_against_R(self, rossi):
# R code:
#
# rossi <- read.csv('.../lifelines/datasets/rossi.csv')
# mod.allison <- coxph(Surv(week, arrest) ~ ridge(fin, age, race, wexp, mar, paro, prio,
# theta=1.0, scale=FALSE), data=rossi)
# cat(round(mod.allison$coefficients, 4), sep=", ")
expected = np.array([[-0.3641, -0.0580, 0.2894, -0.1496, -0.3837, -0.0822, 0.0913]])
cf = CoxPHFitter(normalize=False, penalizer=1.0)
cf.fit(rossi, duration_col='week', event_col='arrest')
npt.assert_array_almost_equal(cf.hazards_.values, expected, decimal=3)
3
Example 5
Project: tifffile Source File: test_tifffile.py
@skipif(si is None)
def test_imread_uint16_big_endian():
expected = np.load(os.path.join(si.data_dir, 'chessboard_GRAY_U8.npy'))
img = imread(os.path.join(si.data_dir, 'chessboard_GRAY_U16B.tif'))
assert img.dtype == np.uint16
assert_array_almost_equal(img, expected)
3
Example 6
Project: cartopy Source File: test_lambert_conformal.py
def test_single_spole(self):
s_pole_crs = ccrs.LambertConformal(standard_parallels=[-1.])
assert_array_almost_equal(s_pole_crs.x_limits,
(-19840440, 19840440.),
decimal=0)
assert_array_almost_equal(s_pole_crs.y_limits,
(-370239953, -8191953),
decimal=0)
3
Example 7
Project: qutip Source File: test_mkl.py
@unittest.skipIf(qset.has_mkl == False, 'MKL extensions not found.')
def test_mkl_spsolve1():
"""
MKL spsolve : Single RHS vector (Real)
"""
Adense = np.array([[0., 1., 1.],
[1., 0., 1.],
[0., 0., 1.]])
As = sp.csr_matrix(Adense)
np.random.seed(1234)
x = np.random.randn(3)
b = As * x
x2 = mkl_spsolve(As, b)
assert_array_almost_equal(x, x2)
3
Example 8
Project: pymbar Source File: utils_for_testing.py
def assert_sparse_matrix_equal(m1, m2, decimal=6):
"""Assert two scipy.sparse matrices are equal."""
# both are sparse matricies
assert isspmatrix(m1)
assert isspmatrix(m1)
# make sure they have the same format
eq_(m1.format, m2.format)
# even though its called assert_array_almost_equal, it will
# work for scalars
assert_array_almost_equal((m1 - m2).sum(), 0, decimal=decimal)
3
Example 9
Project: pyvolve Source File: parameters_sanity_test.py
def test_sanity_state_freqs_MG_provided_codon(self):
mg_nuc = [ 0.23577944, 0.2426595, 0.28132983, 0.24023122]
mg_codon = [6.48685834e-03, 2.56846182e-02, 3.62821504e-02, 1.78992022e-02, 3.78995203e-03, 1.27376858e-02, 1.11733512e-02, 2.77350952e-03, 3.21357920e-02, 1.15713167e-02, 1.35629025e-03, 2.18752127e-02, 2.50168300e-05, 3.10876439e-02, 3.37328837e-02, 1.65327942e-02, 8.21428969e-03, 1.55572812e-02, 1.76293820e-02, 2.29747386e-02, 1.73289159e-03, 1.13379531e-02, 1.59673812e-02, 2.97921605e-02, 3.52280293e-02, 9.42724910e-03, 2.48052302e-02, 1.47583962e-02, 1.96410901e-02, 9.33795423e-03, 6.06200346e-05, 1.11892264e-02, 1.18844724e-02, 1.75173640e-02, 2.77504624e-02, 1.90563757e-02, 3.16335607e-02, 1.45931598e-02, 1.42666011e-02, 2.96971714e-02, 1.90421569e-02, 3.33563400e-03, 2.94568624e-03, 3.40917454e-02, 1.32157035e-02, 1.94067362e-02, 1.83063743e-02, 1.03705727e-02, 1.09380931e-02, 6.07488829e-03, 1.17862027e-02, 4.53122192e-03, 2.49775815e-02, 8.96308703e-03, 3.10326855e-02, 2.94072089e-02, 1.93306945e-02, 3.42785939e-03, 2.24745563e-02, 7.87119137e-03, 1.92728016e-02]
params = {"state_freqs": mg_codon}
pm = MechCodon_Sanity("mg", params, size=61)
pm._sanity_state_freqs_MG()
np.testing.assert_array_almost_equal(pm.params["nuc_freqs"], mg_nuc, decimal = DECIMAL, err_msg = "Nucleotide frequencies not properly calc'd from codon frequencies for an MG model.")
3
Example 10
Project: tract_querier Source File: test_scalar_measures.py
def test_fractional_anisotropy(N=10, random=numpy.random.RandomState(0)):
tensors = random.randn(N, 3, 3)
fa = numpy.empty(N)
for i, t in enumerate(tensors):
tt = numpy.dot(t, t.T)
tensors[i] = tt
ev = numpy.linalg.eigvalsh(tt)
mn = ev.mean()
fa[i] = numpy.sqrt(1.5 * ((ev - mn) ** 2).sum() / (ev ** 2).sum())
assert_array_almost_equal(fa, scalar_measures.fractional_anisotropy(tensors))
3
Example 11
Project: spinn Source File: test_cuda_util.py
def _test_masked_careduce_inner(f, X, Y, mask, expected):
print X
print Y
print mask
ret = f(X, Y, mask)
print ret
print expected
np.testing.assert_array_almost_equal(ret, expected)
3
Example 12
Project: siphon Source File: test_dataset.py
@recorder.use_cassette('nc4_compound_ref')
def test_struct():
"Test reading a structured variable"
ds = Dataset('http://localhost:8080/thredds/cdmremote/nc4/compound/ref_tst_compounds.nc4')
var = ds.variables['obs'][:]
assert var.shape == (3,)
assert var.dtype == np.dtype([('day', 'b'), ('elev', '<i2'), ('count', '<i4'),
('relhum', '<f4'), ('time', '<f8')])
assert_array_equal(var['day'], np.array([15, -99, 20]))
assert_array_equal(var['elev'], np.array([2, -99, 6]))
assert_array_equal(var['count'], np.array([1, -99, 3]))
assert_array_almost_equal(var['relhum'], np.array([0.5, -99.0, 0.75]))
assert_array_almost_equal(var['time'],
np.array([3600.01, -99.0, 5000.01], dtype=np.double))
3
Example 13
Project: scikit-image Source File: test_colorconv.py
def test_yuv(self):
rgb = np.array([[[1.0, 1.0, 1.0]]])
assert_array_almost_equal(rgb2yuv(rgb), np.array([[[1, 0, 0]]]))
assert_array_almost_equal(rgb2yiq(rgb), np.array([[[1, 0, 0]]]))
assert_array_almost_equal(rgb2ypbpr(rgb), np.array([[[1, 0, 0]]]))
assert_array_almost_equal(rgb2ycbcr(rgb), np.array([[[235, 128, 128]]]))
rgb = np.array([[[0.0, 1.0, 0.0]]])
assert_array_almost_equal(rgb2yuv(rgb), np.array([[[0.587, -0.28886916, -0.51496512]]]))
assert_array_almost_equal(rgb2yiq(rgb), np.array([[[0.587, -0.27455667, -0.52273617]]]))
assert_array_almost_equal(rgb2ypbpr(rgb), np.array([[[0.587, -0.331264, -0.418688]]]))
assert_array_almost_equal(rgb2ycbcr(rgb), np.array([[[144.553, 53.797, 34.214]]]))
3
Example 14
Project: ldsc Source File: test_jackknife.py
def test_jknife_2d(self):
pseudovalues = np.vstack([np.arange(10), np.arange(10)]).T
(est, var, se, cov) = jk.Jackknife.jknife(pseudovalues)
assert_array_almost_equal(var, np.array([[0.91666667, 0.91666667]]))
assert_array_almost_equal(est, np.array([[4.5, 4.5]]))
assert_array_almost_equal(
cov, np.matrix([[0.91666667, 0.91666667], [0.91666667, 0.91666667]]))
assert_array_almost_equal(se ** 2, var)
assert_array_equal(cov.shape, (2, 2))
assert_array_equal(var.shape, (1, 2))
assert_array_equal(est.shape, (1, 2))
assert_array_equal(se.shape, (1, 2))
3
Example 15
Project: python-acoustics Source File: test_building.py
def test_stc_curve():
tl = np.array([18, 18, 17, 17, 20, 21, 22, 23, 25, 26, 26, 25, 25, 26,
30, 31])
calculated = stc_curve(tl)
real = np.array([9, 12, 15, 18, 21, 24, 25, 26, 27, 28, 29, 29, 29, 29,
29, 29])
assert_array_almost_equal(calculated, real)
3
Example 16
Project: lifetimes Source File: test_estimation.py
def test_params_out_is_close_to_BTYDplus(self):
""" See https://github.com/mplatzer/BTYDplus """
mbfg = estimation.ModifiedBetaGeoFitter()
mbfg.fit(cdnow_customers['frequency'], cdnow_customers['recency'], cdnow_customers['T'], iterative_fitting=3)
expected = np.array([0.525, 6.183, 0.891, 1.614])
npt.assert_array_almost_equal(expected, np.array(mbfg._unload_params('r', 'alpha', 'a', 'b')), decimal=3)
3
Example 17
Project: GPy Source File: inference_tests.py
def test_inferenceX_GPLVM_RBF(self):
Ys = self.genData()
m = GPy.models.GPLVM(Ys,3,kernel=GPy.kern.RBF(3,ARD=True))
m.optimize()
x, mi = m.infer_newX(m.Y, optimize=True)
np.testing.assert_array_almost_equal(m.X, mi.X, decimal=2)
3
Example 18
Project: scikit-aero Source File: test_coesa.py
def test_under_1000m():
"""Tests for altitude values under 1000.0 m
"""
z = np.array([50.0, 550.0, 850.0])
h = util.geometric_to_geopotential(z)
expected_h = np.array([50.0, 550.0, 850.0])
expected_T = np.array([287.825, 284.575, 282.626])
expected_p = np.array([100720.0, 94890.0, 91523.0])
expected_rho = np.array([1.2191, 1.1616, 1.1281])
h, T, p, rho = coesa.table(h)
assert_array_almost_equal(h, expected_h, decimal=0)
assert_array_almost_equal(T, expected_T, decimal=3)
assert_array_almost_equal(p, expected_p, decimal=-1)
assert_array_almost_equal(rho, expected_rho, decimal=4)
3
Example 19
Project: numexpr Source File: test_numexpr.py
def test_changing_nthreads_00_inc(self):
a = linspace(-1, 1, 1e6)
b = ((.25 * a + .75) * a - 1.5) * a - 2
for nthreads in range(1, 7):
numexpr.set_num_threads(nthreads)
c = evaluate("((.25*a + .75)*a - 1.5)*a - 2")
assert_array_almost_equal(b, c)
3
Example 20
Project: carl Source File: test_exponential.py
def check_exponential(inverse_scale):
rng = check_random_state(1)
p_carl = Exponential(inverse_scale=inverse_scale)
p_scipy = st.expon(scale=1. / inverse_scale)
X = rng.rand(50, 1)
assert_array_almost_equal(p_carl.pdf(X),
p_scipy.pdf(X.ravel()))
assert_array_almost_equal(p_carl.cdf(X),
p_scipy.cdf(X.ravel()))
assert_array_almost_equal(-np.log(p_carl.pdf(X)),
p_carl.nll(X))
3
Example 21
Project: Axelrod Source File: test_eigen.py
def test_eigen_4(self):
# Test a 4x4 matrix
mat = [[2, 0, 0, 0], [1, 2, 0, 0], [0, 1, 3, 0], [0, 0, 1, 3]]
evector, evalue = principal_eigenvector(mat, maximum_iterations=None,
max_error=1e-10)
self.assertAlmostEqual(evalue, 3, places=3)
assert_array_almost_equal(evector, numpy.dot(mat, evector) / evalue)
assert_array_almost_equal(evector, normalise([0, 0, 0, 1]), decimal=4)
3
Example 22
Project: numexpr Source File: test_numexpr.py
def test_changing_nthreads_01_dec(self):
a = linspace(-1, 1, 1e6)
b = ((.25 * a + .75) * a - 1.5) * a - 2
for nthreads in range(6, 1, -1):
numexpr.set_num_threads(nthreads)
c = evaluate("((.25*a + .75)*a - 1.5)*a - 2")
assert_array_almost_equal(b, c)
3
Example 23
def test_mvn_pdf(self):
cov3 = self.cov3
mvn3 = self.mvn3
mvn3c = self.mvn3c
r_val = [-7.667977543898155, -6.917977543898155, -5.167977543898155]
assert_array_almost_equal( mvn3.logpdf(cov3), r_val, decimal = 14)
#decimal 18
r_val = [0.000467562492721686, 0.000989829804859273, 0.005696077243833402]
assert_array_almost_equal( mvn3.pdf(cov3), r_val, decimal = 17)
#cheating new mean, same cov, too dangerous, got wrong instance in tests
#mvn3.mean = np.array([0,0,0])
mvn3b = MVNormal(np.array([0,0,0]), cov3)
r_val = [0.02914269740502042, 0.02269635555984291, 0.01767593948287269]
assert_array_almost_equal( mvn3b.pdf(cov3), r_val, decimal = 16)
3
Example 24
Project: python-pcl Source File: test.py
def test_asarray(self):
p = pcl.PointCloud(self.p) # copy
# old0 = p[0]
a = np.asarray(p) # view
a[:] += 6
assert_array_almost_equal(p[0], a[0])
# Regression test: deleting a second view would previously
# reset the view count to zero.
b = np.asarray(p)
del b
self.assertRaises(ValueError, p.resize, 2 * len(p))
3
Example 25
Project: bdot Source File: test_carray.py
def test_dot_matrix_chunklen_greater_than_length_m2_numpy_out():
matrix = np.random.random_sample(size=(1000, 100))
bcarray1 = bdot.carray(matrix, chunklen=2**9, cparams=bdot.cparams(clevel=2))
bcarray2 = bdot.carray(matrix, chunklen=2**11, cparams=bdot.cparams(clevel=2))
result = np.empty((1000, 1000), dtype=np.float64)
bcarray1.dot(bcarray2, out=result)
expected = matrix.dot(matrix.T)
assert_array_almost_equal(expected, result, decimal=5)
3
Example 26
def test_random_state_transfer():
"""
Test that random state can be transferred from one theano graph to another.
"""
class Graph:
def __init__(self, seed=123):
self.rng = MRG_RandomStreams(seed)
self.y = self.rng.uniform(size=(1,))
g1 = Graph(seed=123)
f1 = theano.function([], g1.y)
g2 = Graph(seed=987)
f2 = theano.function([], g2.y)
g2.rng.rstate = g1.rng.rstate
for (su1, su2) in zip(g1.rng.state_updates, g2.rng.state_updates):
su2[0].set_value(su1[0].get_value())
numpy.testing.assert_array_almost_equal(f1(), f2(), decimal=6)
3
Example 27
Project: tensorlib Source File: test_mathutils.py
def test_matricize():
"""
Test implementation of matricize.
"""
X = np.arange(1, 9).reshape(2, 2, 2)
matricize(X, 0)
assert_array_almost_equal(matricize(X, 2), matricize(X, -1))
assert_array_almost_equal(matricize(X, 1), matricize(X, -2))
3
Example 28
Project: gplearn Source File: test_fixes.py
def test_expit():
# Check numerical stability of expit (logistic function).
# Simulate our previous Cython implementation, based on
#http://fa.bianp.net/blog/2013/numerical-optimizers-for-logistic-regression
assert_almost_equal(expit(1000.), 1. / (1. + np.exp(-1000.)), decimal=16)
assert_almost_equal(expit(-1000.), np.exp(-1000.) / (1. + np.exp(-1000.)),
decimal=16)
x = np.arange(10)
out = np.zeros_like(x, dtype=np.float32)
assert_array_almost_equal(expit(x), expit(x, out=out))
3
Example 29
Project: spykeutils Source File: test_scipy_quantities.py
def test_works_with_multidimensional_arrays(self):
a = sp.array([[0.0, 1.0], [2.0, 3.0]]) * pq.s
b = sp.array([[2.0, 2.0], [3.0, 4.0]]) * pq.s
expected = sp.array([[2.0, 4.0], [10.0, 18.0]]) * pq.s
actual = spq.inner(a, b)
assert_array_almost_equal(expected, actual.rescale(expected.units))
3
Example 30
Project: tracer Source File: test_flat_surface.py
def test_register_incoming(self):
"""Flat mirror: a simple bundle is registered correctly"""
correct_params = r_[[math.sqrt(3)]*4]
params = self._surf.register_incoming(self._bund)
N.testing.assert_array_almost_equal(params, correct_params)
3
Example 31
Project: pymanopt Source File: test_manifold_oblique.py
def test_pairmean(self):
s = self.man
X = s.rand()
Y = s.rand()
Z = s.pairmean(X, Y)
np_testing.assert_array_almost_equal(s.dist(X, Z), s.dist(Y, Z))
3
Example 32
Project: tsfresh Source File: test_ts_features.py
def test_calculate_ts_features_after_randomisation(self):
df = self.create_test_data_sample()
df_random = df.copy().sample(frac=1)
extracted_features = extract_features(df, self.settings, "id", "sort", "kind", "val").sort_index()
extracted_features_from_random = extract_features(df_random, self.settings,
"id", "sort", "kind", "val").sort_index()
six.assertCountEqual(self, extracted_features.columns, extracted_features_from_random.columns)
for col in extracted_features:
self.assertIsNone(np.testing.assert_array_almost_equal(extracted_features[col],
extracted_features_from_random[col]))
3
Example 33
Project: scikit-image Source File: test_colorconv.py
def test_yuv_roundtrip(self):
img_rgb = img_as_float(self.img_rgb)[::16, ::16]
assert_array_almost_equal(yuv2rgb(rgb2yuv(img_rgb)), img_rgb)
assert_array_almost_equal(yiq2rgb(rgb2yiq(img_rgb)), img_rgb)
assert_array_almost_equal(ypbpr2rgb(rgb2ypbpr(img_rgb)), img_rgb)
assert_array_almost_equal(ycbcr2rgb(rgb2ycbcr(img_rgb)), img_rgb)
3
Example 34
Project: lifelines Source File: test_estimation.py
def test_output_against_R(self, rossi):
# from http://cran.r-project.org/doc/contrib/Fox-Companion/appendix-cox-regression.pdf
# Link is now broken, but this is the code:
#
# rossi <- read.csv('.../lifelines/datasets/rossi.csv')
# mod.allison <- coxph(Surv(week, arrest) ~ fin + age + race + wexp + mar + paro + prio,
# data=rossi)
# cat(round(mod.allison$coefficients, 4), sep=", ")
expected = np.array([[-0.3794, -0.0574, 0.3139, -0.1498, -0.4337, -0.0849, 0.0915]])
cf = CoxPHFitter(normalize=False)
cf.fit(rossi, duration_col='week', event_col='arrest')
npt.assert_array_almost_equal(cf.hazards_.values, expected, decimal=3)
3
Example 35
Project: poliastro Source File: test_util.py
def test_transform_unitless_vector():
vector = [0, 1, 0]
angle = 45 * u.deg
axis = 'z'
expected_vector = [np.sqrt(2) / 2, np.sqrt(2) / 2, 0]
result = util.transform(vector, angle, axis)
assert_array_almost_equal(result, expected_vector)
3
Example 36
Project: lifetimes Source File: test_estimation.py
def test_expectation_returns_same_value_Hardie_excel_sheet(self):
bfg = estimation.BetaGeoFitter()
bfg.fit(cdnow_customers['frequency'], cdnow_customers['recency'], cdnow_customers['T'], tol=1e-6)
times = np.array([0.1429, 1.0, 3.00, 31.8571, 32.00, 78.00])
expected = np.array([0.0078 ,0.0532 ,0.1506 ,1.0405,1.0437, 1.8576])
actual = bfg.expected_number_of_purchases_up_to_time(times)
npt.assert_array_almost_equal(actual, expected, decimal=3)
3
Example 37
Project: iris Source File: test_mapping.py
def test_default_projection_and_extent(self):
self.assertEqual(iplt.default_projection(self.cube),
ccrs.PlateCarree())
np_testing.assert_array_almost_equal(
iplt.default_projection_extent(self.cube),
[0., 360., -89.99995422, 89.99998474])
np_testing.assert_array_almost_equal(
iplt.default_projection_extent(
self.cube, mode=iris.coords.BOUND_MODE),
[-1.875046, 358.124954, -91.24995422, 91.24998474])
3
Example 38
Project: APGL Source File: UtilTest.py
def testPowerEigs(self):
n = 10
numRuns = 10
for i in range(numRuns):
A = numpy.random.rand(n, n)
l, v = Util.powerEigs(A, 0.001)
nptst.assert_array_almost_equal(v*l, A.dot(v), 2)
u, V = numpy.linalg.eig(A)
self.assertAlmostEquals(numpy.max(u), l, 2)
try:
nptst.assert_array_almost_equal(V[:, 0], v, 2)
except AssertionError:
nptst.assert_array_almost_equal(V[:, 0], -v, 2)
3
Example 39
def testMargin(self):
#! TODO: check results to make sure they are OK
gm, pm, wg, wp = margin(self.siso_tf1);
gm, pm, wg, wp = margin(self.siso_tf2);
gm, pm, wg, wp = margin(self.siso_ss1);
gm, pm, wg, wp = margin(self.siso_ss2);
gm, pm, wg, wp = margin(self.siso_ss2*self.siso_ss2*2);
np.testing.assert_array_almost_equal(
[gm, pm, wg, wp], [1.5451, 75.9933, 1.2720, 0.6559], decimal=3)
3
Example 40
Project: PyFME Source File: test_cessna_310.py
def test_calculate_aero_forces_moments_alpha_beta_zero():
aircraft = Cessna310()
aircraft.q_inf = 0.5 * 1.225 * 100 ** 2
aircraft.alpha = 0
aircraft.beta = 0
aircraft.controls = {'delta_elevator': 0,
'hor_tail_incidence': 0,
'delta_aileron': 0,
'delta_rudder': 0,
'delta_t': 0}
L, D, Y, l, m, n = aircraft._calculate_aero_forces_moments()
assert_array_almost_equal([L, D, Y],
[28679.16845, 2887.832934, 0.],
decimal=4)
assert_array_almost_equal([l, m, n],
[0, 10177.065816, 0],
decimal=4)
3
Example 41
Project: pyvolve Source File: parameters_sanity_test.py
def test_sanity_state_freqs_aminoacid(self):
wag_freqs = [0.08662799999999994, 0.0193078, 0.0570451, 0.0580589, 0.0384319, 0.0832518, 0.0244313, 0.048466, 0.0620286, 0.086209, 0.0195027, 0.0390894, 0.0457631, 0.0367281, 0.043972, 0.0695179, 0.0610127, 0.0708956, 0.0143859, 0.0352742]
params = {}
pm = ECM_Sanity("wag", params, size = 20)
pm._sanity_state_freqs(empirical = True)
np.testing.assert_array_almost_equal(pm.params["state_freqs"], wag_freqs, decimal = DECIMAL, err_msg = "WAG (aa model) default state_freqs not set up properly.")
3
Example 42
Project: dask Source File: test_ghost.py
def test_nearest_ghost():
a = np.arange(144).reshape(12, 12).astype(float)
darr = da.from_array(a, chunks=(6, 6))
garr = ghost(darr, depth={0: 5, 1: 5},
boundary={0: 'nearest', 1: 'nearest'})
tarr = trim_internal(garr, {0: 5, 1: 5})
assert_array_almost_equal(tarr, a)
3
Example 43
Project: pgmpy Source File: test_ExactInference.py
def test_query_multiple_variable(self):
belief_propagation = BeliefPropagation(self.bayesian_model)
query_result = belief_propagation.query(['Q', 'J'])
np_test.assert_array_almost_equal(query_result['J'].values,
np.array([0.416, 0.584]))
np_test.assert_array_almost_equal(query_result['Q'].values,
np.array([0.4912, 0.5088]))
3
Example 44
def test_relu():
arr = np.arange(-12, 13).reshape(5, 5).astype(np.float32)
expressions, input_variable = fuse([Relu()])
relu_func = theano.function([input_variable], expressions)
arr = arr[np.newaxis, np.newaxis]
arr2 = arr.copy()
arr2[arr2 <= 0] = 0
thresholded = relu_func(arr)[0]
assert_array_almost_equal(thresholded, arr2)
3
Example 45
Project: tensorlib Source File: test_mathutils.py
def test_unmatricize():
"""
Test implementation of unmatricize.
"""
X = np.arange(2 * 3 * 4 * 5).reshape(3, 2, 4, 5)
for i in range(X.ndim):
X2 = matricize(X, i)
assert_array_almost_equal(unmatricize(X2, i, X.shape), X)
X2 = matricize(X, -2)
assert_array_almost_equal(unmatricize(X2, -2, X.shape), X)
X = np.arange(1, 9).reshape(2, 2, 2)
for i in range(X.ndim):
X2 = matricize(X, i)
assert_array_almost_equal(unmatricize(X2, i, X.shape), X)
3
Example 46
def assert_array_almost_equal(x, y, decimal=6, err_msg='', verbose=True):
"""Raises an AssertionError if objects are not equal up to desired precision.
Args:
x(numpy.ndarray or cupy.ndarray): The actual object to check.
y(numpy.ndarray or cupy.ndarray): The desired, expected object.
decimal(int): Desired precision.
err_msg(str): The error message to be printed in case of failure.
verbose(bool): If ``True``, the conflicting
values are appended to the error message.
.. seealso:: :func:`numpy.testing.assert_array_almost_equal`
"""
numpy.testing.assert_array_almost_equal(
cupy.asnumpy(x), cupy.asnumpy(y), decimal=decimal,
err_msg=err_msg, verbose=verbose)
3
Example 47
Project: pgmpy Source File: test_ExactInference.py
def test_query_single_variable_with_evidence(self):
belief_propagation = BeliefPropagation(self.bayesian_model)
query_result = belief_propagation.query(variables=['J'],
evidence={'A': 0, 'R': 1})
np_test.assert_array_almost_equal(query_result['J'].values,
np.array([0.60, 0.40]))
3
Example 48
Project: pymanopt Source File: test_manifold_euclidean.py
def test_exp_log_inverse(self):
s = self.man
X = s.rand()
Y = s.rand()
Yexplog = s.exp(X, s.log(X, Y))
np_testing.assert_array_almost_equal(Y, Yexplog)
3
Example 49
Project: attention-lvcsr Source File: test_shared_randomstreams.py
def test_random_state_transfer(self):
"""
Test that random state can be transferred from one theano graph to another.
"""
class Graph:
def __init__(self, seed=123):
self.rng = RandomStreams(seed)
self.y = self.rng.uniform(size=(1,))
g1 = Graph(seed=123)
f1 = function([], g1.y)
g2 = Graph(seed=987)
f2 = function([], g2.y)
for (su1, su2) in zip(g1.rng.state_updates, g2.rng.state_updates):
su2[0].set_value(su1[0].get_value())
numpy.testing.assert_array_almost_equal(f1(), f2(), decimal=6)
3
Example 50
Project: selective_search_py Source File: test_features.py
def test_2region_1color(self):
self.setup_method(self, w = 1, h = 2)
for y in range(self.h):
self.f.label[y, :] = y
hist = self.f._Features__init_color(2)
assert len(hist) == 2
assert hist[0].shape == (75,)
r1_expected = ([1.0/3] + [0] * 24) + ([1.0/3] + [0] * 24) + ([1.0/3] + [0] * 24)
r2_expected = ([1.0/3] + [0] * 24) + ([1.0/3] + [0] * 24) + ([1.0/3] + [0] * 24)
numpy.testing.assert_array_almost_equal(hist[0].ravel(), r1_expected)
numpy.testing.assert_array_almost_equal(hist[1].ravel(), r2_expected)