Algoritma Andaline Menggunakan Bahasa Pemrograman Python

#inisialisasi input dan target
#format (((x1,x2,...,1),t),...)
pola = (
	((1,1,1),1),
	((1,-1,1),-1),
	((-1,1,1),-1),
	((-1,-1,1),-1)
	)

dw = [0,0,0]	# perubahan bobot
bw = [0,0,0]	# bobot baru
a = 0.1			# laju pembelajaran
T = 0.05		# toleransi

i = 1
	
while True:
	print "epoc %s" % i
	print ('-'*65)
	print " input \t\t| t \t| net \t| y \t| t-y \t| perubahan bobot \t| bobot baru \t|" 
	print ('-'*65)
	print "\t\t\t\t\t\t| ",bw," \t|"
	for j in range(len(pola)):
		y = 0
		for k in range(len(pola[j][0])):
			y = y + bw[k] * pola[j][0][k]
		
		b = a*(pola[j][1] - y)
		
		for l in range(len(pola[j][0])):
			dw[l] = round((b * pola[j][0][l]),2)
			bw[l] = round((bw[l] + dw[l]),2)

		print " ",pola[j][0]," \t| ",pola[j][1]," \t| ",y," \t|",y,"\t|",(pola[j][1] - y),"| ",dw," \t| ",bw," \t|"

	print ('-'*65)
	print ""

	i = i + 1
	
	if max(dw) < T:
		break

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s