当前位置: 首页>>代码示例>>Python>>正文


Python math.tanh函数代码示例

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


在下文中一共展示了tanh函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: feed_forward

    def feed_forward(self):
        """
        フィードフォワードアルゴリズム
        """
        # 入力はクエリの単語たち?(aiの初期化)
        for i in range(len(self.wordids)):
            self.ai[i] = 1.0

        # 隠れ層の発火
        for j in range(len(self.hiddenids)):
            sum = 0.0
            for i in range(len(self.wordids)):
                # リンクの強度を掛け合わせる
                # TODO : なぜaiを使うのか。1.0直値ではいけない理由が不明
                # sum = sum + self.ai[j] * self.wi[i][j]
                sum = sum + 1.0 * self.wi[i][j]
            # tanhを適用して最終的な出力を作り出す
            self.ah[j] = tanh(sum)

        # 出力層の発火
        for k in range(len(self.urlids)):
            sum = 0.0
            for j in range(len(self.hiddenids)):
                sum = sum + self.ah[j] * self.wo[j][k]
            self.ao[k] = tanh(sum)

        return self.ao[:]
开发者ID:cy-shota-fukawa,项目名称:neural_network,代码行数:27,代码来源:nn.py

示例2: rho_harm

def rho_harm(x, xp, beta):
    # here upsilon_1 and upsilon_2 are just exponents
    Upsilon_1 = sum((x[d] + xp[d]) ** 2 / 4.0 * \
                    math.tanh(beta / 2.0) for d in range(3))
    Upsilon_2 = sum((x[d] - xp[d]) ** 2 / 4.0 / \
                    math.tanh(beta / 2.0) for d in range(3))
    return math.exp(- Upsilon_1 - Upsilon_2)
开发者ID:alexkcode,项目名称:StatMech,代码行数:7,代码来源:markov_harmonic_bosons.py

示例3: get_gm

 def get_gm(self, xxx_todo_changeme2, dev, debug=False):
     """Returns the source to output transconductance or d(I)/d(Vsn1-Vsn2)."""
     (vout, vin) = xxx_todo_changeme2
     self._update_status(vin, dev)
     gm = self.A * self.SLOPE * (math.tanh(self.SLOPE * (self.V - vin)) ** 2 - 1) / (
         self.A * math.tanh(self.SLOPE * (self.V - vin)) - self.B) ** 2
     return gm + options.gmin
开发者ID:B-Rich,项目名称:ahkab,代码行数:7,代码来源:switch.py

示例4: levy_harmonic_path

def levy_harmonic_path(k):
    x = [random.gauss(0.0, 1.0 / math.sqrt(2.0 * math.tanh(k * beta / 2.0)))]
    if k == 2:
        Ups1 = 2.0 / math.tanh(beta)
        Ups2 = 2.0 * x[0] / math.sinh(beta)
        x.append(random.gauss(Ups2 / Ups1, 1.0 / math.sqrt(Ups1)))
    return x[:]
开发者ID:borundev,项目名称:KrauthCourse,代码行数:7,代码来源:A1.py

示例5: compute

    def compute(self, plug, data):

        #   Check if output value is connected
        if plug == self.aOutputVaue:

            #    Get input datas
            operationTypeHandle = data.inputValue(self.aOperationType)
            operationType = operationTypeHandle.asInt()

            inputValueXHandle = data.inputValue(self.aInputValueX)
            inputValueX = inputValueXHandle.asFloat()

            inputValueYHandle = data.inputValue(self.aInputValueY)
            inputValueY = inputValueYHandle.asFloat()
            
            #   Math tanus
            outputValue = 0
            if operationType == 0:
                outputValue = math.atan(inputValueX)
            if operationType == 1:
                outputValue = math.tan(inputValueX)
            if operationType == 2:
                outputValue = math.atanh(inputValueX)
            if operationType == 3:
                outputValue = math.tanh(inputValueX)
            if operationType == 4:
                outputValue = math.tanh(inputValueY, inputValueX)

            #   Output Value
            output_data = data.outputValue(self.aOutputVaue)
            output_data.setFloat(outputValue)

        #   Clean plug
        data.setClean(plug)
开发者ID:AtonLerin,项目名称:Maya_Tools,代码行数:34,代码来源:QDTan.py

示例6: testHyperbolic

 def testHyperbolic(self):
     self.assertEqual(math.sinh(5), hyperbolic.sineh_op(5))
     self.assertEqual(math.cosh(5), hyperbolic.cosineh_op(5))
     self.assertEqual(math.tanh(5), hyperbolic.tangenth_op(5))
     self.assertEqual(1. / math.sinh(5), hyperbolic.cosecanth_op(5))
     self.assertEqual(1. / math.cosh(5), hyperbolic.secanth_op(5))
     self.assertEqual(1. / math.tanh(5), hyperbolic.cotangenth_op(5))
开发者ID:Eleanor320,项目名称:pygep,代码行数:7,代码来源:mathematical.py

示例7: set_eta1eta2

    def set_eta1eta2(self, eta1, eta2):
        eta=sqrt(eta1**2 + eta2**2)

        if eta==0.:
            self.e1,self.e2,self.g1,self.g2=(0.,0.,0.,0.)
            return

        etot=tanh(eta)
        gtot=tanh(eta/2.)

        if etot >= 1.0:
            mess="e values must be < 1, found %.16g" % etot
            raise ShapeRangeError(mess)
        if gtot >= 1.0:
            mess="g values must be < 1, found %.16g" % gtot
            raise ShapeRangeError(mess)

        cos2theta = eta1/eta
        sin2theta = eta2/eta

        e1=etot*cos2theta
        e2=etot*sin2theta

        g1=gtot*cos2theta
        g2=gtot*sin2theta

        self.eta1,self.eta2=eta1,eta2
        self.e1,self.e2=e1,e2
        self.g1,self.g2=g1,g2
开发者ID:esheldon,项目名称:espy,代码行数:29,代码来源:shear.py

示例8: feedforward

	def feedforward(self):
		""" the feedforward algorithm. This takes a list of inputs,
		pushes them through the network, and returns the output of all the nodes in the out
		put layer. In this case, since youve only constructed a network with words in the
		query, the output from all the input nodes will always be 1:
		"""
		# The only inputs are the query words
		for i in range(len(self.wordids)):
			self.ai[i] = 1.0

		# Hidden activations
		for j in range(len(self.hiddenids)):
			sum = 0.0
			for i in range(len(self.wordids)):
				sum =sum + self.ai[i] * self.wi[i][j]
			self.ah[j] = tanh(sum)

		# output activations
		for k in range(len(self.urlids)):
			sum = 0.0
			for j in range(len(self.hiddenids)):
				sum = sum + self.ah[j] * self.wo[j][k]
			self.ao[k] = tanh(sum)

		return self.ao[:]  # Return a copy of self.ao 
开发者ID:vencejo,项目名称:ActualCollectiveIntelligence,代码行数:25,代码来源:nn.py

示例9: rho_harm

def rho_harm(x, xp, beta):
    ''' Gives a diagonal harmonic density matrix, exchanging 2 particles '''
    Upsilon_1 = sum((x[d] + xp[d]) ** 2 / 4.0 *
                    math.tanh(beta / 2.0) for d in range(3))
    Upsilon_2 = sum((x[d] - xp[d]) ** 2 / 4.0 /
                    math.tanh(beta / 2.0) for d in range(3))
    return math.exp(- Upsilon_1 - Upsilon_2)
开发者ID:M0nd4,项目名称:statistical-mechanics-ens,代码行数:7,代码来源:homework_w7_b2.py

示例10: tanh

def tanh(self, other=None):
# Return hyperbolic tangent of interval
	
 	if other != None:
  		intv = IReal(self, other)
 	else:
  		if type(self) == float or type(self) == str:
   			intv = IReal(self)
  		else:
   			intv = self
 
 	if math.tanh(intv.inf) > math.tanh(intv.sup):
		inf = max(intv.inf, intv.sup)
		sup = min(intv.inf, intv.sup)
	else:
		inf = intv.inf
		sup = intv.sup


 	ireal.rounding.set_mode(1)

 	ireal.rounding.set_mode(-1)
 	ireal.rounding.set_mode(-1)

 	new_inf = math.tanh(inf)
 	ireal.rounding.set_mode(1)
	new_sup = max(float(IReal('%.16f' % math.tanh(sup)).sup), float(IReal('%.19f' % math.tanh(sup)).sup))

 	return IReal(new_inf, new_sup)
开发者ID:filipevarjao,项目名称:IntPy,代码行数:29,代码来源:stdfunc.py

示例11: Evap

	def Evap(self, p0, p1, t1, tau, beta, duration):
		"""Evaporation ramp"""
		if duration <=0:
			return
		else:
			N=int(round(duration/self.ss))
			print '...Evap nsteps = ' + str(N)
			ramp=[]
			ramphash = 'L:/software/apparatus3/seq/ramps/' + 'Evap_' \
					   + hashlib.md5(str(self.ss)+str(duration)+str(p0)+str(p1)+str(t1)+str(tau)+str(beta)).hexdigest()
			if not os.path.exists(ramphash):
				print '...Making new Evap ramp'
				for xi in range(N):
					t = (xi+1)*self.ss
					if t < t1:
						phys =  (p0-p1)*math.tanh( beta/tau * (t-t1)* p1/(p0-p1))/math.tanh( beta/tau * (-t1) * p1/(p0-p1)) + p1
					else:
						phys =   p1 * math.pow(1,beta) / math.pow( 1 + (t-t1)/tau ,beta)
					volt = cnv(self.name,phys)
					ramp = numpy.append( ramp, [ volt])
				ramp.tofile(ramphash,sep=',',format="%.4f")
			else:
				print '...Recycling previously calculated Evap ramp'
				ramp = numpy.fromfile(ramphash,sep=',')

			self.y=numpy.append(self.y,ramp)
			
		return
开发者ID:PedroMDuarte,项目名称:apparatus3-seq,代码行数:28,代码来源:wfm_.py

示例12: skill_variation

 def skill_variation(self, K, V):
     """calcola la variazione di skill dei players K e V in seguito alla kill"""
     if self.PT[V].team == 3:
         return  # A volte viene killato qualcuno che risulta spect
     D = self.PT[K].skill - self.PT[V].skill  # Delta skill tra i due player
     Dk = self.PT[K].skill - self.TeamSkill[(self.PT[V].team - 1)]  # Delta skill Killer rispetto al team avversario
     Dv = self.TeamSkill[(self.PT[K].team - 1)] - self.PT[V].skill  # Delta skill Vittima rispetto al team avversario
     K_opponent_variation = (
         1 - math.tanh(D / self.Sk_range)
     ) / self.Sk_Kpp  # Variazione skill del Killer in base a skill vittima
     V_opponent_variation = (
         2 / self.Sk_Kpp - K_opponent_variation
     )  # Variazione skill della Vittima in base a skill killer
     KT_variation = (
         1 - math.tanh(Dk / self.Sk_range)
     ) / self.Sk_Kpp  # Variazione skill del Killer in base a skill team vittima
     VT_variation = (
         -(1 - math.tanh(Dv / self.Sk_range)) / self.Sk_Kpp
     )  # Variazione skill della Vittima in base a skill team killer
     Dsk_K = self.Sbil * (
         self.Sk_team_impact * KT_variation + (1 - self.Sk_team_impact) * K_opponent_variation
     )  # delta skill del Killer
     Dsk_V = self.Sbil * (
         self.Sk_team_impact * VT_variation + (1 - self.Sk_team_impact) * V_opponent_variation
     )  # delta skill della vittima
     self.PT[K].skill += Dsk_K * self.PT[K].skill_coeff  # (nuova skill)
     self.PT[V].skill += Dsk_V * self.PT[V].skill_coeff  # (nuova skill)
     self.PT[K].skill_var += Dsk_K  # variazione skill per mappa
     self.PT[V].skill_var += Dsk_V  # variazione skill per mappa
     return
