;;;NETTOOL3 CREATED


(de nettool-net ()
  (let ((input
          (new c-layer '("input" (16 16) t () () () () () t) 60 110 112 112) )
        (hidden-1
          (new c-layer '("hidden-1" (8 8) () () t () () () t) 250 70 80 80) )
        (hidden-2
          (new c-layer '("hidden-2" (8 8) () () t () () () t) 250 180 80 80) )
        (prepro-1
          (new c-layer '("prepro-1" (4 4) () () t () () () t) 440 30 60 60) )
        (prepro-2
          (new c-layer '("prepro-2" (4 4) () () t () () () t) 440 110 60 60) )
        (prepro-3
          (new c-layer '("prepro-3" (4 4) () () t () () () t) 440 190 60 60) )
        (prepro-4
          (new c-layer '("prepro-4" (4 4) () () t () () () t) 440 270 60 60) )
        (output
          (new c-layer '("output" (1 10) () t () () () t ()) 600 90 19 190) ) )
    (new c-connection input hidden-1
      (list ct-mask-toric-connect '(3 3) '(2 2) '(0 0) '(15 15)) )
    (new c-connection input hidden-2
      (list ct-mask-toric-connect '(3 3) '(2 2) '(0 0) '(15 15)) )
    (new c-connection hidden-1 prepro-1
      (list ct-mask-toric-connect '(3 3) '(2 2) '(0 0) '(7 7)) )
    (new c-connection hidden-1 prepro-2
      (list ct-mask-toric-connect '(3 3) '(2 2) '(0 0) '(7 7)) )
    (new c-connection hidden-1 prepro-3
      (list ct-mask-toric-connect '(3 3) '(2 2) '(0 0) '(7 7)) )
    (new c-connection hidden-1 prepro-4
      (list ct-mask-toric-connect '(3 3) '(2 2) '(0 0) '(7 7)) )
    (new c-connection hidden-2 prepro-1
      (list ct-mask-toric-connect '(3 3) '(2 2) '(0 0) '(7 7)) )
    (new c-connection hidden-2 prepro-2
      (list ct-mask-toric-connect '(3 3) '(2 2) '(0 0) '(7 7)) )
    (new c-connection hidden-2 prepro-3
      (list ct-mask-toric-connect '(3 3) '(2 2) '(0 0) '(7 7)) )
    (new c-connection hidden-2 prepro-4
      (list ct-mask-toric-connect '(3 3) '(2 2) '(0 0) '(7 7)) )
    (new c-connection prepro-1 output
      (list ct-connect '(1 1) '(1 1) '(0 0) '(3 3)) )
    (new c-connection prepro-2 output
      (list ct-connect '(1 1) '(1 1) '(0 0) '(3 3)) )
    (new c-connection prepro-3 output
      (list ct-connect '(1 1) '(1 1) '(0 0) '(3 3)) )
    (new c-connection prepro-4 output
      (list ct-connect '(1 1) '(1 1) '(0 0) '(3 3)) ) ) )


(de create-net ()
  (alloc-net (+ 469 0) (+ 3146 0) (+ 746 0))
  (build-net-nobias
    '((input 256) (hidden-1 64) (hidden-2 64) (prepro-1 16) (prepro-2 16)
       (prepro-3 16) (prepro-4 16) (output 10) )
    () )
  ()
  (shared-bias-connect hidden-1)
  (shared-bias-connect hidden-2)
  (shared-bias-connect prepro-1)
  (shared-bias-connect prepro-2)
  (shared-bias-connect prepro-3)
  (shared-bias-connect prepro-4)
  (bias-connect output)
  (mask-toric-connect input 16 16 hidden-1 8 8 2 2 3 3)
  (mask-toric-connect input 16 16 hidden-2 8 8 2 2 3 3)
  (mask-toric-connect hidden-1 8 8 prepro-1 4 4 2 2 3 3)
  (mask-toric-connect hidden-1 8 8 prepro-2 4 4 2 2 3 3)
  (mask-toric-connect hidden-1 8 8 prepro-3 4 4 2 2 3 3)
  (mask-toric-connect hidden-1 8 8 prepro-4 4 4 2 2 3 3)
  (mask-toric-connect hidden-2 8 8 prepro-1 4 4 2 2 3 3)
  (mask-toric-connect hidden-2 8 8 prepro-2 4 4 2 2 3 3)
  (mask-toric-connect hidden-2 8 8 prepro-3 4 4 2 2 3 3)
  (mask-toric-connect hidden-2 8 8 prepro-4 4 4 2 2 3 3)
  (connect prepro-1 output)
  (connect prepro-2 output)
  (connect prepro-3 output)
  (connect prepro-4 output) )


(de draw-net (&optional l num)
  (when (null draw-net-windowobject)
    (when (null net-display)
      (libload "nettool.sn") )
    (setq :draw-net-windowobject
      (new net-display 0 0 641 362 "Network Window"
        (lambda ()
          (graphics-batch
            (cls)
            (gprintf 60 106 "Input")
            (gray-draw-list 60 110 (neurval input) 16 1.2 -1.2 7)
            (gprintf 250 66 "Hidden-1")
            (gray-draw-list 250 70 (neurval hidden-1) 8 1.2 -1.2 10)
            (gprintf 250 176 "Hidden-2")
            (gray-draw-list 250 180 (neurval hidden-2) 8 1.2 -1.2 10)
            (gprintf 440 26 "Prepro-1")
            (gray-draw-list 440 30 (neurval prepro-1) 4 1.2 -1.2 15)
            (gprintf 440 106 "Prepro-2")
            (gray-draw-list 440 110 (neurval prepro-2) 4 1.2 -1.2 15)
            (gprintf 440 186 "Prepro-3")
            (gray-draw-list 440 190 (neurval prepro-3) 4 1.2 -1.2 15)
            (gprintf 440 266 "Prepro-4")
            (gray-draw-list 440 270 (neurval prepro-4) 4 1.2 -1.2 15)
            (gprintf 600 86 "Output")
            (draw-list 600 90 (neurval output) 1 1.2 19 17) ) )
        (lambda (xc yc)
          (cond
            ((point-in-rect xc yc '(60 110 112 112))
              (nth (+ (div (- xc 60) 7) (* 16 (div (- yc 110) 7))) input) )
            ((point-in-rect xc yc '(250 70 80 80))
              (nth (+ (div (- xc 250) 10) (* 8 (div (- yc 70) 10))) hidden-1) )
            ((point-in-rect xc yc '(250 180 80 80))
              (nth (+ (div (- xc 250) 10) (* 8 (div (- yc 180) 10))) hidden-2) )
            ((point-in-rect xc yc '(440 30 60 60))
              (nth (+ (div (- xc 440) 15) (* 4 (div (- yc 30) 15))) prepro-1) )
            ((point-in-rect xc yc '(440 110 60 60))
              (nth (+ (div (- xc 440) 15) (* 4 (div (- yc 110) 15))) prepro-2) )
            ((point-in-rect xc yc '(440 190 60 60))
              (nth (+ (div (- xc 440) 15) (* 4 (div (- yc 190) 15))) prepro-3) )
            ((point-in-rect xc yc '(440 270 60 60))
              (nth (+ (div (- xc 440) 15) (* 4 (div (- yc 270) 15))) prepro-4) )
            ((point-in-rect xc yc '(600 90 19 190))
              (nth (+ (div (- xc 600) 19) (* 1 (div (- yc 90) 19))) output) )) ) ))
    (setq :draw-net-window :draw-net-windowobject:window) )
  (==> draw-net-windowobject expose)
  (==> draw-net-windowobject repair-damaged) )
