本文整理汇总了Python中nose.tools.assert_almost_equals函数的典型用法代码示例。如果您正苦于以下问题:Python assert_almost_equals函数的具体用法?Python assert_almost_equals怎么用?Python assert_almost_equals使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了assert_almost_equals函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_distance
def test_distance(self):
atom1 = Atom(1, 'CA', '', 'A', 'ALA', 1, '', x=1., y=2., z=2.,
occupancy=1., b_factor=0., element=None, mass=None)
atom2 = Atom()
assert_almost_equals(3.0, atom1.distance(atom2))
assert_almost_equals(3.0, atom2.distance(atom1))
示例2: test_Laminate_sanity6
def test_Laminate_sanity6():
'''Check middle d_ is half the total thickness.'''
cols = ['t(um)']
for case in cases.values():
for LM in case.LMs:
# for LMs in cases.values():
# for LM in LMs:
if (LM.nplies%2 != 0) & (LM.p%2 != 0) & (LM.p > 3):
print(LM.Geometry)
#print(LM.name)
print(LM.p)
#print(LM.LMFrame)
df = LM.LMFrame
#t_total = df.groupby('layer')['t(um)'].unique().sum()[0] * 1e-6
#print(t_total)
#print(LM.total)
#print(type(LM.total))
t_mid = df.loc[df['label'] == 'neut. axis', 'd(m)']
actual = t_mid.iloc[0]
expected = LM.total/2
#print(actual)
#print(expected)
# Regular assert breaks due to float. Using assert_almost_equals'''
np.testing.assert_almost_equal(actual, expected)
nt.assert_almost_equals(actual, expected)
示例3: test_nb_smoothing
def test_nb_smoothing():
'''
Tests for the following two sentences, with smoothing of 0.5
the D
man N
runs V
man V
the D
cannons N
'''
allwords = ['the', 'man', 'runs', 'the', 'cannons']
wordCountsByTag = Counter({
'D': Counter({'the': 2}),
'N': Counter({'man': 1, 'cannons': 1}),
'V': Counter({'runs': 1, 'man': 1})
})
classCounts = Counter({'D': 2, 'N': 2, 'V': 2})
# smoothing of 0.5 reserves 1/2 probability mass for unknown
weights = naivebayes.learnNBWeights(wordCountsByTag, classCounts,
allwords, alpha=0.5)
assert_almost_equals(5.0 / 8.0, np.exp(weights[('D', 'the')]), places=3)
assert_almost_equals(1.0 / 8.0, np.exp(weights[('N', 'the')]))
assert_almost_equals(0.333, np.exp(weights[('N', OFFSET)]), places=3)
assert_almost_equals(0.333, np.exp(weights[('V', OFFSET)]), places=3)
# offsets unchanged
assert_almost_equals(0.333, np.exp(weights[('D', OFFSET)]), places=3)
示例4: test_nb_d3_3
def test_nb_d3_3():
global x_tr, y_tr, x_dv, y_dv, x_te
# public
theta_nb = naive_bayes.estimate_nb(x_tr,y_tr,0.1)
y_hat,scores = clf_base.predict(x_tr[55],theta_nb,labels)
assert_almost_equals(scores['science'],-949.406,places=2)
示例5: test_std10_red_chisq
def test_std10_red_chisq(self):
std = 10
np.random.seed(1)
self.s.add_gaussian_noise(std)
self.s.metadata.set_item("Signal.Noise_properties.variance", std ** 2)
self.m.fit(fitter="leastsq", method="ls")
nt.assert_almost_equals(self.m.red_chisq.data, 0.79949135)
示例6: test_adadelta_logreg
def test_adadelta_logreg():
x = T.fvector('x')
y = T.fscalar('y')
w = _make_shared([1.0,1.0],name='w')
b = _make_shared([1.0],name='b')
yhat = 1.0 / ( 1.0 + T.exp( - T.dot(x,w) - b ) )
e = y - yhat
cost = T.dot(e,e)
ad = AdaDelta(cost = cost,
params = [w,b])
update = theano.function( inputs = [x,y],
outputs = cost,
updates = ad.updates )
c = update([2,1],0)
assert_almost_equals(c,0.9643510838246173)
c_prev = c
for i in range(100):
c = update([2,1],0)
assert_equals(c,c)
assert_true(c < c_prev)
c_prev = c
示例7: test_match_nopro_f1_d2_3
def test_match_nopro_f1_d2_3():
global all_markables
f, r, p = coref.eval_on_dataset(
coref_rules.make_resolver(coref_rules.exact_match_no_pronouns),
all_markables)
assert_almost_equals(r, 0.3028, places=4)
assert_almost_equals(p, 0.9158, places=4)
示例8: test_calculate_phi_psi
def test_calculate_phi_psi(self):
atoms, residues, chains = parse_complex_from_file(self.golden_data_path + '1PPElig.pdb')
protein = Complex(chains, atoms)
# psi: angle #0:[email protected],ca,c #0:[email protected]
# phi: angle #0:[email protected] #0:[email protected],ca,c
phi_angles = [-105.92428251619579, -134.402235889132, -58.32268858533758, -85.62997439535678, -129.666484600813,
-77.00076813772478, -142.09891098624075, -82.10672119029674, -163.14606891327375,
-109.37900096123484, -138.72905680654182, -59.09699793329797, -60.06774387010816,
-74.41030551527874, -99.82766540256617, -92.6495110068149, 54.969041241310705,
-104.60151419194615, -67.57074855137641, -123.83574594954692, -85.90313254423194,
-87.7781803331676, -66.345484249271, -64.51513795752882, 108.23656098935888, -129.62530277139578,
-71.90658189461674, -170.4460918036806]
psi_angles = [138.38576328505278, 105.22472788100255, 106.42882930892199, 150.65572151747787, 72.08329638522976,
130.19890858175336, 115.48238807519739, 132.48041144914038, 163.35191386073618,
151.17756189538443, -28.310569696143393, 162.66293554938997, -32.25480696024475,
-20.28436719199857, -11.444789534534305, 163.38578466073147, 150.2534549328882,
-128.53524744082424, 20.01260634937939, 151.96710290169335, 159.55519588393594,
115.07091589216549, 152.8911959270869, -24.04765297807205, -14.890186424782046, 15.86273088398991,
152.7552784042674, 146.11762131430552]
for i in range(1, len(protein.residues)):
phi, psi = calculate_phi_psi(protein.residues[i], protein.residues[i - 1])
assert_almost_equals(phi_angles[i - 1], math.degrees(phi))
assert_almost_equals(psi_angles[i - 1], math.degrees(psi))
示例9: test_get_beta_multiplevalues
def test_get_beta_multiplevalues():
"""Check that multiple values are handled properly"""
Svals = [16, 256]
Nvals = [64, 4096]
betavals = get_beta(Svals, Nvals)
assert_almost_equals(betavals[0], 0.101, places=3)
assert_almost_equals(betavals[1], 0.0147, places=4)
示例10: check_get_beta
def check_get_beta(S0, N0, version, beta_known):
beta_code = get_beta(S0, N0, version=version)
#Determine number of decimal places in known value and round code value equilalently
decimal_places_in_beta_known = abs(Decimal(beta_known).as_tuple().exponent)
beta_code_rounded = round(beta_code, decimal_places_in_beta_known)
assert_almost_equals(beta_code_rounded, float(beta_known), places=6)
示例11: count_bigrams
def test_分词(self):
self.bigrams = count_bigrams(self.dev_x, max_size = 100000)
print('bigram size',len(self.bigrams))
self.assertEqual(len(self.bigrams), 6308)
train_x, train_y = self.dev_x, self.dev_y # for debug
test_x, test_y = self.test_x, self.test_y
# init the model
segger = Base_Segger(bigrams = self.bigrams)
# train the model
segger.fit(train_x, train_y,
dev_x = test_x, dev_y = test_y,
iterations = 3)
f1 = segger.evaluator.report(quiet = True)
assert_almost_equals(f1, 0.8299, places = 4)
# save it and reload it
gzip.open('test_model.gz','w').write(pickle.dumps(segger))
segger = pickle.load(gzip.open('test_model.gz'))
# use the model and evaluate outside
evaluator = CWS_Evaluator()
output = segger.predict(test_x)
evaluator.eval_all(test_y, output)
evaluator.report()
f1 = segger.evaluator.report(quiet = True)
assert_almost_equals(f1, 0.8299, places = 4)
示例12: test_efforts
def test_efforts(self):
a = np.linspace(10, 100, 10)
t = np.array([0, 25, 50, 75])
efforts, w, M = ns.segmentation._efforts(a, t)
assert np.all(efforts == np.array([2, 2, 3]))
nt.assert_almost_equals(w, 2.333, places=3) # mean of [2, 2, 3]
assert M == 1
示例13: test_harmonic_synthesis_ifft
def test_harmonic_synthesis_ifft(self):
pd = SMSPeakDetection()
pd.hop_size = hop_size
frames = pd.find_peaks(self.audio)
pt = SMSPartialTracking()
pt.max_partials = max_partials
frames = pt.find_partials(frames)
synth = SMSSynthesis()
synth.hop_size = hop_size
synth.max_partials = max_partials
synth.det_synthesis_type = SMSSynthesis.SMS_DET_IFFT
synth_audio = synth.synth(frames)
assert len(synth_audio) == len(self.audio)
sms_audio, sampling_rate = simpl.read_wav(
libsms_harmonic_synthesis_ifft_path
)
assert len(synth_audio) == len(sms_audio)
for i in range(len(synth_audio)):
assert_almost_equals(synth_audio[i], sms_audio[i], float_precision)
示例14: _assert_structure_equals
def _assert_structure_equals(defn, s1, s2, views, r):
assert_equals(s1.ndomains(), s2.ndomains())
assert_equals(s1.nrelations(), s2.nrelations())
for did in xrange(s1.ndomains()):
assert_equals(s1.nentities(did), s2.nentities(did))
assert_equals(s1.ngroups(did), s2.ngroups(did))
assert_equals(s1.assignments(did), s2.assignments(did))
assert_equals(set(s1.groups(did)), set(s2.groups(did)))
assert_close(s1.get_domain_hp(did), s2.get_domain_hp(did))
assert_almost_equals(s1.score_assignment(did), s2.score_assignment(did))
for rid in xrange(s1.nrelations()):
assert_close(s1.get_relation_hp(rid), s2.get_relation_hp(rid))
dids = defn.relations()[rid]
groups = [s1.groups(did) for did in dids]
for gids in it.product(*groups):
ss1 = s1.get_suffstats(rid, gids)
ss2 = s2.get_suffstats(rid, gids)
if ss1 is None:
assert_is_none(ss2)
else:
assert_close(ss1, ss2)
assert_almost_equals(s1.score_likelihood(r), s2.score_likelihood(r))
before = list(s1.assignments(0))
bound = model.bind(s1, 0, views)
gid = bound.remove_value(0, r)
assert_equals(s1.assignments(0)[0], -1)
assert_equals(before, s2.assignments(0))
bound.add_value(gid, 0, r) # restore
示例15: test_indindividual_decision_function
def test_indindividual_decision_function():
Add.nargs = 2
Mul.nargs = 2
vars = Model.convert_features(X)
for x in vars:
x._eval_ts = x._eval_tr.copy()
vars = [Variable(k, weight=1) for k in range(len(vars))]
for i in range(len(vars)):
ind = Individual([vars[i]])
ind.decision_function(X)
hy = ind._ind[0].hy.tonparray()
[assert_almost_equals(a, b) for a, b in zip(X[:, i], hy)]
ind = Individual([Sin(0, weight=1),
Add(range(2), np.ones(2)), vars[0], vars[-1]])
ind.decision_function(X)
hy = ind._ind[0].hy.tonparray()
y = np.sin(X[:, 0] + X[:, -1])
[assert_almost_equals(a, b) for a, b in zip(y, hy)]
y = np.sin((X[:, 0] + X[:, 1]) * X[:, 0] + X[:, 2])
ind = Individual([Sin(0, weight=1), Add(range(2), weight=np.ones(2)),
Mul(range(2), weight=1),
Add(range(2), weight=np.ones(2)),
vars[0], vars[1], vars[0], vars[2]])
ind.decision_function(X)
# assert v.hy.SSE(v.hy_test) == 0
hy = ind._ind[0].hy.tonparray()
[assert_almost_equals(a, b) for a, b in zip(hy, y)]