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

Python neuron.Neuron类代码示例

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

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



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

示例1: test_update_weights

    def test_update_weights(self):
        neuron = Neuron(0, 0, [0.05, 0.05], [0.519053, 1])
        neuron.delta_val = -0.1295578
        neuron.update_weights(0.001)

        self.assertEquals(0.0499327526, round(neuron.weights[0], 10))
        self.assertEquals(0.0498704, round(neuron.weights[1], 7))
开发者ID:jcow,项目名称:Machine-Learning-Projects,代码行数:7,代码来源:test.py


示例2: test_set_error_output_layer

    def test_set_error_output_layer(self):
        neuron = Neuron(0, 0, [0.05, 0.05], [1, 1])
        neuron.output = 0.518979
        neuron.is_output_layer = True
        neuron.set_output_layer_error(0)

        self.assertEquals(-0.12955, round_to(neuron.delta_val, 5))
开发者ID:jcow,项目名称:Machine-Learning-Projects,代码行数:7,代码来源:test.py


示例3: test_step_true

    def test_step_true(self):
        neuron = Neuron(
            weights=[1, 2, 3],
            transfer_function=StepTransferFunction,
        )

        self.assertEqual(neuron.run([1, 2, 3]), 1)
开发者ID:rpedigoni,项目名称:am2,代码行数:7,代码来源:test.py


示例4: Perceptron

class Perceptron(object):
    def __init__(self, input_size, lrn_rate=1):
        """'input_size' is the length of the input.
        'lrn_rate' is the learning rate.
        """
        self.neuron = Neuron([0]*input_size, 0, signal)
        self.lrn_rate = lrn_rate
        self.fire = self.neuron.fire

    def training(self, examples):
        epochs = 0

        while True:
            epochs = epochs + 1
            error_count = 0

            for (input_vector, desired_output) in examples:
                actual_output = self.neuron.fire(input_vector)
                error = desired_output - actual_output

                if error != 0:
                    learned = self.lrn_rate*error
                    self.neuron.update(input_vector, learned)
                    error_count = error_count + 1

            if error_count == 0:
                break

        return epochs

    def __str__(self):
        ret = 'lrn_rate: %s' % self.lrn_rate
        ret = '%s\n%s' % (ret, self.neuron.__str__())
        return ret
开发者ID:embatbr,项目名称:The-Men-Who-Stare-at-Codes,代码行数:34,代码来源:perceptron.py


示例5: testSinglePreviousEvaluate

	def testSinglePreviousEvaluate(self):
		previousNeuron = InputNeuron()
		previousNeuron.setValue(1)
		previousRow = [previousNeuron]
		
		neuron = Neuron(previousRow)
		self.assertGreater(neuron.evaluate(), 1/2)
开发者ID:AxelUlmestig,项目名称:NeuralNetwork,代码行数:7,代码来源:test.py


示例6: test_step_false

 def test_step_false(self):
     neuron = Neuron(
         weights=[1, 2, 3],
         transfer_function=StepTransferFunction,
         function=lambda p: p >= 7,  # any function can be used here
     )
     self.assertEqual(neuron.run([1, 1, 1]), 0)
开发者ID:rpedigoni,项目名称:am2,代码行数:7,代码来源:test.py


示例7: test_integrator

    def test_integrator(self):
        neuron = Neuron(
            weights=[1, 2, 3],
            transfer_function=BaseTransferFunction,  # does nothing
        )

        self.assertEqual(neuron.integrator([1, 1, 1]), 6)
开发者ID:rpedigoni,项目名称:am2,代码行数:7,代码来源:test.py


示例8: add_layer

    def add_layer(self, neurons, layer_number):
        """

        :param neurons:
        :param layer_number:
        :return:
        """
        bias_value = random.randint(1,10)
        bias = Neuron(activation_func=lambda x: 0, activation_prime=lambda x: 0, isBias=True)
        bias.y_output = bias_value

        neurons.append(bias)
        self.layers[layer_number] = neurons

        if layer_number == 0:
            return

        if layer_number > self.max_layer:
            self.max_layer = layer_number

        for input in self.layers[layer_number - 1]:
            for output in neurons:
                output.add_input_reference(input)

                if not output.isBias:
                    weight = self.randomize_weight()
                    input.add_output_connection(output, weight)
开发者ID:teberger,项目名称:neural_networks,代码行数:27,代码来源:neural_network.py


示例9: test_sigmoid

    def test_sigmoid(self):
        neuron = Neuron(
            weights=[1, 2, 3],
            transfer_function=SigmoidTransferFunction,
        )

        v = neuron.run([0, 0, 0])
        self.assertEqual(v, 0.5)
