如何在python中制作感知器的伪代码?
how to make pseudocode of perceptron in python?
这段代码写在python 3,你能告诉我你的伪代码是什么样的吗?我无法理解正在进行的计算:
#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)
我试过用这种方法做伪代码,但效果不太好。
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
你能告诉我哪里出了问题吗?
基本上,发生的事情是你有这些变量:
x
- 感知器的输入值
y
- 感知器的预期输出
w
- 感知器上的权重值
derivato(n)
函数returnstanh曲线的导数。这用于计算对 w
变量的调整。
x
设置为0.85,y
设置为0.25。 w
初始化为随机数。
10次,a
就是感知机的输出。这等于 tanh(x*w)
,其中 x
是输入,w
是权重,tanh
是 tanh 函数。
错误(e
变量)是通过y-a
计算得出的,其中 y 是预期的输出。 (基本事实)
对权重的调整(w
)是通过计算tanh曲线在e
处的导数并乘以x
计算出来的。所以调整为x*derivato(e)
然后,将调整添加到权重,以进行调整。
这段代码写在python 3,你能告诉我你的伪代码是什么样的吗?我无法理解正在进行的计算:
#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)
我试过用这种方法做伪代码,但效果不太好。
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
你能告诉我哪里出了问题吗?
基本上,发生的事情是你有这些变量:
x
- 感知器的输入值
y
- 感知器的预期输出
w
- 感知器上的权重值
derivato(n)
函数returnstanh曲线的导数。这用于计算对 w
变量的调整。
x
设置为0.85,y
设置为0.25。 w
初始化为随机数。
10次,a
就是感知机的输出。这等于 tanh(x*w)
,其中 x
是输入,w
是权重,tanh
是 tanh 函数。
错误(e
变量)是通过y-a
计算得出的,其中 y 是预期的输出。 (基本事实)
对权重的调整(w
)是通过计算tanh曲线在e
处的导数并乘以x
计算出来的。所以调整为x*derivato(e)
然后,将调整添加到权重,以进行调整。