# ANN Simulator Sandbox

Model was written in NetLogo 6.1.1
•
Viewed 314 times
•
Downloaded 22 times
•
Run 0 times

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)

## Comments and Questions

Please start the discussion about this model!
(You'll first need to log in.)

Click to Run Model

;; Artificial Neural Network Sandbox ;; ;; by L. F. Bencivengo, Jr. December 14, 2020 globals [OutputA OutputB OutputC OutputI OutputII OutputIII Output1 Output2 Output3 started? auto_Input_Pattern input#] breed [Input_Neurons Input_Neuron] breed [Hidden_Neurons Hidden_Neuron] breed [Output_Neurons Output_Neuron] turtles-own [threshold weight1 weight2 weight3 activation output] directed-link-breed [axons-AI axon-AI] directed-link-breed [axons-BII axon-BII] directed-link-breed [axons-CIII axon-CIII] ;; BUTTONS: This section defines the function of each Interface Button to setup clear-all ;; turn off auto_Input_Pattern set auto_Input_Pattern FALSE set input# 0 ;; create neurons with current output = 0 set-default-shape Input_Neurons "square 2" set-default-shape Hidden_Neurons "triangle 2" set-default-shape Output_Neurons "circle 2" setup-Input_Neurons setup-Hidden_Neurons setup-Output_Neurons ;; create axons that connect each neuron in the network set-default-shape axons-AI "axon-ai-0" set-default-shape axons-BII "axon-bii-0" set-default-shape axons-CIII "axon-ciii-0" setup-synapses ;; clear the ticks to disable Input Buttons set started? FALSE clear-ticks end to go ;; if just starting, reset ticks and enable Input Buttons if not started? [reset-ticks reset-timer] set started? TRUE ;; read values of weights and thresholds from sliders update-weights ;; update the activation and output of each neuron in the network update-Hidden_Outputs update-Output_Outputs ;; update the display to show any changes in neurons' output update-display tick end to auto-Input_Pattern ;; if auto-input is clicked, run through the auto-input sequence ;; through repeated calls of update-Input_Pattern ;; Forever Button, Disabled until ticks start end to Input_A ;; change the current state of Input Neuron A ifelse OutputA = 0 [set OutputA 1] [set OutputA 0] ifelse OutputA = 0 [ask turtle 0 [set output 0]] [ask turtle 0 [set output 1]] stop end to Input_B ;; change the current state of Input Neuron B ifelse OutputB = 0 [set OutputB 1] [set OutputB 0] ifelse OutputB = 0 [ask turtle 1 [set output 0]] [ask turtle 1 [set output 1]] end to Input_C ;; change the current state of Input Neuron C ifelse OutputC = 0 [set OutputC 1] [set OutputC 0] ifelse OutputC = 0 [ask turtle 2 [set output 0]] [ask turtle 2 [set output 1]] end to reset_weights ;; reset the sliders for every neuron's weights and thresholds to the default value of 1 set weightIA 1 set weightIB 1 set weightIC 1 set thresholdI 1 set weightIIA 1 set weightIIB 1 set weightIIC 1 set thresholdII 1 set weightIIIA 1 set weightIIIB 1 set weightIIIC 1 set thresholdIII 1 set weight1I 1 set weight1II 1 set weight1III 1 set threshold1 1 set weight2I 1 set weight2II 1 set weight2III 1 set threshold2 1 set weight3I 1 set weight3II 1 set weight3III 1 set threshold3 1 end ;; PROCEDURES: This section defines the Procedures which control the model to setup-Input_Neurons ;; turtle 0 is Input Neuron A create-Input_Neurons 1 [ set shape "input neuron a - 0" set size 3 set color grey set xcor -8 set ycor 12] ;; turtle 1 is Input Neuron B create-Input_Neurons 1 [ set shape "input neuron b - 0" set size 3 set color grey set xcor 0 set ycor 12] ;; turtle 2 is Input Neuron C create-Input_Neurons 1 [ set shape "input neuron c - 0" set size 3 set color grey set xcor 8 set ycor 12] end to setup-Hidden_Neurons ;; turtle 3 is Hidden Neuron I create-Hidden_Neurons 1 [ set shape "hidden neuron i - 0" set size 3 set color grey set xcor -8 set ycor 0] ;; turtle 4 is Hidden Neuron II create-Hidden_Neurons 1 [ set shape "hidden neuron ii - 0" set size 3 set color grey set xcor 0 set ycor 0] ;; turtle 5 is Hidden Neuron III create-Hidden_Neurons 1 [ set shape "hidden neuron iii - 0" set size 3 set color grey set xcor 8 set ycor 0] end to setup-Output_Neurons ;; turtle 6 is Output Neuron 1 create-Output_Neurons 1 [ set shape "output neuron 1 - 0" set size 3 set color grey set xcor -8 set ycor -12] ;; turtle 7 is Output Neuron 2 create-Output_Neurons 1 [ set shape "output neuron 2 - 0" set size 3 set color grey set xcor 0 set ycor -12] ;; turtle 8 is Output Neuron 3 create-Output_Neurons 1 [ set shape "output neuron 3 - 0" set size 3 set color grey set xcor 8 set ycor -12] end to setup-synapses ;; create axons from each Input Neuron to each Hidden Neuron ask turtle 0 [create-axons-AI-to Hidden_Neurons] ask turtle 1 [create-axons-BII-to Hidden_Neurons] ask turtle 2 [create-axons-CIII-to Hidden_Neurons];; [set thickness 0.25 set color white]] ;; create axons from each Hidden Neuron to each Output Neuron ask turtle 3 [create-axons-AI-to Output_Neurons] ask turtle 4 [create-axons-BII-to Output_Neurons] ask turtle 5 [create-axons-CIII-to Output_Neurons] end to update-Input_Pattern ;; when auto_Input_Pattern = TRUE, runs through a sequence of input patterns ;; changing the pattern at a rate that depends upon the auto-Input_Rate slider value ifelse input# = 8 [set input# 1] [set input# input# + 1] (ifelse input# = 1 [ask turtle 0 [set output 0] ask turtle 1 [set output 0] ask turtle 2 [set output 0] set OutputA 0 set OutputB 0 set OutputC 0] input# = 2 [ask turtle 0 [set output 1] ask turtle 1 [set output 0] ask turtle 2 [set output 0] set OutputA 1 set OutputB 0 set OutputC 0] input# = 3 [ask turtle 0 [set output 0] ask turtle 1 [set output 1] ask turtle 2 [set output 0] set OutputA 0 set OutputB 1 set OutputC 0] input# = 4 [ask turtle 0 [set output 0] ask turtle 1 [set output 0] ask turtle 2 [set output 1] set OutputA 0 set OutputB 0 set OutputC 1] input# = 5 [ask turtle 0 [set output 1] ask turtle 1 [set output 1] ask turtle 2 [set output 0] set OutputA 1 set OutputB 1 set OutputC 0] input# = 6 [ask turtle 0 [set output 1] ask turtle 1 [set output 0] ask turtle 2 [set output 1] set OutputA 1 set OutputB 0 set OutputC 1] input# = 7 [ask turtle 0 [set output 0] ask turtle 1 [set output 1] ask turtle 2 [set output 1] set OutputA 0 set OutputB 1 set OutputC 1] input# = 8 [ask turtle 0 [set output 1] ask turtle 1 [set output 1] ask turtle 2 [set output 1] set OutputA 1 set OutputB 1 set OutputC 1] []) reset-timer end to update-weights ;; read weights from slider values: ;; Ex. "weight1" is a neuron variable while "weightIA" is the value read from a slider ;; update Hidden Neuron weights ask turtle 3 [set weight1 weightIA set weight2 weightIB set weight3 weightIC set threshold thresholdI] ask turtle 4 [set weight1 weightIIA set weight2 weightIIB set weight3 weightIIC set threshold thresholdII] ask turtle 5 [set weight1 weightIIIA set weight2 weightIIIB set weight3 weightIIIC set threshold thresholdIII] ;; update Output Neuron weights ask turtle 6 [set weight1 weight1I set weight2 weight1II set weight3 weight1III set threshold threshold1] ask turtle 7 [set weight1 weight2I set weight2 weight2II set weight3 weight2III set threshold threshold2] ask turtle 8 [set weight1 weight3I set weight2 weight3II set weight3 weight3III set threshold threshold3] end to update-Hidden_Outputs ;; multiply the value of each input to a Hidden Neuron by the weight of its synapse ;; compare the weighted sum to the threshold to determine the neuron's output (0 or 1) ask turtle 3 [ set activation (weight1 * OutputA + weight2 * OutputB + weight3 * OutputC) ifelse activation > threshold [set output 1] [set output 0] ifelse output = 1 [set OutputI 1] [set OutputI 0] ] ask turtle 4 [ set activation (weight1 * OutputA + weight2 * OutputB + weight3 * OutputC) ifelse activation > threshold [set output 1] [set output 0] ifelse output = 1 [set OutputII 1] [set OutputII 0] ] ask turtle 5 [ set activation (weight1 * OutputA + weight2 * OutputB + weight3 * OutputC) ifelse activation > threshold [set output 1] [set output 0] ifelse output = 1 [set OutputIII 1] [set OutputIII 0] ] end to update-Output_Outputs ;; multiply the value of each input to an Ouput Neuron by the weight of its synapse ;; compare the weighted sum to the threshold to determine the neuron's output (0 or 1) ask turtle 6 [ set activation (weight1 * OutputI + weight2 * OutputII + weight3 * OutputIII) ifelse activation > threshold [set output 1] [set output 0] ifelse output = 1 [set Output1 1] [set Output1 0] ] ask turtle 7 [ set activation (weight1 * OutputI + weight2 * OutputII + weight3 * OutputIII) ifelse activation > threshold [set output 1] [set output 0] ifelse output = 1 [set Output2 1] [set Output2 0] ] ask turtle 8 [ set activation (weight1 * OutputI + weight2 * OutputII + weight3 * OutputIII) ifelse activation > threshold [set output 1] [set output 0] ifelse output = 1 [set Output2 1] [set Output2 0] ] end to update-display ;; changes each neuron's shape and color to display whether its output is 0 or 1 ask turtle 0 [ ifelse output = 1 [set shape "input neuron a - 1" set color white ask my-out-links [set color white]] [set shape "input neuron a - 0" set color grey ask my-out-links [set color grey]] ] ask turtle 1 [ ifelse output = 1 [set shape "input neuron b - 1" set color white ask my-out-links [set color white]] [set shape "input neuron b - 0" set color grey ask my-out-links [set color grey]] ] ask turtle 2 [ ifelse output = 1 [set shape "input neuron c - 1" set color white ask my-out-links [set color white]] [set shape "input neuron c - 0" set color grey ask my-out-links [set color grey]] ] ask turtle 3 [ ifelse output = 1 [set shape "hidden neuron i - 1" set color white ask my-out-links [set color white]] [set shape "hidden neuron i - 0" set color grey ask my-out-links [set color grey]] ] ask turtle 4 [ ifelse output = 1 [set shape "hidden neuron ii - 1" set color white ask my-out-links [set color white]] [set shape "hidden neuron ii - 0" set color grey ask my-out-links [set color grey]] ] ask turtle 5 [ ifelse output = 1 [set shape "hidden neuron iii - 1" set color white ask my-out-links [set color white]] [set shape "hidden neuron iii - 0" set color grey ask my-out-links [set color grey]] ] ask turtle 6 [ ifelse output = 1 [set shape "output neuron 1 - 1" set color white ask my-out-links [set color white]] [set shape "output neuron 1 - 0" set color grey ask my-out-links [set color grey]] ] ask turtle 7 [ ifelse output = 1 [set shape "output neuron 2 - 1" set color white ask my-out-links [set color white]] [set shape "output neuron 2 - 0" set color grey ask my-out-links [set color grey]] ] ask turtle 8 [ ifelse output = 1 [set shape "output neuron 3 - 1" set color white ask my-out-links [set color white]] [set shape "output neuron 3 - 0" set color grey ask my-out-links [set color grey]] ] end

There are 3 versions of this model.

## Attached files

File | Type | Description | Last updated | |
---|---|---|---|---|

ANN Simulator Sandbox.png | preview | preview image | over 3 years ago, by Larry Bencivengo | Download |

ANN Simulator Sandbox.png | preview | Preview for 'ANN Simulator Sandbox' | over 3 years ago, by Larry Bencivengo | Download |

This model does not have any ancestors.

This model does not have any descendants.