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


Python Tools.tanh方法代码示例

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


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

示例1: __init__

# 需要导入模块: from Tools import Tools [as 别名]
# 或者: from Tools.Tools import tanh [as 别名]
class Neuron:
    def __init__(self, numberOutputs, index):
        self.outputVal = 0.0
        self.index = index
        self.gradient = 0.0
        self.learningRate = 0.15
        self.alpha = 0.1
        self.tools = Tools()

        # for the neuron thas this neuron will feeds
        # Array of Connections
        self.outputWeights = []

        for i in range(0, numberOutputs):
            self.outputWeights.append(Connection())
            self.outputWeights[i].weight = self.randomWeight()
            #print self.outputWeights[i].weight

    def __repr__(self):
        return "Neuron : index = " + str(self.index) + ", outputVal = " + str(self.outputVal) + "\n" # + ", Connections : " + str(self.outputWeights) 
    def __str__(self):
        return self.__repr__()
    
    def feedForward(self, prevLayer):
        # Sum the previous layer's ouputs (which are our inputs)
        # Include the bias node from the previous layer

        sum = 0.0
    
        for i in range(0, len(prevLayer)):
            sum += prevLayer[i].outputVal * prevLayer[i].outputWeights[self.index].weight

        # update the outputVal
        self.outputVal = self.activationFunction(sum)
    
    def activationFunction(self, x):
        #return self.tools.sigmoid(x)
        return self.tools.tanh(x)

    def activationFunctionDerivative(self, x):
        #return self.tools.sigmoidDerivative(x)
        return self.tools.tanhDerivative(x)

    def randomWeight(self):
        return random.uniform(0.0, 1.0)

    def calcOutputGradients(self, targetVal):
        delta = targetVal - self.outputVal
        self.gradient = delta * self.activationFunctionDerivative(self.outputVal) 
    def calcHiddenGradients(self, nextLayer):
        dow = self.sumDow(nextLayer)
        self.gradient = dow * self.activationFunctionDerivative(self.outputVal)
    def sumDow(self, nextLayer):
        sum = 0.0

        for i in range(0, len(nextLayer) - 1):
            sum += (self.outputWeights[i].weight * nextLayer[i].gradient)
        return sum

    def updateInputWeights(self, prevLayer):
        for i in range(0, len(prevLayer)):
            neuron = prevLayer[i]
            oldDeltaWeight = neuron.outputWeights[self.index].deltaWeight
            newDeltaWeight = self.learningRate * neuron.outputVal * self.gradient + self.alpha * oldDeltaWeight
            neuron.outputWeights[self.index].deltaWeight = newDeltaWeight
            neuron.outputWeights[self.index].weight += newDeltaWeight
开发者ID:gmpetrov,项目名称:nn-py,代码行数:68,代码来源:Neuron.py


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