接下来我们回顾一下上一章节的内容,再次运行Create_AI_Framework_In5Classes(Day4)的Neuron_Network_Entry.py程序,运行结果如下:

+1      V1      V2      Hidden layer creation: 1        N[1][1]         N[1][2]         N[1][3]         N[1][4]         
Output layer:  OutputThe weight from 1 at layers[0] to 4 at layers[1] : 0.9631037342630762The weight from 1 at layers[0] to 5 at layers[1] : -0.12449764667150542The weight from 1 at layers[0] to 6 at layers[1] : -0.2081992534823458The weight from 1 at layers[0] to 7 at layers[1] : 0.19350453832954195The weight from 2 at layers[0] to 4 at layers[1] : 0.9930441432931731The weight from 2 at layers[0] to 5 at layers[1] : -0.2896501396781723The weight from 2 at layers[0] to 6 at layers[1] : 0.2419179858031506The weight from 2 at layers[0] to 7 at layers[1] : 0.22011110531917577The weight from 4 at layers[1] to 8 at layers[2] : 0.6906117215129182The weight from 5 at layers[1] to 8 at layers[2] : -0.9891300519067223The weight from 6 at layers[1] to 8 at layers[2] : 0.567324777559072The weight from 7 at layers[1] to 8 at layers[2] : 0.2514126571616677Epoch 0 0.2606288708240459Epoch 100 0.2606288708240459Epoch 200 0.2606288708240459Epoch 300 0.2606288708240459Epoch 400 0.2606288708240459Epoch 500 0.2606288708240459Epoch 600 0.2606288708240459Epoch 700 0.2606288708240459Epoch 800 0.2606288708240459Epoch 900 0.2606288708240459Epoch 1000 0.2606288708240459Epoch 1100 0.2606288708240459Epoch 1200 0.2606288708240459Epoch 1300 0.2606288708240459Epoch 1400 0.2606288708240459Epoch 1500 0.2606288708240459Epoch 1600 0.2606288708240459Epoch 1700 0.2606288708240459Epoch 1800 0.2606288708240459Epoch 1900 0.2606288708240459Epoch 2000 0.2606288708240459Epoch 2100 0.2606288708240459Epoch 2200 0.2606288708240459Epoch 2300 0.2606288708240459Epoch 2400 0.2606288708240459Epoch 2500 0.2606288708240459Epoch 2600 0.2606288708240459Epoch 2700 0.2606288708240459Epoch 2800 0.2606288708240459Epoch 2900 0.2606288708240459Epoch 3000 0.2606288708240459Epoch 3100 0.2606288708240459Epoch 3200 0.2606288708240459Epoch 3300 0.2606288708240459Epoch 3400 0.2606288708240459Epoch 3500 0.2606288708240459Epoch 3600 0.2606288708240459Epoch 3700 0.2606288708240459Epoch 3800 0.2606288708240459Epoch 3900 0.2606288708240459Epoch 4000 0.2606288708240459Epoch 4100 0.2606288708240459Epoch 4200 0.2606288708240459Epoch 4300 0.2606288708240459Epoch 4400 0.2606288708240459Epoch 4500 0.2606288708240459Epoch 4600 0.2606288708240459Epoch 4700 0.2606288708240459Epoch 4800 0.2606288708240459Epoch 4900 0.2606288708240459Epoch 5000 0.2606288708240459Epoch 5100 0.2606288708240459Epoch 5200 0.2606288708240459Epoch 5300 0.2606288708240459Epoch 5400 0.2606288708240459Epoch 5500 0.2606288708240459Epoch 5600 0.2606288708240459Epoch 5700 0.2606288708240459Epoch 5800 0.2606288708240459Epoch 5900 0.2606288708240459Epoch 6000 0.2606288708240459Epoch 6100 0.2606288708240459Epoch 6200 0.2606288708240459Epoch 6300 0.2606288708240459Epoch 6400 0.2606288708240459Epoch 6500 0.2606288708240459Epoch 6600 0.2606288708240459Epoch 6700 0.2606288708240459Epoch 6800 0.2606288708240459Epoch 6900 0.2606288708240459Epoch 7000 0.2606288708240459Epoch 7100 0.2606288708240459Epoch 7200 0.2606288708240459Epoch 7300 0.2606288708240459Epoch 7400 0.2606288708240459Epoch 7500 0.2606288708240459Epoch 7600 0.2606288708240459Epoch 7700 0.2606288708240459Epoch 7800 0.2606288708240459Epoch 7900 0.2606288708240459Epoch 8000 0.2606288708240459Epoch 8100 0.2606288708240459Epoch 8200 0.2606288708240459Epoch 8300 0.2606288708240459Epoch 8400 0.2606288708240459Epoch 8500 0.2606288708240459Epoch 8600 0.2606288708240459Epoch 8700 0.2606288708240459Epoch 8800 0.2606288708240459Epoch 8900 0.2606288708240459Epoch 9000 0.2606288708240459Epoch 9100 0.2606288708240459Epoch 9200 0.2606288708240459Epoch 9300 0.2606288708240459Epoch 9400 0.2606288708240459Epoch 9500 0.2606288708240459Epoch 9600 0.2606288708240459Epoch 9700 0.2606288708240459Epoch 9800 0.2606288708240459Epoch 9900 0.2606288708240459CongratulationsAll Epoch is completed!!!Visualize the graduation of Loss in the traning process

Prediction: 0.5646632219606454 while real value is: 0Prediction: 0.6312977876853616 while real value is: 1Prediction: 0.6054143701451664 while real value is: 1Prediction: 0.6572912508223139 while real value is: 0



(32)代码优化一(32)代码优化一

上一章节代码运行的结果中收敛度是一条平行线,以下进行代码修改让收敛度尽快的达到最低的损失度。

代码优化一:在代码中进行一个很小的调整,将

Create_AI_Framework_In5Classes(Day4)的BackPropagation.py 中的代码:



weight_to_node_value == nodes[k].get_value()


修改成如下代码。

weight_to_node_value = nodes[k].get_value()


因为“==”是比较符号而不是赋值符号,如果是比较符号,Back Propagation 就没有进行更新。只有对Weight进行更新才能够把Neuron Network的训练成果作用于下一次的训练。

重新运行Neuron_Network_Entry.py,结果如下:

(32)代码优化一(32)代码优化一

这个时候,收敛度的结果已经从平行线变成了一条下降的曲线,说明代码的修改已经起作用了。但是训练的时候,发现在运行结果图的左侧有一个不太规则的地方,接下来可以修改另外一个地方。

(32)代码优化一


相关文章: