python类tanh()的实例源码

bpnn.py 文件源码 项目:mit_ocw_6034_ai_patrick_winston 作者: yenicelik 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def sigmoid(x):
    return math.tanh(x)

# derivative of our sigmoid function
test_math.py 文件源码 项目:oil 作者: oilshell 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def testTanh(self):
        self.assertRaises(TypeError, math.tanh)
        self.ftest('tanh(0)', math.tanh(0), 0)
        self.ftest('tanh(1)+tanh(-1)', math.tanh(1)+math.tanh(-1), 0)
        self.ftest('tanh(inf)', math.tanh(INF), 1)
        self.ftest('tanh(-inf)', math.tanh(NINF), -1)
        self.assertTrue(math.isnan(math.tanh(NAN)))
        # check that tanh(-0.) == -0. on IEEE 754 systems
        if float.__getformat__("double").startswith("IEEE"):
            self.assertEqual(math.tanh(-0.), -0.)
            self.assertEqual(math.copysign(1., math.tanh(-0.)),
                             math.copysign(1., -0.))
test_math.py 文件源码 项目:python2-tracer 作者: extremecoders-re 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def testTanh(self):
        self.assertRaises(TypeError, math.tanh)
        self.ftest('tanh(0)', math.tanh(0), 0)
        self.ftest('tanh(1)+tanh(-1)', math.tanh(1)+math.tanh(-1), 0)
        self.ftest('tanh(inf)', math.tanh(INF), 1)
        self.ftest('tanh(-inf)', math.tanh(NINF), -1)
        self.assertTrue(math.isnan(math.tanh(NAN)))
        # check that tanh(-0.) == -0. on IEEE 754 systems
        if float.__getformat__("double").startswith("IEEE"):
            self.assertEqual(math.tanh(-0.), -0.)
            self.assertEqual(math.copysign(1., math.tanh(-0.)),
                             math.copysign(1., -0.))
nonlinearities.py 文件源码 项目:PyTrafficCar 作者: liyuming1978 项目源码 文件源码 阅读 15 收藏 0 点赞 0 评论 0
def __init__(self, opt={}):
        self.out_sx = opt['in_sx']
        self.out_sy = opt['in_sy']
        self.out_depth = opt['in_depth']
        self.layer_type = 'tanh'
nonlinearities.py 文件源码 项目:PyTrafficCar 作者: liyuming1978 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def forward(self, V, is_training):
        self.in_act = V
        V2 = V.cloneAndZero()
        V2.w = map(tanh, V.w)
        self.out_act = V2
        return self.out_act
NN.py 文件源码 项目:Clustering 作者: Ram81 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def dsigmoid(y):
    return y * (1.0 - y)

#using tanh instead of logistic sigmoid
NN.py 文件源码 项目:Clustering 作者: Ram81 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def tanh(x):
    return math.tanh(x)

#derivative of tanh
NN.py 文件源码 项目:Clustering 作者: Ram81 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def feedForward(self, inputs):
        '''
            Feed Forward Propagation
        ''' 

        if len(inputs) != self.input - 1:
            raise ValueError("Wrong Number of Inputs!")

        #input activations
        for i in range(self.input - 1): #-1 because of bias term
            self.ai[i] = inputs[i]

        #hidden layer activations
        for i in range(self.hidden):
            sum_ = 0.0
            for j in range(self.input):
                sum_ += self.ai[j] * self.wi[j][i]
            self.ah[i] = tanh(sum_)         #assigning the activation

        #output activations
        for k in range(self.output):        
            sum_ = 0.0
            for i in range(self.hidden):
                sum_ += self.ah[i] * self.wi[i][k]
            self.ao[k] = sigmoid(sum_)          #assigning the activation

        return self.ao[:]
sparse_vector_class.py 文件源码 项目:NLP.py 作者: PythonOptimizers 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def tanh(a):
    """Elementwise hyperbolic tangent."""
    if not isSparseVector(a):
        raise TypeError("Argument must be a SparseVector")
    rv = SparseVector(a.n, {})
    for k in a.values.keys():
        rv.values[k] = math.tanh(a.values[k])
    return rv
test_math.py 文件源码 项目:web_ctp 作者: molebot 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def testTanh(self):
        self.assertRaises(TypeError, math.tanh)
        self.ftest('tanh(0)', math.tanh(0), 0)
        self.ftest('tanh(1)+tanh(-1)', math.tanh(1)+math.tanh(-1), 0)
        self.ftest('tanh(inf)', math.tanh(INF), 1)
        self.ftest('tanh(-inf)', math.tanh(NINF), -1)
        self.assertTrue(math.isnan(math.tanh(NAN)))
test_math.py 文件源码 项目:web_ctp 作者: molebot 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def testTanhSign(self):
        # check that tanh(-0.) == -0. on IEEE 754 systems
        self.assertEqual(math.tanh(-0.), -0.)
        self.assertEqual(math.copysign(1., math.tanh(-0.)),
                         math.copysign(1., -0.))
bpnn.py 文件源码 项目:huaat_ml_dl 作者: ieee820 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def sigmod(x):
    '''
    the sigmod function,tanh is a little better than the standard  1/(1+e^-x)
    :param x:    the self variable
    :return:     the value after tanh
    '''
    return math.tanh(x)
