;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; LUSH Lisp Universal Shell
;;;   Copyright (C) 2002 Leon Bottou, Yann Le Cun, AT&T Corp, NECI.
;;; Includes parts of TL3:
;;;   Copyright (C) 1987-1999 Leon Bottou and Neuristique.
;;; Includes selected parts of SN3.2:
;;;   Copyright (C) 1991-2001 AT&T Corp.
;;;
;;; This program is free software; you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 2 of the License, or
;;; (at your option) any later version.
;;;
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with this program; if not, write to the Free Software
;;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; This file is derived from SN-2.8
;;;   Copyright (C) 1987-1999 Neuristique s.a.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; $Id: xor.sn,v 1.2 2003/03/18 21:18:30 leonb Exp $
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;; A sample implementation of the XOR problem.
;;; and an example of the standard libraries capabilities


;;; builds the network

(alloc-net 100 1000)

(build-net
 '((input 2)(hidden 2)(output 1))
 '((input hidden)(hidden output))))))

;;; the examples

(setq pattern-matrix [[-1 -1][1 -1][1 1][-1 1]])
(setq desired-matrix [[1][-1][1][-1]])
(ensemble 0 3)

;;; Always the same seed => the same initial weights configuration.

(seed 0.87)

;;; The parameters

(epsi 1)
(forget 1)

;;; The plotting functions

(de init-plotting()
  (init-error-plotting 40 1.5)
  (init-perf-plotting 40)
  (set-disp-net-and-error)
  (if ~draw-net-window
    (setq draw-net-window (new-window 512 200 "Network States"))
    (let ((window draw-net-window)) (cls)) )
)

(de draw-net(ns pn)
  (if draw-net-window
    (let ((window draw-net-window)
          (x (* 128 pn)) )
         (graphics-batch
            (draw-list (+ x 48) 44 (state output) 1 1.8 32 28)
            (draw-list (+ x 32) 94 (state hidden) 2 1.8 32 28)
            (draw-list (+ x 32) 144 (state input) 2 1.8 32 28) ) ) ) ) ) ) 


(init-plotting)
(run 4 40)

