• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python tools.assert_almost_equals函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中nose.tools.assert_almost_equals函数的典型用法代码示例。如果您正苦于以下问题:Python assert_almost_equals函数的具体用法?Python assert_almost_equals怎么用?Python assert_almost_equals使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了assert_almost_equals函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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))
开发者ID:brianjimenez,项目名称:lightdock,代码行数:7,代码来源:test_atom.py


示例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) 
开发者ID:par2,项目名称:lamana-test,代码行数:26,代码来源:test_constructs.py


示例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)
开发者ID:Mercurial1101,项目名称:gt-nlp-class,代码行数:29,代码来源:testnb.py


示例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)
开发者ID:cedebrun,项目名称:gt-nlp-class,代码行数:7,代码来源:test_pset1_classifier.py


示例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)
开发者ID:jerevon,项目名称:hyperspy,代码行数:7,代码来源:test_model.py


示例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
开发者ID:terkkila,项目名称:cgml,代码行数:30,代码来源:test_optimizers.py


示例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)
开发者ID:cedebrun,项目名称:gt-nlp-class,代码行数:7,代码来源:test_coref.py


示例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))
开发者ID:brianjimenez,项目名称:lightdock,代码行数:25,代码来源:test_predictor.py


示例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)
开发者ID:npp2016,项目名称:METE,代码行数:7,代码来源:tests_mete.py


示例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)
开发者ID:npp2016,项目名称:METE,代码行数:7,代码来源:tests_mete.py


示例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)
开发者ID:zhangkaixu,项目名称:oneseg,代码行数:31,代码来源:test_base.py


示例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
开发者ID:felipebetancur,项目名称:notesegmentation,代码行数:7,代码来源:test_segmentation.py


示例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)
开发者ID:johnglover,项目名称:simpl,代码行数:25,代码来源:test_synthesis.py


示例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
开发者ID:gitter-badger,项目名称:irm,代码行数:28,代码来源:test_state.py


示例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)]
开发者ID:mgraffg,项目名称:EvoDAG,代码行数:27,代码来源:test_gp.py


示例16: test_varyingDropoutRates

def test_varyingDropoutRates():

    X = T.fmatrix('X')

    rng = np.random.RandomState(seed=0)

    W = _make_shared(np.ones((10,1),dtype=cgml.types.floatX))
    b = _make_shared(np.zeros((1,), dtype=cgml.types.floatX))

    for dropout in [0.0,0.5,1.0]:
        
        layer = Layer(rng=rng,
                      input=X,
                      n_in=10,
                      n_out=1,
                      activation=cgml.activations.linear,
                      W=W,
                      b=b,
                      dropout=dropout,
                      name="dropout")
    
        f = theano.function(inputs=[X],
                            outputs=layer.output)
        
        X_np = np.ones((1,10),dtype=cgml.types.floatX)

        values = []

        for i in range(10000):
        
            y_np = f(X_np)
            
            values.append(y_np[0,0])

        assert_almost_equals(np.mean(values),(1-dropout)*10,places=1)
开发者ID:terkkila,项目名称:cgml,代码行数:35,代码来源:test_layers.py


示例17: test_reclasso

def test_reclasso(n=5, m=5, mu0=.5, mu1=.8, thresh=1e-4, verbose=True):  
    """
    test the reclasso algorithm using random data
    """
    
    # sample a problem
    X = np.random.randn(n+1, m)
    y = np.random.randn(n+1, 1)
    
    # solve both problems using an interior point method
    theta0 = algo.interior_point(X[:-1, :], y[:-1], mu0)
    theta1 = algo.interior_point(X, y, mu1)
    
    # prepare warm-start solution for the homotopy 
    theta0, nz0, K0, truesol0 = algo.fix_sol(X[:-1, :], y[:-1], mu0, theta0, thresh=thresh)
    theta1, nz1, K1, truesol1 = algo.fix_sol(X, y, mu1, theta1, thresh=thresh)
    
    if not truesol0 or not truesol1: raise NameError, "bad threshold for interior point solution"
    
    # solve the problem using reclasso
    theta_nz, nz, K, nbr1, nbr2 = reclasso(X, y, mu0, mu1, theta0[nz0], nz0, K0, verbose=verbose, showpath=False)
    theta = np.zeros((m, 1))
    theta[nz] = theta_nz
    
    # check the result is the same as with the interior point method
    error = np.sum((theta1 - theta)**2)/np.sum(theta1**2)
    
    assert_almost_equals(error, 0)
