[AHK]AutoHotkey也玩神经网络实现OR逻辑感知器
来源:互联网 发布:阿里云电话客服 编辑:程序博客网 时间:2024/06/16 11:36
;~ ================ ;~ ---Artificial Neural Networks--- ;~ --OR Logic Gate Perceptron ;~ =======Code=========#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.#Warn ; Enable warnings to assist with detecting common errors.SendMode Input ; Recommended for new scripts due to its superior speed and reliability.SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. /*OR Truth Table: Input Output0 0 00 1 11 0 11 1 1 */ ;========OR Logic Gate Perceptron======= class perceptron{ c := 0.01 ; learning constant bias := - 0.5 weights := [] ; initialize array __New() { Loop, 2 ; Get random weights { Random, rand, -1.0, 1.0 ; Generate a random number between -1 and 1 this.weights.Insert(rand) } } getOutput(i1,i2) { sum := 0 sum := this.bias + i1*this.weights[1] + i2*this.weights[2] return % stepF(sum) } train(i1,i2) { actual := this.getOutput(i1,i2) error := desired(i1,i2) - actual ; calculate error this.weights[1] := this.weights[1] + (this.c * error * i1) this.weights[2] := this.weights[2] + (this.c * error * i2) } } training := [[0,0],[0,1],[1,0],[1,1]] ; training dataperceptron := new perceptron()bool := truetrainingLoops := 500 ; training the perceptron Loop, % trainingLoops Loop, 4 perceptron.train(training[A_Index,1],training[A_Index,2]) MsgBox, Training finished! while(bool){ InputBox, input1, Input 1, Please enter 1 or 0. InputBox, input2, Input 2, Please enter 1 or 0. MsgBox, 4,,% input1 . " OR " . input2 . " = " . perceptron.getOutput(input1,input2) . "`nDo you want to try other inputs?" IfMsgBox, No bool := false} ;-----Functions----- stepF(float) ; Step Function(Activation Function){ if float > 0 return 1 else return 0} desired(i1,i2) ; get the desired result{ if(( i1 = 1) or ( i2 =1)) return 1 else return 0}
阅读全文
0 0
- Spark、hadoop源码编译
- ajax在PC上运行正常,打包到手机后就报error0错误
- QPixmap load jpg图片失败的解决方法
- WeX5调用jQuery格式问题
- 强分类器(提升方法)-----------AdaBoost算法原理和推导过程
- [AHK]AutoHotkey也玩神经网络实现OR逻辑感知器
- 蓝桥杯 PREV-1 历届试题 核桃的数量
- 爬取南京邮电大学党委宣传部
- spring+quartz定时器
- gdb远程调试示例
- 34_面向对象_07_构造器(构造方法)
- 蓝桥杯 ALGO-148 算法训练 5-1最小公倍数
- WeX5向data组件动态添加数据格式
- Linux进程通信-管道(pipe)