Simple Neural Network for Streetlight Crossing Decision: Python Implementation
import numpy as np\nweights=np.array([0.5,0.48,-0.7])\nalpha=0.1\nstreetlights =np.array([[ 1,0, 1 ],[ 0, 1, 1 ],[ 0,0, 1 ],[ 1, 1, 1 ],[ 0, 1, 1 ],[1,0,1]])\nwalk_vs_stop =np.array( [ 0, 1, 0, 1, 1, 0 ] )\ninput=streetlights[0]#[101]\ngoal_prediction =walk_vs_stop[0] #equals o... i.e. "stop'
for iteration in range(20):\nprediction=input.dot(weights)\nerror=(goal_prediction-prediction)*2\ndelta=prediction-goal_prediction\nweights=weights-(alpha(input*delta))\nprint("Error:" + str(error)+" Prediction:" + str(prediction))
原文地址: https://www.cveoy.top/t/topic/pqEz 著作权归作者所有。请勿转载和采集!