简体   繁体   English

如何在python中制作感知器的伪代码?

[英]how to make pseudocode of perceptron in python?

This code was written in python 3, could you tell me what your pseudocode would look like?这段代码是用 python 3 编写的,你能告诉我你的伪代码是什么样的吗? I can not understand the calculations that are being made:我无法理解正在进行的计算:

#dobro n * 2
# x * weight

import random
import numpy as np

   def derivada(n):
        return n*(1-n)

x = 0.85 
y = 0.25
w = random.random()

#épocas

for i in range(10):
     a=np.tanh(x*w)

     e = y-a#erro

     w+= x* derivada(e)

     print(a)

I tried to do the pseudocode this way, but it's not working too well.我尝试以这种方式执行伪代码,但效果不佳。

     algoritm "untitled"

            var
                er, n, f, x1, w1, w2, u, y : real
                                  b, yd, i : inteiro
           Begin
               b <- 1
               x1 <- 1
               w1 <- 0
               u <- (x1*w1)+b
               y <- tan(u)
               yd <- 5
               er <- yd-y
               for i de 1 to 10 do
               n <- 0.5
               f <- (n*x1*er)
               w1 <- w1+f
               Write(w1)
               endfor

               // Commands
          End

Can you tell me what's wrong?你能告诉我有什么问题吗?

Basically, what's happening is you have these variables:基本上,发生的事情是你有这些变量:

x - Input value to perceptron x - 感知器的输入值

y - Expected output from perceptron y - 感知器的预期输出

w - Weight value on perceptron w - 感知器的权重值

The derivato(n) function returns the derivative of the tanh curve. derivato(n)函数返回 tanh 曲线的导数。 This is used to calculate the adjustment to the w variable.这用于计算对w变量的调整。

x is set to 0.85, y is set to 0.25. x设置为 0.85, y设置为 0.25。 w is initialized to a random number. w被初始化为一个随机数。

10 times, a is the output of the perceptron. 10 次, a是感知器的输出。 This is equal to tanh(x*w) where x is the input, w is the weight, and tanh being the tanh function.这等于tanh(x*w) ,其中x是输入, w是权重, tanh是 tanh 函数。

The error ( e variable) is calculated by doing ya , where y is the expected output.通过执行ya计算误差( e变量),其中 y 是预期输出。 (the ground truth) (基本事实)

The adjustment to the weight ( w ) is calculated by calculating the derivative of the tanh curve at e and multiplying by x .权重 ( w ) 的调整是通过计算 tanh 曲线在e处的导数并乘以x来计算的。 So the adjustment is x*derivato(e)所以调整是x*derivato(e)

Then, the adjustment is added to the weight, to adjust it.然后,将调整添加到权重,以对其进行调整。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM