แปลงโค้ดไพธอนเป็นกิจกรรม Activity Diagram ยังไงครับ

แนะนำ สอบถาม ภาษา C สำหรับผู้เริ่มต้น ภาษา Java ภาษา Python

Moderator: mindphp, ผู้ดูแลกระดาน

ภาพประจำตัวสมาชิก
Kum Wa Hluk
PHP Newbie
PHP Newbie
โพสต์: 2
ลงทะเบียนเมื่อ: 08/07/2018 2:03 pm

แปลงโค้ดไพธอนเป็นกิจกรรม Activity Diagram ยังไงครับ

โพสต์โดย Kum Wa Hluk » 08/07/2018 2:09 pm

import numpy as np

# X = (hours sleeping, hours studying), y = score on test

X = np.array(([1353, 1218, 1120], [ 1218, 1120, 1107], [1120, 1107, 863], [1107, 863, 875],
[863, 875, 905], [875, 905, 910], [905, 910, 924], [910, 924, 967], [924, 967, 1189],
[967, 1189, 1198], [1189, 1198, 1179], [1198, 1179, 1189], [1179, 1189, 1023], [1189, 1023, 1255],
[1023, 1255, 1026], [1255, 1026, 1110], [1026, 1110, 1093], [1110, 1093, 1075], [1093, 1075, 979], [1075, 979, 1229], [979, 1229, 1421],
[1229, 1421, 1500], [1421, 1500, 1346], [1500, 1346, 1230], [1346, 1230, 1176], [1230, 1176, 1236], [1176, 1236, 1049], [1236, 1049, 1131],
[1049, 1131, 1117], [1131, 1117, 1218], [1117, 1218, 1105], [1218, 1105, 1402], [1105, 1402, 1366],
[1402, 1366, 1492], [1366, 1492, 1741], [1492, 1741, 1461], [1741, 1461, 1283], [1461, 1283, 1209], [1283, 1209, 1237], [1209, 1237, 1215],
[1237, 1215, 1216], [1215, 1216, 1398], [1216, 1398, 1185], [1398, 1185, 1322], [1185, 1322, 1487], [1322, 1487, 1636], [1487, 1636, 1609],
[1636, 1609, 1527], [1609, 1527, 1303], [1527, 1303, 1388], [1303, 1388, 1303], [1388, 1303, 1062], [1303, 1062, 1264], [1062, 1264, 1299],
[1264, 1299, 1307], [1299, 1307, 1340], [1307, 1340, 1495], [1340, 1495, 1755], [1495, 1755, 1617], [1755, 1617, 1510], [1617, 1510, 1443],
[1510, 1443, 1600], [1443, 1600, 1338], [1600, 1338, 1448]), dtype=float)

y = np.array(([1107], [863], [875], [905], [910], [924], [967], [1189], [1198],
[1179], [1189], [1023], [1255], [1026], [1110], [1093], [1075], [979], [1229], [1421], [1500],
[1346], [1230], [1176], [1236], [1049], [1131], [1117], [1218], [1105], [1402], [1366], [1492],
[1741], [1461], [1283], [1209], [1237], [1215], [1216], [1398], [1185], [1322], [1487], [1636],
[1609], [1527], [1303], [1388], [1303], [1062], [1264], [1299], [1307], [1340], [1495], [1755],
[1617], [1510], [1443], [1600], [1338], [1448], [1334]), dtype=float)



# scale units
X = X/np.amax(X, axis=0) # maximum of X array
y = y/10000 # max test score is 10000


class Neural_Network(object):
def __init__(self):
#parameters
self.inputSize = 3
self.outputSize = 1
self.hiddenSize = 10

#weights
self.W1 = np.random.randn(self.inputSize, self.hiddenSize) # (3x2) weight matrix from input to hidden layer
self.W2 = np.random.randn(self.hiddenSize, self.outputSize) # (3x1) weight matrix from hidden to output layer

def forward(self, X):
#forward propagation through our network
self.z = np.dot(X, self.W1) # dot product of X (input) and first set of 3x2 weights
self.z2 = self.sigmoid(self.z) # activation function
self.z3 = np.dot(self.z2, self.W2) # dot product of hidden layer (z2) and second set of 3x1 weights
o = self.sigmoid(self.z3) # final activation function
return o

def sigmoid(self, s):
# activation function
return 1/(1+np.exp(-s))

def sigmoidPrime(self, s):
#derivative of sigmoid
return s * (1 - s)

def backward(self, X, y, o):
# backward propgate through the network
self.o_error = y - o # error in output
self.o_delta = self.o_error*self.sigmoidPrime(o) # applying derivative of sigmoid to error

self.z2_error = self.o_delta.dot(self.W2.T) # z2 error: how much our hidden layer weights contributed to output error
self.z2_delta = self.z2_error*self.sigmoidPrime(self.z2) # applying derivative of sigmoid to z2 error

self.W1 += X.T.dot(self.z2_delta) # adjusting first set (input --> hidden) weights
self.W2 += self.z2.T.dot(self.o_delta) # adjusting second set (hidden --> output) weights

def train (self, X, y):
o = self.forward(X)
self.backward(X, y, o)



NN = Neural_Network()

#defining our output
# o = NN.forward(X)

#-------- ขั้นตอนฝึกสอน ------------

for i in range(1000): # trains the NN 1,000 times
print ("Input: \n" + str(X))
print ("Actual Output: \n" + str(y))
print ("Predicted Output: \n" + str(NN.forward(X)))
print ("Loss: \n" + str(np.mean(np.square(y - NN.forward(X))))) # mean sum squared loss
print ("\n")
NN.train(X, y)

#--------- ขั้นตอนทดสอบ ------------
data_test = np.array(([1428,1327,1471], [1327,1471,1550], [1471,1550,1695], [1550,1695,1197], [1695,1197,981], [1197,981,925],
[981,925,796], [925,796,823], [796,823,760], [823,760,846], [760,846,812], [846,812,940], [812,940,1031],
[940,1031,1068], [1031,1068,1198]), dtype=float) # ข้อมูลที่นำไปทดสอบ

# scale units
test = data_test/np.amax(data_test, axis=0) # maximum of X array
output_test = NN.forward(test)
print ("--------- ขั้นตอนทดสอบ ------------")
print ("Data test: " + str(data_test))
print ("Predicted Output: " + str(output_test*10000))
แนบไฟล์
bnn3.1.txt
โค้ดไพธอนเป็นกิจกรรม Activity Diagram ยังไงครับ
(4.92 KiB) ดาวน์โหลด 8 ครั้ง

ย้อนกลับไปยัง

ผู้ใช้งานขณะนี้

กำลังดูบอร์ดนี้: 4 และ บุคคลทั่วไป 0 ท่าน