python sdm0718由HiKat1创建 - https://repl.it/JaLD/7
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python sdm0718由HiKat1创建 - https://repl.it/JaLD/7相关的知识,希望对你有一定的参考价值。
#!/usr/bin/env python
# coding:utf-8
#
# use Python3 !!!
#
import math
# import numpy as np
LEAERNING_RATE = 0.1
b1 = 8
b2 = 2
b3 = 0
w11 = (b2 + 1.0) / 10.0
w12 = -1.0 * (b3 + 1.0) / 10.0
w13 = (b1 + 1.0) / 10.0
w14 = (b3 + 1.0) / 10.0
w21 = -1.0 * (b1 + 1.0) / 10.0
w22 = -1.0 * (b2 + 1.0) / 10.0
# 順伝搬計算
def forward_backward_update(x1, x2, y):
global w11
global w12
global w13
global w14
global w21
global w22
# 順伝搬計算
a2 = x1 * w11 + x2 * w13
a3 = x1 * w12 + x2 * w14
a1 = math.tanh(a2) * w21 + math.tanh(a3) * w22
y_dash = math.tanh(a1)
# 逆伝搬計算
delta1 = -1.0 * (y - math.tanh(a1)) * (1.0 - pow(math.tanh(a1), 2))
delta2 = delta1 * w21 * (1.0 - pow(math.tanh(a2), 2))
delta3 = delta1 * w22 * (1.0 - pow(math.tanh(a3), 2))
# 勾配計算
grad_w11 = delta2 * x1
grad_w12 = delta3 * x1
grad_w13 = delta2 * x2
grad_w14 = delta3 * x2
grad_w21 = delta1 * math.tanh(a2)
grad_w22 = delta1 * math.tanh(a3)
# 勾配更新
w11 = w11 + LEAERNING_RATE * -1.0 * grad_w11
w12 = w12 + LEAERNING_RATE * -1.0 * grad_w12
w13 = w13 + LEAERNING_RATE * -1.0 * grad_w13
w14 = w14 + LEAERNING_RATE * -1.0 * grad_w14
w21 = w21 + LEAERNING_RATE * -1.0 * grad_w21
w22 = w22 + LEAERNING_RATE * -1.0 * grad_w22
return [y_dash, w11, w12, w13, w14, w21, w22]
print("Answer Q1 ================================")
print('w11 = {0} ,w13 = {1}, w21 = {2}'.format(w11, w13, w21))
print('w12 = {0} ,w14 = {1}, w22 = {2}'.format(w12, w14, w22))
print("Answer Q2 ================================")
temp = []
temp = forward_backward_update(1.0, 1.0, 1.0)
print("y' = " + str(temp[0]))
print('w11 = {0} ,w13 = {1}, w21 = {2}'.format(temp[1], temp[3], temp[5]))
print('w12 = {0} ,w14 = {1}, w22 = {2}'.format(temp[2], temp[4], temp[6]))
print("Answer Q3 ================================")
temp = []
temp = forward_backward_update(0, 1.0, -1.0)
print("y' = " + str(temp[0]))
print('w11 = {0} ,w13 = {1}, w21 = {2}'.format(temp[1], temp[3], temp[5]))
print('w12 = {0} ,w14 = {1}, w22 = {2}'.format(temp[2], temp[4], temp[6]))
print("Answer Q4 ================================")
temp = []
temp = forward_backward_update(0, 0, 1.0)
print("y' = " + str(temp[0]))
print('w11 = {0} ,w13 = {1}, w21 = {2}'.format(temp[1], temp[3], temp[5]))
print('w12 = {0} ,w14 = {1}, w22 = {2}'.format(temp[2], temp[4], temp[6]))
print("Answer Q5 ================================")
temp = []
temp = forward_backward_update(1.0, 0, -1.0)
print("y' = " + str(temp[0]))
print('w11 = {0} ,w13 = {1}, w21 = {2}'.format(temp[1], temp[3], temp[5]))
print('w12 = {0} ,w14 = {1}, w22 = {2}'.format(temp[2], temp[4], temp[6]))
以上是关于python sdm0718由HiKat1创建 - https://repl.it/JaLD/7的主要内容,如果未能解决你的问题,请参考以下文章
python sdm0725由HiKat1创建 - https://repl.it/JmMo/2
python HiKat1创建的sdm0711-with-graph.py - https://repl.it/J59N/1
python CRF-SDM
Intel SDM Chapter 10: APIC
在GNS3下使用Cisco SDM 的教程
qualcomm sdm450 tinymix mic record