开发者ID:rpedigoni,项目名称:am2,代码行数:8,代码来源:test.py


示例10: loadmat

 def loadmat(self):
     """Load neurons from a single .mat file"""
     self.header = MATHeader()
     nrecs = self.header.read(self.path)
     for nrec in nrecs:
         neuron = Neuron(self.path, sort=self)
         neuron.loadmat(nrec)
         self.alln[neuron.id] = neuron # save it
开发者ID:neuropy,项目名称:neuropy,代码行数:8,代码来源:sort.py


示例11: load

    def load(path):
        """
            Loads a neural network from a json file
            @param (String) path - The path to load the neural network from
            @returns (Network) - The neural network that was loaded
        """
        network = Network()

        try:
            with open(path, "r+") as f:
                network_data = "\n".join(f.readlines())
                network_json = json.loads(network_data)
                layers = network_json["layers"]
                
                # For every layer in the network ...
                for layer in layers:
                    neurons = []

                    # For every neuron in the layer ...
                    for neuron in layer["neurons"]:
                        weights = neuron["weights"]
                        bias = neuron["bias"]
                        activation = neuron["activation"]

                        # Choose the proper activation function and corresponding derivative
                        activation_func = None
                        derivative_func = None
                        if activation == Network.LINEAR:
                            activation_func = Network.ACTIVATION_LINEAR
                            derivative_func = Network.DERIVATIVE_LINEAR
                        elif activation == Network.SIGMOID:
                            activation_func = Network.ACTIVATION_SIGMOID
                            derivative_func = Network.DERIVATIVE_SIGMOID
                        elif activation == Network.TANH:
                            activation_func = Network.ACTIVATION_TANH
                            derivative_func = Network.DERIVATIVE_TANH
                        elif activation == Network.STEP:
                            activation_func = Network.ACTIVATION_STEP
                            derivative_func = Network.DERIVATIVE_STEP

                        # Create a neuron with the desired info
                        neuron = Neuron(0, activation_func, derivative_func)
                        neuron.weights = weights
                        neuron.bias = bias
                        
                        # Add the processed neuron to the collection
                        neurons.append(neuron)

                    # Create a layer with the desired neurons
                    layer = Layer(0, 0, None, None)
                    layer.neurons = neurons
                    
                    # Add the processed layer to the collection
                    network.layers.append(layer)
        except:
            raise Exception("Invalid Neural Network File @ {}!".format(path))

        return network
开发者ID:XxZ350xX,项目名称:Neural-Network,代码行数:58,代码来源:network.py


示例12: loadptcs

 def loadptcs(self):
     """Load neurons from a single .ptcs file"""
     self.header = PTCSHeader()
     with open(self.path, 'rb') as f:
         self.header.read(f)
         for i in range(self.header.nneurons):
             neuron = Neuron(self.path, sort=self)
             neuron.loadptcs(f, self.header)
             self.alln[neuron.id] = neuron # save it
         assert eof(f), 'File %s has unexpected length' % self.path
开发者ID:neuropy,项目名称:neuropy,代码行数:10,代码来源:sort.py


示例13: init

    def init(self, neurons_num=3, inputs=3, activation_function="sigmoid"):
        self.inputs_num = inputs
        self.neurons_num = neurons_num
        self.activation_function = activation_function

        self.neurons = []
        for i in range(self.neurons_num):
            neuron = Neuron()
            neuron.init(self.inputs_num, self.activation_function)
            self.neurons.append(neuron)
开发者ID:ansaev,项目名称:neural_network,代码行数:10,代码来源:layer.py


示例14: test_1

def test_1(steps):
    weights = 3
    print "Linear combination of weights {0}, {1} steps".format(weights, steps)
    neuron = Neuron(weights, sigm, sigmp, error)
    errors = []
    for i in range(steps):
        inputs = [random.random() for r in range(weights)]
        target = 2*inputs[0] + 0.3*inputs[1] - 0.7*inputs[2]
        neuron.learn_1(inputs, target)
        errors.append(neuron.last_error)
    print report(errors)
开发者ID:rylans,项目名称:nn-from-scratch,代码行数:11,代码来源:neuron_test.py


示例15: test_feed_forward

    def test_feed_forward(self):
        neuron = Neuron(0, 0, [0.05, 0.05], [1, 1])
        next_node1 = Neuron(0, 0, [0.05, 0.05], [0, 0])
        next_node2 = Neuron(0, 0, [0.05, 0.05], [0, 0])
        nodes = [next_node1, next_node2]
        neuron.feed_forward(nodes)

        self.assertEquals(0.524, round_to(nodes[0].inputs[0], 3))
        self.assertEquals(0, round_to(nodes[0].inputs[1], 3))
        self.assertEquals(0.524, round_to(nodes[1].inputs[0], 3))
        self.assertEquals(0, round_to(nodes[1].inputs[1], 3))
开发者ID:jcow,项目名称:Machine-Learning-Projects,代码行数:11,代码来源:test.py


示例16: __init__

 def __init__(self, size, dt=0.001, tau_rc=0.02, tau_ref=0.002):
     """Constructor for a set of LIF rate neuron
     
     :param int size: number of neurons in set
     :param float dt: timestep for neuron update function
     :param float t_rc: the RC time constant 
     :param float tau_ref: refractory period length (s)
     """
     Neuron.__init__(self, size, dt)
     self.tau_rc = tau_rc
     self.tau_ref = tau_ref
开发者ID:Elhamahm,项目名称:nengo_1.4,代码行数:11,代码来源:lif_rate.py


示例17: test_3

def test_3(steps):
    weights = 1
    print "Target converse {0}, {1} steps".format(weights, steps)
    neuron = Neuron(weights, sigm, sigmp, error)
    errors = []
    for i in range(steps):
        inputs = [random.random() for r in range(weights)]
        target = 1.0 - inputs[0]
        neuron.learn_1(inputs, target)
        errors.append(neuron.last_error)
    print report(errors)
开发者ID:rylans,项目名称:nn-from-scratch,代码行数:11,代码来源:neuron_test.py


示例18: test_5

def test_5(steps):
    weights = 40
    print "Target sqrt(avg) {0}, {1} steps".format(weights, steps)
    neuron = Neuron(weights, sigm, sigmp, error)
    errors = []
    for i in range(steps):
        inputs = [random.random() for r in range(weights)]
        avg = sum(inputs)/len(inputs)
        target = math.sqrt(avg)
        neuron.learn_1(inputs, target)
        errors.append(neuron.last_error)
    print report(errors)
开发者ID:rylans,项目名称:nn-from-scratch,代码行数:12,代码来源:neuron_test.py


示例19: __init__

class ProgramLogic:
    def __init__(self):
        parser.parseFile()

        self.neuron = Neuron(self.inputCount())
        self.neuron.randomize(-1.0, 1.0)
        self.teachingStep = 0
        self.prevResponse = 0
        self.prevError = 0
        self.curResponse = 0
        self.curError = 0

    def inputCount(self):
        return parser.counts[parser.inputCount]

    def performTeaching(self, teachingRatio):
        resultPrev = self.neuron.learn(self.currentNormalizedInputs(), self.currentExpectedOutput(), teachingRatio)
        self.prevResponse = resultPrev[Neuron.prevResponse]
        self.prevError = resultPrev[Neuron.prevError]
        self.curResponse = self.neuron(self.currentNormalizedInputs())
        self.curError = self.currentExpectedOutput - self.curResponse

        self.teachingStep += 1

    def currentComment(self):
        return parser.elements[self.realIndex()][parser.comment]

    def currentExpectedOutput(self):
        return parser.elements[self.realIndex()][parser.expectedOutputs][0]

    def currentInputs(self):
        return parser.elements[self.realIndex()][parser.inputs]

    def currentNormalizedInputs(self):
        return Neuron.normalize(self.currentInputs())

    def currentPrevWeights(self):
        return self.neuron.weights

    def currentPrevResponse(self):
        return self.prevResponse

    def currentPrevError(self):
        return self.prevError

    def currentResponse(self):
        return self.curResponse

    def currentError(self):
        return self.curError

    def realIndex(self):
        return self.teachingStep % len(parser.inputs)
开发者ID:kissofblood,项目名称:neuron,代码行数:53,代码来源:programlogic.py


示例20: test_4

def test_4(steps):
    weights = 40
    print "Target max - min {0}, {1} steps".format(weights, steps)
    neuron = Neuron(weights, sigm, sigmp, error)
    errors = []
    for i in range(steps):
        inputs = [random.random() for r in range(weights)]
        imax = max(inputs)
        imin = min(inputs)
        target = imax - imin
        neuron.learn_1(inputs, target)
        errors.append(neuron.last_error)
    print report(errors)
开发者ID:rylans,项目名称:nn-from-scratch,代码行数:13,代码来源:neuron_test.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python h.allsec函数代码示例发布时间:2022-05-27
下一篇:
Python neuron.h函数代码示例发布时间: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