~dieggsy/chicken-genann

chicken-genann/example3.scm -rwxr-xr-x 676 bytes
2e21e197dieggsy Update source url 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/csi -s
(import genann
        (only chicken.format printf)
        (only srfi-4 f64vector-ref))

(define save-name "example/xor.ann")

(printf "Genann example 3.~n")
(printf "Load a saved ANN to solve the XOR function.~n")

(define ann (call-with-input-file save-name
              (cut genann-read <>)))

;; Input data for the XOR function.
(define inputs #(#f64(0 0) #f64(0 1) #f64(1 0) #f64(1 1)))

;; Run the network and see what it predicts.
(do ((i 0 (add1 i)))
    ((= i 4))
  (printf "Output for ~a is ~a~n"
          (vector-ref inputs i)
          (inexact->exact
           (round
            (f64vector-ref (genann-run ann (vector-ref inputs i)) 0)))))