(* * LANGUAGE : ANS Forth * PROJECT : Forth Environments * DESCRIPTION : neural net with backpropagation * CATEGORY : Example * AUTHOR : Marcel Hendrix, November 26 1989 * LAST CHANGE : October 13, 1991, Marcel Hendrix *) ?DEF Sensors [IF] FORGET Sensors [THEN] -- **** Define the layers. ****************************************** 2 =: Sensors -- Dyadic functions 2 =: HiddenUnits -- set up 1-dimensional I/Hidden/O vectors 6 =: OutputUnits -- 6 outputs: AND NAND OR NOR EXOR IOR INCLUDE backprop.frt REVISION -multgate "ÄÄÄ Neural App: Multiple Gates 1.01 ÄÄÄ" -- **** End of layer defs. ****************************************** (* Application Level *) :ABOUT CR CR ." ** LOGIC in Multi-layered Neural-Net using back-propagation **" CR ." This net implements AND NAND OR NOR EXOR IOR simultaneously." CR CR ." ADD-PAIR -- Pattern is primed for linking with ." CR ." î {I=00 I=01 I=11 I=10}" CR ." î {O=010101 O=011010 O=101001}" CR ." DRILL -- All primed pairs are coded-in." CR ." NO-CONNECTIONS -- Forget all associations." CR ." REACT -- Test if pair is reproduced." CR ." .STATUS -- Prints inputs | outputs | targets." CR ." .WEIGHTS -- Prints all weights." CR ." TO LearningRate -- LearningRate, oscillates if too large (>1000)." CR ." TO Retries -- Retry Rate (normally 3000)." CR ." Noisy | Clean -- Select if input is noisy or not." CR ." TO Noise -- 1 out of pixels in is corrupted, if Noisy." CR ." FALSE | TRUE TO ?display -- See matrices during learning or not." CR ." DO-IT! -- Sets up defaults and learns the patterns." CR ." .ABOUT -multgate -- Print this info." CR CR ." Note: When running, '+' and '-' influence LearningRate," CR ." '/' switches between .STATUS and .WEIGHTS," CR ." 'd' turns display on and off," CR ." 'ESC' breaks." ; -- Input patterns CREATE I=00 0 0 sensor, CREATE I=01 0 1 sensor, CREATE I=11 1 1 sensor, CREATE I=10 1 0 sensor, -- Output patterns -- and nand or nor exor ior CREATE O=010101 0 1 0 1 0 1 output, CREATE O=011010 0 1 1 0 1 0 output, CREATE O=101001 1 0 1 0 0 1 output, : doMultiGateShow CR ." The net is given the bit pattern %" /inputs 1 ?DO I InputValues .BIT LOOP ." , so it outputs %" 0 ( %error ) /outputs 0 ?DO I ActualOutputs .OUTPUTBIT + LOOP ." (" /outputs / 1 .R ." % error)." CR ; : MultiGateShow ['] doMultiGateShow IS SHOW-NET ; : doMultiGate TIMER-RESET NO-CONNECTIONS I=00 O=010101 ADD-PAIR \ Define Gate functions I=01 O=011010 ADD-PAIR I=11 O=101001 ADD-PAIR I=10 O=011010 ADD-PAIR DRILL .ELAPSED ; : MultiGate ['] doMultiGate IS DO-IT! ; MultiGateShow MultiGate #800 TO LearningRate .ABOUT -multgate (* End of Application *)