开发者ID:pierreg,项目名称:reclasso,代码行数:28,代码来源:test.py


示例18: test_py_c_equal_rt

 def test_py_c_equal_rt(self):
     audio, sampling_rate, onsets = modal.get_audio_file('piano_G2.wav')
     audio = audio[0:4096]
     frame_size = 256
     hop_size = 256
     py_odf = EnergyODF()
     py_odf.set_frame_size(frame_size)
     py_odf.set_hop_size(hop_size)
     c_odf = CEnergyODF()
     c_odf.set_frame_size(frame_size)
     c_odf.set_hop_size(hop_size)
     # if necessary, pad the input signal
     if len(audio) % hop_size != 0:
         audio = np.hstack((
             audio, np.zeros(hop_size - (len(audio) % hop_size),
                             dtype=np.double)
         ))
     # get odf samples
     audio_pos = 0
     while audio_pos <= len(audio) - frame_size:
         frame = audio[audio_pos:audio_pos + frame_size]
         py_odf_value = py_odf.process_frame(frame)
         c_odf_value = c_odf.process_frame(frame)
         assert_almost_equals(py_odf_value, c_odf_value,
                              places=self.FLOAT_PRECISION)
         audio_pos += hop_size
开发者ID:einvalentin,项目名称:modal,代码行数:26,代码来源:test_energy.py


示例19: test_hmm_weights

def test_hmm_weights():
    simple_weights = viterbi.get_HMM_weights('tests/hmm_simple.dat')
    assert_almost_equals(1.0, np.exp(simple_weights[('D', START_TAG, TRANS)]), places=3)
    assert_almost_equals(1.0, np.exp(simple_weights[('N', 'D', TRANS)]), places=3)
    assert_almost_equals(1.0, np.exp(simple_weights[('V', 'N', TRANS)]), places=3)
    assert_almost_equals(1.0, np.exp(simple_weights[('JJ', 'V', TRANS)]), places=3)
    assert_almost_equals(1.0, np.exp(simple_weights[(END_TAG, 'JJ', TRANS)]), places=3)
开发者ID:Mercurial1101,项目名称:gt-nlp-class,代码行数:7,代码来源:testviterbi.py


示例20: test_case2

    def test_case2(self):
        # case2: C = 1.0, phi = 2.0

        scw = SCW(2.0, 1.0)

        assert_equals(scw.psi, 3.0)
        assert_equals(scw.zeta, 5.0)

        x = {}
        Trie.insert(x, ["a", "b", "c"], 1.0)
        Trie.insert(scw.mu, ["a", "b", "c"], 1.0)

        margin = scw.calc_margin(x, 1)
        assert_equals(margin, 1.0)

        variance = scw.calc_variance(x)
        assert_equals(variance, 1.0)

        alpha = scw.calc_alpha(margin, variance)
        assert_almost_equals(alpha, (math.sqrt(24)-3)/5)

        beta = scw.calc_beta(margin, variance, alpha)
        desired = ((2 * (math.sqrt(24) - 3) / 5) /
                   (0.5 *
                    (-2 * (math.sqrt(24) - 3) / 5 +
                        math.sqrt(4 * (33 - 6 * math.sqrt(24)) / 25 + 4)) +
                    2 * (math.sqrt(24) - 3) / 5))
        assert_almost_equals(beta, desired)

        Trie.insert(x, ["a", "b", "d"], 2.0)
        scw.update_mu_sigma(x, -1, 0.2, 0.5)
        assert_equals(Trie.find(scw.mu, ["a", "b", "c"]), 0.8)
        assert_equals(Trie.find(scw.mu, ["a", "b", "d"]), -0.4)
        assert_equals(Trie.find(scw.sigma, ["a", "b", "c"]), 0.5)
        assert_equals(Trie.find(scw.sigma, ["a", "b", "d"]), -1.0)
开发者ID:pombredanne,项目名称:rakutenma-python,代码行数:35,代码来源:test_scw.py



注:本文中的nose.tools.assert_almost_equals函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python tools.assert_dict_contains_subset函数代码示例发布时间:2022-05-27
下一篇:
Python tools.assert_almost_equal函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap