本文整理汇总了Python中math.tanh函数的典型用法代码示例。如果您正苦于以下问题:Python tanh函数的具体用法?Python tanh怎么用?Python tanh使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了tanh函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: _zoom_animation
def _zoom_animation(self):
import time
from math import tanh
scale = 5
for i1 in range(-scale, scale+1):
self.replot(zlfrac=0.5 + 0.5*tanh(i1*2.0/scale)/tanh(2.0))
self.c.update()
开发者ID:pigboysid,项目名称:myat,代码行数:7,代码来源:canvas.py
示例17: feedForward
def feedForward(self):
nIn = len(self.wordIds)
nHidden = len(self.hiddenIds)
nOut = len(self.urlIds)
# the only inputs are the query words
for i in range(nIn):
self.wordOut[i] = 1.0
# hidden activations
for i in range(nHidden):
sum = 0.0
for j in range(nIn):
sum += self.wordOut[j] * self.wordHidden[j][i]
self.hiddenOut[i] = tanh(sum)
# output activations
for i in range(nOut):
sum = 0.0
for j in range(nHidden):
sum += self.hiddenOut[j] * self.hiddenUrl[j][i]
self.urlOut[i] = tanh(sum)
return self.urlOut[:]
开发者ID:ArtanisCV,项目名称:Mercury,代码行数:28,代码来源:neuralNetwork.py
示例18: getallhiddenids
def getallhiddenids(self,wordids,urlids):
l1={}
for wordid in wordids:
cur=self.con.execute('select toid from wordhidden where from id=%d'% wordid)
for row in cur: l1[row[0]=1
for urlid in urlids:
cur=self.con.select('select fromid from hiddenurl where toid=%d'% urlid)
for row in cur:l1[row[0]]=1
return l1.keys()
def setupnetwork(self,wordids,urlids):
self.wordids=wordids
self.hiddenids=self.getallhiddenids(wordids,urlids)
self.urlids=self.urlids
self.ai=[1.0]*len(self.wordids)
self.ah=[1.0]*len(self.hiddenids)
self.ao=[1.0]*len(self.urlids)
self.wi=[[self.getstrength(wordid,hiddenid,0) for hiddenid in self.hiddenids] for wordid in self.wordids]
self.wo=[[self.getstrenth(hiddenid,urlid,1) for urlid in self.urlids]for hiddenid in self.hiddenids]
def feedforward(self):
for i in range(len(self.wordids)):
self.ai[i]=1
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)
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[:]
def getresult(self,wordids,urlids):
self.setupnetwork(wordids,urlids)
return self.feedforward()
def dtanh(y):
return 1.0-y*y
def backPropagete(self,targets,N=0.5):
output_deltas=[0.0]*len(self.urlids)
for k in range(len(self.urlids)):
error=targets[k]-self.ao[k]
output_deltas=dtanh(self.ao[k]])*error
hidden_deltas=[0.0]*len(self.hiddenids)
for j in range(len(self.hidddenids)):
error=0.0
for k in range(len(self.len(urlids))):
error=error+output[k]*self.wo[j][k]
hidden_deltas[j]=dtanh(self.ah[j])*error
for j in range(len(self.hiddenids)):
for k in range(len(self.urlids)):
change = output_delta[k]*self.ah[j]
self.wo[j][k]=self.wo[j][k]+N*change
for i in range(len(self.wordids)):
for j in range(len(self.hiddenids)):
change=hidden_delta[j]*self.ai[i]
self.wi[i][j]=self.wi[i][j]+N*change
开发者ID:tfka,项目名称:python_code,代码行数:59,代码来源:nn.py
示例19: score
def score(filename):
"""
Score individual image files for the genetic algorithm.
The idea is to derive predictive factors for the langmuir performance
(i.e., max power) based on the connectivity, phase fractions, domain sizes,
etc. The scoring function should be based on multivariate fits from a database
of existing simulations. To ensure good results, use robust regression techniques
and cross-validate the best-fit.
:param filename: image file name
:type filename: str
:return score (ideally as an estimated maximum power in W/(m^2))
:rtype float
"""
# this works around a weird bug in scipy.misc.imread with 1-bit images
# open them with PIL as 8-bit greyscale "L" and then convert to ndimage
pil_img = Image.open(filename)
image = misc.fromimage(pil_img.convert("L"))
width, height = image.shape
if width != 256 or height != 256:
print "Size Error: ", filename
# isize = analyze.interface_size(image)
ads1, std1 = analyze.average_domain_size(image)
# we now need to invert the image to get the second domain size
inverted = (image < image.mean())
ads2, std2 = analyze.average_domain_size(inverted)
#overall average domain size
ads = (ads1 + ads2) / 2.0
# transfer distances
# connectivity
td1, connect1, td2, connect2 = analyze.transfer_distance(image)
spots = np.logical_xor(image,
ndimage.binary_erosion(image, structure=np.ones((2,2))))
erosion = np.count_nonzero(spots)
spots = np.logical_xor(image,
ndimage.binary_dilation(image, structure=np.ones((2,2))))
dilation = np.count_nonzero(spots)
# fraction of phase one
nonzero = np.count_nonzero(image)
fraction = float(nonzero) / float(image.size)
# scores zero at 0, 1 and maximum at 0.5
ps = fraction*(1.0-fraction)
# from simulations with multivariate nonlinear regression
return (-1.98566e8) + (-1650.14)/ads + (-680.92)*math.pow(ads,0.25) + \
1.56236e7*math.tanh(14.5*(connect1 + 0.4)) + 1.82945e8*math.tanh(14.5*(connect2 + 0.4)) \
+ 2231.32*connect1*connect2 \
+ (-4.72813)*td1 + (-4.86025)*td2 \
+ 3.79109e7*ps**8 \
+ 0.0540293*dilation + 0.0700451*erosion
开发者ID:JoshuaSBrown,项目名称:langmuir,代码行数:59,代码来源:ga.py
示例20: distance_Sigmoid
def distance_Sigmoid(X,Y,a,r):
d = np.dot(X,X)
d = math.tanh(a * d + r)
b = np.dot(Y,Y)
b = math.tanh(a * b + r)
c = np.dot(X,Y)
c = math.tanh(a * c + r)
return a + b - 2 * c
开发者ID:wangfengfighting,项目名称:GPS_Similar,代码行数:8,代码来源:sciencecluster.py
注:本文中的math.tanh函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论