开发者ID:Satish-Lakhani,项目名称:redcap,代码行数:30,代码来源:C_GSRV.py

示例13: feedforward

    def feedforward(self):
        # the only inputs are the query words
        for i in range(len(self.wordids)):
            self.ai[i] = 1.0
            # hidden activations

        for j in range(len(self.hiddenids)):
            sum = 0.0

            for i in range(len(self.wordids)):

                sum = sum + self.ai[i] * self.wi[i][j]

            self.ah[j] = tanh(sum) * 10

            # output activations
        for k in range(len(self.urlids)):
            sum = 0.0

            for j in range(len(self.hiddenids)):

                sum = sum + self.ah[j] * self.wo[j][k]

            self.ao[k] = tanh(sum)

        return self.ao[:]
开发者ID:obengwilliam,项目名称:searchjob,代码行数:26,代码来源:neural_network.py

示例14: feed_forward

    def feed_forward(self):
        '''
        This returns the output of all the output nodes, with the inputs
        coming from the setup_network function.
        '''
        # first it sets the input word weights to 1.0
        for i in xrange(len(self.word_ids)):
            self.ai[i] = 1.0

        # then it iterates through all of the hidden nodes associated with
        # the words and urls (query and results) and uses a sigmoid to
        # accumulate the weights coming from the inputs (ai) and the
        # input weight matrix (wi) for each word-hidden_node relation.
        for j in xrange(len(self.hidden_ids)):
            sum = 0.0
            for i in xrange(len(self.word_ids)):
                sum = sum + self.ai[i] * self.wi[i][j]
            self.ah[j] = tanh(sum)

        # finally it iterates through all of the output nodes (urls)
        # and uses a sigmoid function to accumulate the weights
        # coming from the hidden nodes (ah) updated in the
        # previous step and the output weights (wo) for each
        # hidden_node-url relation.
        for k in xrange(len(self.url_ids)):
            sum = 0.0
            for j in xrange(len(self.hidden_ids)):
                sum = sum + self.ah[j] * self.wo[j][k]
            self.ao[k] = tanh(sum)

        return self.ao[:]
开发者ID:nholtappels,项目名称:collective_intelligence_examples,代码行数:31,代码来源:nn.py

示例15: we_context_mod

def we_context_mod(w, v, words,phrases,rep):
    w = deepcopy(w)
    v = deepcopy(v)
    for repet in range(rep):
        for o in range(len(words)):
            print o, ' of ', len(words)
            # h = np.zeros(prof)
            # for pal in phrases[c].split():
            #     h += v[words.index(pal)]
            # div = 0.0
            # for aux in w:
            #     div += math.exp(-1 * math.tanh(np.dot(aux, h)))
            for c in range(len(phrases)):
                ##
                h = np.zeros(prof)
                for pal in phrases[c].split():
                    h += v[words.index(pal)]
                div = 0.0
                for aux in w:
                    div += math.exp(-1 * math.tanh(np.dot(aux, h)))
                ##

                poc = math.exp(-1 * math.tanh(np.dot(w[o],h))) / div
                err = 0.0
                if words[o] in phrases[c]:
                    err = 1 - poc
                else:
                    err = 0 - poc

                v[o] = v[o] - (eta * err * h)

            for word in phrases[c].split():
                w[words.index(word)] -=  (eta * sum(v) / len(phrases[c].split()))

    return {'w': w, 'v':v}
开发者ID:jaradricc,项目名称:Metodos-analiticos-para-texto-Tarea5,代码行数:35,代码来源:word_embeddings.py


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