nn.py 文件源码 项目:othello-rl 作者: jpypi 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def activation(x):
    #return expit(x)
    ##return 1.7159 * math.tanh(2/3*x)
    #print(x)

    return np.tanh(x)#list(map(math.tanh, x))
    #return np.multiply(x > 0, x)
nn.py 文件源码 项目:othello-rl 作者: jpypi 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def dactivation(x):
    #v = expit(x)
    #return v*(1-v)
    #return 1 - math.tanh(x)**2

    return 1 - np.tanh(x)**2#list(map(lambda y: 1 - math.tanh(y)**2, x))
    #return np.float64(x > 0)
short_context_search.py 文件源码 项目:Hanhan_NLP 作者: hanhanwu 项目源码 文件源码 阅读 15 收藏 0 点赞 0 评论 0
def feedforward(self, words, urls):

        for j in range(len(self.hidden_nodes)):
            sum = 0.0
            for i in range(len(self.words)):
                sum += self.li[i]*self.w_ih[i][j]
            self.lh[j] = tanh(sum)

        for j in range(len(self.urls)):
            sum = 0.0
            for i in range(len(self.hidden_nodes)):
                sum += self.lh[i]*self.w_ho[i][j]
            self.lo[j] = tanh(sum)

        return self.lo
sugar.py 文件源码 项目:hyper-engine 作者: maxim5 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def tanh(node): return merge([node], math.tanh)
test_math.py 文件源码 项目:pefile.pypy 作者: cloudtracer 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def testTanh(self):
        self.assertRaises(TypeError, math.tanh)
        self.ftest('tanh(0)', math.tanh(0), 0)
        self.ftest('tanh(1)+tanh(-1)', math.tanh(1)+math.tanh(-1), 0)
        self.ftest('tanh(inf)', math.tanh(INF), 1)
        self.ftest('tanh(-inf)', math.tanh(NINF), -1)
        self.assertTrue(math.isnan(math.tanh(NAN)))
        # check that tanh(-0.) == -0. on IEEE 754 systems
        if float.__getformat__("double").startswith("IEEE"):
            self.assertEqual(math.tanh(-0.), -0.)
            self.assertEqual(math.copysign(1., math.tanh(-0.)),
                             math.copysign(1., -0.))
cmath.py 文件源码 项目:ouroboros 作者: pybee 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def tan(x):
    z = _make_complex(x)
    z = tanh(complex(-z.imag, z.real))
    return complex(z.imag, -z.real)
cmath.py 文件源码 项目:ouroboros 作者: pybee 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def tanh(x):

    _tanh_special = [
        [-1, None, complex(-1, -0.0), -1, None, -1, -1],
        [nan+nanj, None, None, None, None, nan+nanj, nan+nanj],
        [nan+nanj, None, complex(-0.0, -0.0), complex(-0.0, 0.0), None, nan+nanj, nan+nanj],
        [nan+nanj, None, complex(0.0, -0.0), 0.0, None, nan+nanj, nan+nanj],
        [nan+nanj, None, None, None, None, nan+nanj, nan+nanj],
        [1, None, complex(1, -0.0), 1, None, 1, 1],
        [nan+nanj, nan+nanj, complex(float("nan"), -0.0), nan, nan+nanj, nan+nanj, nan+nanj]
    ]

    z = _make_complex(x)

    if not isfinite(z):
        if math.isinf(z.imag) and math.isfinite(z.real):
            raise ValueError
        if math.isinf(z.real) and math.isfinite(z.imag) and z.imag != 0:
            if z.real > 0:
                return complex(1, math.copysign(0.0, math.sin(z.imag)
                                                * math.cos(z.imag)))
            return complex(-1, math.copysign(0.0, math.sin(z.imag)
                                             * math.cos(z.imag)))
        return _tanh_special[_special_type(z.real)][_special_type(z.imag)]

    if abs(z.real) > _LOG_LARGE_DOUBLE:
        return complex(
            math.copysign(1, z.real),
            4*math.sin(z.imag)*math.cos(z.imag)*math.exp(-2*abs(z.real))
        )
    tanh_x = math.tanh(z.real)
    tan_y = math.tan(z.imag)
    cx = 1/math.cosh(z.real)
    denom = 1 + tanh_x * tanh_x * tan_y * tan_y
    return complex(tanh_x * (1 + tan_y*tan_y)/denom,
                   ((tan_y / denom) * cx) * cx)
test_math.py 文件源码 项目:ouroboros 作者: pybee 项目源码 文件源码 阅读 38 收藏 0 点赞 0 评论 0
def testTanh(self):
        self.assertRaises(TypeError, math.tanh)
        self.ftest('tanh(0)', math.tanh(0), 0)
        self.ftest('tanh(1)+tanh(-1)', math.tanh(1)+math.tanh(-1), 0)
        self.ftest('tanh(inf)', math.tanh(INF), 1)
        self.ftest('tanh(-inf)', math.tanh(NINF), -1)
        self.assertTrue(math.isnan(math.tanh(NAN)))


问题


面经


文章

微信
公众号

扫码关注公众号