Chris Allen
CHE 557
12/7/01

LISP Genetic Algorithm Program:

;This function loads a list of two column vectors, one x and one y.
;"TRAIN.DAT" is one such file.  Length does not need to be known.
(defun grabdata (fname)
  (let ((fstream NIL) (num 1) (num2 1) (xvect NIL) (yvect NIL))
    (with-open-file (fstream fname :direction :input)
      (do ((num 1)) ((not (numberp num)) num)
        (setq num (read fstream nil))
        (setq num2 (read fstream nil))
        (cond ((numberp num) (setq xvect (cons num xvect))))
        (cond ((numberp num2) (setq yvect (cons num2 yvect))))
      )
    )
    (list (reverse xvect) (reverse yvect))
  )
)

;This function generates a file fname from the x-vector and the
;model provided, which must be in the (fit scalefit cumfit (...))
;form.  The resulting file is data synonymous with the format of
;"TRAIN.DAT" or "TEST.DAT".
(defun outputmodel (model xvect fname)
  (let ((fstream NIL) (count 0))
    (with-open-file (fstream fname :direction :output)
      (dotimes (count (length xvect) count)
        (format fstream " ~a ~a ~%"
          (first xvect) (yhatcalc (fourth model) (first xvect)))
        (setq xvect (rest xvect))
      )
    )
  )
)

;Average number of list.
(defun avg (yvect)
  (let ((sum 0))
    (mapcar #'(lambda (tosum) (setq sum (+ sum tosum))) yvect)
    (/ sum (length yvect))
  )
)
        
;Standard deviation of a list.
(defun st-dev (yvect)
  (let ((avgy (avg yvect)) (n (length yvect)) (sqry 0) (sum 0) (count 0))
    (dotimes (count n count)
      (setq sqry (- (first yvect) avgy))
      (setq sum (+ sum (* sqry sqry)))
      (setq yvect (rest yvect))
    )
    (sqrt (/ sum (- n 1)))
  )
)

;This is a function, similar to expt, that allows one to take integer
;powers of numbers.
(defun pwr (x n)
  (let ((y 1) (count 0))
    (cond ((> n 0)
      (dotimes (count n y)
        (setq y (* y x))
      ))
          ((< n 0)
      (dotimes (count (- 0 n) y)
        (setq y (/ y x))
      ))
    )
    y
  )
)
    
;This function generates m number of models in the form of
;(fit scalefit cumfit (...)).  Such a list of these forms constitute
;a "population" of models.  This function leaves fit, scalefit, and
;cumfit uncalculated; evalpop takes care of this.
(defun initialize (m)
  (let ((str NIL) (modelstr NIL) (masterstr NIL) (modcount 0) (count 0))
    (dotimes (modcount m masterstr)
      (setq modelstr NIL)   
      (dotimes (count 4 count)
        (setq str (encode (random 2) (- (random 8) 3) (- (random 8) 3)))
        (setq modelstr (append modelstr str))
      )
      (setq masterstr (cons (list 0 0 0 modelstr) masterstr))
    )
  )
)

;This serves the same function as the one above, but is should run
;faster.  This alternate version of "initialize" takes into account
;the fact that 28 randomized bits can be generated all at once.
(defun alt-init (m)
  (let ((masterstr NIL) (modcount 0))
    (dotimes (modcount m masterstr)
      (setq masterstr (cons (list 0 0 0 (randlist 28)) masterstr))
    )
  )
)
        
;The function below has three parts:  the population fitness generator, the
;sorting and averaging algorithm, and the scale/cumulative fitness generator.
;The function returns a sorted population with models in the form of
;(rawfitness scaledfitness cumulativefitness (...)).
(defun evalpop (modpop xvect yvect)
  (let ((curmodpop modpop) (newmodpop NIL) (count 0) (model NIL) (fit 0) (minfit 0)
   (avgfit 0) (cumfit 0))

    (dotimes (count (length modpop) newmodpop)   
      (setq model (first curmodpop))
      (setq fit (fitness (evaluate (fourth model) xvect yvect)))
      (setq model (list fit (second model) (third model) (fourth model)))
      (setq newmodpop (cons model newmodpop))
      (setq curmodpop (rest curmodpop))
    )
    (setq modpop (sort (copy-list newmodpop) 
      #'(lambda (p1 p2) (> (first p1) (first p2)))))
      
    (setq minfit (first (first (last modpop))))
    (setq avgfit (avg (mapcar #'(lambda (modn) (first modn)) modpop)))
    (setq newmodpop NIL)
    (setq curmodpop (reverse modpop))

    (dotimes (count (length modpop) newmodpop)
      (setq model (first curmodpop))
      (setq fit (/ (- (first model) minfit) (- avgfit minfit)))
      (setq cumfit (+ cumfit fit))   
    
      (setq model (list (first model) fit cumfit (fourth model))) 
      (setq newmodpop (cons model newmodpop))
      (setq curmodpop (rest curmodpop))
    )
  )     
)

;The raw fitness of a sum of squared error is very simple, but just in
;case the model has an extremely low SSE, no division by zero will result.
(defun fitness (SSE)
  (cond ((< (abs SSE) 1e-20) 1e20)
        (T (/ 1 SSE))
  )
)
      
;Evaluation of a model (the fourth term, denoted (...)) is broken down
;into four individual terms.  The "model" is a 28-bit-long bit string,   
;with seven bits per term, which appear consecutively in the string.
;The sum of squares error is returned by this function.
(defun evaluate (model xvect yvect)
  (let ((curxvect xvect) (ydif NIL) (sum 0) (count 0))
    (dotimes (count (length xvect) count)
      (setq ydif (cons (yhatcalc model (first curxvect)) ydif))
      (setq curxvect (rest curxvect))
    )
    (setq ydif (mapcar #'- (reverse ydif) yvect))
    (setq ydif (mapcar #'* ydif ydif))
    (mapcar #'(lambda (tosum) (setq sum (+ sum tosum))) ydif)
    (setq sum (/ (sqrt sum) (st-dev yvect)))  
  )
)
      
;Getting y=f(x) requires four independent calls to "decode".
(defun yhatcalc (model x)
  (let ((sum 0) (curmodel model))
    (setq sum (+ sum (decode (butlast curmodel 21) x)))
    (setq curmodel (nthcdr 7 curmodel))
    (setq sum (+ sum (decode (butlast curmodel 14) x)))
    (setq curmodel (nthcdr 7 curmodel))
    (setq sum (+ sum (decode (butlast curmodel 7) x)))
    (setq sum (+ sum (decode (nthcdr 7 curmodel) x)))
  )
)
  
;To create a seven-bit string from a type (1=exponential, 0=polynomial),
;a multiplicative term (-3 to 4), and a power term (-3 to 4), this
;function must be called.
(defun encode (type a b)
  (let ((str ()))
    (setq str (numtostr b))
    (setq str (append (numtostr a) str))
    (setq str (cons type str))
  )
)
    
;This function evaluates a single model term at a single x-point.  Bit
;strings are stored with bit 6 as the type, bits 3-5 as the
;multiplicative term, and bits 0-2 as the power term.
(defun decode (str x)
  (let ((a 0) (b 0) (type 0) (num 0)) 
    (setq type (first str))
    (setq str (rest str))
   
    (setq a (- (strtonum (butlast str 3)) 3))
    (setq b (- (strtonum (nthcdr 3 str)) 3))
    (cond ((= type 1) (setq num (* a (expt 2.7182818 (* x b)))))
          (T          (setq num (* a (pwr x b))))
    )
  )
)
    
;Converts a number to a 3-bit string.  
(defun numtostr (num)
  (let ((str ()))
    (setq num (+ num 3))
 
    (setq str (cons (cond ((> num 3) 1) (T 0)) str))
    (cond ((> num 3) (setq num (- num 4))))

    (setq str (cons (cond ((> num 1) 1) (T 0)) str))
    (cond ((> num 1) (setq num (- num 2))))
  
    (setq str (cons (cond ((> num 0) 1) (T 0)) str))
    (reverse str)
  )
)  
 
;Converts a 3-bit string to a number.
(defun strtonum (str)
  (let ((num 0))
    (setq num (+ num
      (cond ((zerop (first str)) 0)
            (T 4)
      ))
    )
   
    (setq str (rest str))
    (setq num (+ num
      (cond ((zerop (first str)) 0)
            (T 2)
      ))
    )
 
    (setq str (rest str))
    (setq num (+ num
      (cond ((zerop (first str)) 0)
            (T 1)
      ))
    )
  )
)

;This function gives a random bit string of length n.
;(This was copied from assignment 3)
(defun randlist (n)
  (let ((buildlist NIL) (count 0))
    (dotimes (count n buildlist)
      (setq buildlist (cons (random 2) buildlist))
    )
  )
)

;This function returns a likely candidate of a model from a sorted
;population.  The cumulative fitness of the models of the population
;will make it more likely to select models earlier in the list than
;models later in the list.
(defun select (modpop)
  (let ((rnd 0) (count 0) (i 0) (curpop modpop))
    (setq rnd (random (third (first modpop))))
    
    (dotimes (count (length modpop) (fourth (first curpop)))
      (cond ((< rnd (third (first curpop))) (setq curpop (rest curpop)))
            (T (return (fourth (first curpop))))
      ) 
      (setq i (+ i 1))
    )
  )
)
      
;Creation of a new generation requires 50 calls to "select" if there
;are 50 models in the population.  Two parents are (usually) crossed
;to make two children, which are then possibly mutated.  The population
;returned is of the same size as the parent generation.
(defun operate (modpop)
  (let ((newmodpop NIL) (count 0) (i NIL) (j NIL) (children NIL))
    (dotimes (count (round (/ (length modpop) 2)) newmodpop)
      (setq i (select modpop))
      (setq j (select modpop))
      (setq children (cross i j)) 
    
      (setq i (mutate (first children)))
      (setq j (mutate (second children)))
      (setq newmodpop (cons (list 0 0 0 i) newmodpop))
      (setq newmodpop (cons (list 0 0 0 j) newmodpop))
    )
  )
)

;The master genetic algorithm control function allows the user to
;select m, the number of models in the population, gen, the number
;of generations to breed, and the experimental x and y vectors
;(usually loaded from a file with "grabdata").  A global variable
;"*BEST*" becomes the best model of the last generation.
    
;This function also prints "*BEST*" in the form of (fit, scalefit,
;cumfit, (...)), followed by a visual representation of the model
;equation.  The function also returns the 51st generation of the
;population of models (if gen = 50), although this is not always
;useful.
   
;A note about optimization:  compilation is a must before running
;this function with anything on the order of 50 models and 50
;generations.  Time per call of this function uncompiled measures   
;at 2 minutes.  Time per call following compilation measures at
;only 8 seconds or less.
(defun ga-control (m gen xvect yvect)
  (let ((count 0) (modpop NIL) (nbest NIL))
  
    (setq modpop (alt-init m))
    (setq *BEST* '(0))
      
    (dotimes (count gen count)    
      (setq modpop (evalpop modpop xvect yvect))
      (setq nbest (first modpop))
      (cond ((> (first nbest) (first *BEST*)) (setq *BEST* nbest)))
      (setq modpop (operate modpop))
    )
    (print *BEST*)
    (modelvisual *BEST*)
    modpop
  )
)

;A bit string is mutated on a probability basis per bit.  The 
;user must set *pm* to a value before running ga-control, such as
;0.05.
(defun mutate (X)
  (mapcar #'(lambda (tohack)
    (cond ((< (random 1.0) *pm*)
      (cond
        ((zerop tohack) 1)
        (t 0)
      ))
          (t
      tohack)
    ))
    X
  )
)
  
;Two strings are crossed at a random location on a probability
;basis per pair.  The user must set *pc* to a value before
;running ga-control, such as 0.95.
(defun cross (A B)
  (cond ((< (random 1.0) *pc*)    
    (crossover A B (+ 1 (random 27))))
        (T (list A B))
  )
)
     
;This function is virtually unchanged from assignment 3.
(defun crossover (A B i)
  (let ((Acopy (copy-list A)) (Bcopy (copy-list B)))
    (replace (nthcdr i Acopy) (nthcdr i B))
    (replace (nthcdr i Bcopy) (nthcdr i A))
    (list Acopy Bcopy)
  )
)

;This function displays the model equation in a user-friendly
;fashion.  Terms that have zero coefficients are not simplified,
;so the user must read between the lines to make sure that the
;model does, in fact, have four terms or less than four terms.
(defun modelvisual (model)
  (let ((curmodel (fourth model)))
    (format t "~%")
    (getmodterm (butlast curmodel 21))
    (setq curmodel (nthcdr 7 curmodel))
    (format t " + ");
    (getmodterm (butlast curmodel 14))
    (setq curmodel (nthcdr 7 curmodel))
    (format t " + ");
    (getmodterm (butlast curmodel 7))
    (format t " + ");
    (getmodterm (nthcdr 7 curmodel))
    (format t "~%")
  )
)
    
;A subfunction used by modelvisual.
(defun getmodterm (str)
  (let ((a 0) (b 0) (type 0))
    (setq type (first str))
    (setq str (rest str))

    (setq a (- (strtonum (butlast str 3)) 3))
    (setq b (- (strtonum (nthcdr 3 str)) 3))
    (cond ((= type 1) (format t "~aexp(~ax)" a b))
          (T          (format t "~ax^~a" a b))
    )
  )
)

Log of Training Data Generation:

Script started on Tue Dec 04 10:36:48 2001
atom.ecn.purdue.edu% composer
Loading /package/allegro/5.0/sparc-sunos5.6/libacl503.so.
Mapping /package/allegro/5.0/sparc-sunos5.6/composer.dxl...done.
Mapping /package/allegro/5.0/sparc-sunos5.6/composere.pll.
Allegro CL Enterprise Edition 5.0 [SPARC] (2/9/99 10:01)
Copyright (C) 1985-1998, Franz Inc., Berkeley, CA, USA.  All Rights Reserved.
;; Optimization settings: safety 1, space 1, speed 1, debug 2.
;; For a complete description of all compiler switches given the
;; current optimization settings evaluate (EXPLAIN-COMPILER-SETTINGS).
USER(1): (load "hw6.fasl")
; Fast loading /home/atom/t/allenck/che557/hw6.fasl
T
USER(2): (setq *pm* 0.05)
0.05
USER(3): (setq *pc* 0.95)
0.95
USER(4): (setq vects (grabdata "TRAIN.DAT"))
((-0.8147364 -0.782896 -0.7313418 -0.73021656 -0.7134321 -0.6532619
  -0.6046401 -0.58557045 -0.5534468 -0.4636571 ...)
 (-30.71934 -27.639036 -26.434715 -24.931215 -23.790018 -18.26469
  -16.981636 -20.407885 -12.883721 -13.40114 ...))
USER(5): (setq xvect (first vects))
(-0.8147364 -0.782896 -0.7313418 -0.73021656 -0.7134321 -0.6532619
 -0.6046401 -0.58557045 -0.5534468 -0.4636571 ...)
USER(6): (setq yvect (second vects))
(-30.71934 -27.639036 -26.434715 -24.931215 -23.790018 -18.26469
 -16.981636 -20.407885 -12.883721 -13.40114 ...)
USER(7): (setq tpop NIL)
NIL
[1] USER(9): (setq tpop (cons (ga-control 50 50 xvect yvect) tpop))

(0.8622113 6.4630103 50.0
 (0 0 1 1 1 0 0 1 1 1 1 1 0 1 1 0 0 1 0 0 1 1 0 0 1 0 0 0))
0x^1 + 4exp(2x) + -2exp(-2x) + -2exp(-3x)
[2] USER(11): (ga-control 50 50 xvect yvect)

(0.7906253 4.07886 50.000015
 (1 0 0 0 0 0 0 1 1 0 0 1 1 0 1 1 1 0 1 0 0 1 1 0 0 0 1 1))
-3exp(-3x) + 1exp(3x) + 3exp(1x) + 1exp(0x)
[2] USER(12): (ga-control 50 50 xvect yvect)

(0.8703825 5.3011827 49.999996
 (1 1 0 0 1 0 0 1 1 1 1 1 0 1 1 0 0 1 1 0 0 1 0 0 0 0 0 0))
1exp(1x) + 4exp(2x) + -2exp(1x) + -3exp(-3x)
[2] USER(13): (ga-control 50 50 xvect yvect)

(0.87701523 3.8766255 49.999996
 (0 0 1 1 1 0 1 1 1 1 0 1 0 0 1 1 0 0 1 1 0 1 0 0 0 0 0 0))
0x^2 + 3exp(1x) + 1exp(3x) + -3exp(-3x)
[2] USER(14): (ga-control 50 50 xvect yvect)

(0.5890821 4.172912 50.000008
 (1 0 0 0 0 0 0 1 1 0 0 1 0 1 0 0 1 1 0 1 0 1 1 1 1 1 0 0))
-3exp(-3x) + 1exp(2x) + 0x^-1 + 4exp(1x)
[2] USER(15): (ga-control 50 50 xvect yvect)

(0.7913628 5.152818 49.999996
 (1 1 0 0 0 1 1 1 0 0 0 0 0 0 1 0 1 0 1 1 1 1 1 1 1 1 1 0))
1exp(0x) + -3exp(-3x) + -1exp(4x) + 4exp(3x)
[2] USER(16): (ga-control 50 50 xvect yvect)

(0.8166193 4.094834 49.999992
 (1 1 1 1 1 0 1 1 0 1 1 1 0 0 1 0 0 0 0 0 0 1 0 1 1 1 1 0))
4exp(2x) + 0exp(1x) + -3exp(-3x) + 0exp(3x)
[2] USER(17): (ga-control 50 50 xvect yvect)
 
(0.8720054 6.267609 49.99999
 (1 0 0 0 0 0 0 1 1 1 1 1 0 1 1 1 0 1 0 1 1 1 0 0 1 1 0 0))
-3exp(-3x) + 4exp(2x) + 2exp(0x) + -2exp(1x)
[2] USER(18): (ga-control 50 50 xvect yvect)
 
(0.88998085 3.4833744 50.0
 (0 0 0 1 1 1 0 1 0 0 0 0 0 0 1 1 1 1 1 0 1 1 0 1 1 0 0 0))
-2x^3 + -3exp(-3x) + 4exp(2x) + 0exp(-3x)
[2] USER(19): (ga-control 50 50 xvect yvect)
 
(0.688254 5.492423 49.999992
 (0 1 1 1 1 0 0 0 0 1 1 0 1 1 1 0 0 1 0 0 0 1 1 1 0 1 0 1))
4x^1 + 0x^0 + -2exp(-3x) + 3exp(2x)
[2] USER(20): (setq *BEST* (append (encode 0 -2 3) (encode 1 -3 -3)
 (encode 1 4 2) (encode 0 0 0)))
(0 0 0 1 1 1 0 1 0 0 ...)
[2] USER(21): (length *BEST*)
28
[2] USER(22): (outputmodel (list 0 0 0 *BEST*) xvect "OUTPUTT.DAT")
50
[2] USER(30): (exit)
; Exiting Lisp
atom.ecn.purdue.edu% exit
atom.ecn.purdue.edu%
script done on Tue Dec 04 11:24:33 2001

Log of Test Data Generation and Processing:

Script started on Tue Dec 04 14:57:17 2001
atom.ecn.purdue.edu% composer
Loading /package/allegro/5.0/sparc-sunos5.6/libacl503.so.
Mapping /package/allegro/5.0/sparc-sunos5.6/composer.dxl...done.
Mapping /package/allegro/5.0/sparc-sunos5.6/composere.pll.
Allegro CL Enterprise Edition 5.0 [SPARC] (2/9/99 10:01)   
Copyright (C) 1985-1998, Franz Inc., Berkeley, CA, USA.  All Rights Reserved.
;; Optimization settings: safety 1, space 1, speed 1, debug 2.  
;; For a complete description of all compiler switches given the
;; current optimization settings evaluate (EXPLAIN-COMPILER-SETTINGS).
USER(1): (load "hw6.fasl")
; Fast loading /home/atom/t/allenck/che557/hw6.fasl
T
USER(2): (setq *pm* 0.05)
0.05
USER(3): (setq *pc* 0.95)
0.95
USER(4): (setq vects (grabdata "TEST.DAT"))
((-1.1854688 -1.016675 -0.99123025 -0.870223 -0.8643655 -0.7244354
  -0.707559 -0.6236887 -0.6062834 -0.60518247 ...)
 (-101.40564 -60.722313 -56.19321 -38.80467 -38.111713 -24.662146
  -23.380352 -17.851412 -16.858852 -16.797672 ...))
USER(5): (setq xvect (first vects))
(-1.1854688 -1.016675 -0.99123025 -0.870223 -0.8643655 -0.7244354
 -0.707559 -0.6236887 -0.6062834 -0.60518247 ...)
USER(6): (setq yvect (second vects))
(-101.40564 -60.722313 -56.19321 -38.80467 -38.111713 -24.662146
 -23.380352 -17.851412 -16.858852 -16.797672 ...)
USER(7): (setq tpop NIL)
NIL
USER(8): (setq tpop (cons (ga-control 50 50 xvect yvect) tpop))

(8.394113 11.719664 49.999992
 (0 1 0 0 1 0 0 1 1 1 1 1 0 1 1 0 0 0 0 0 0 0 0 0 0 1 0 0))
1x^1 + 4exp(2x) + -3exp(-3x) + -3x^1
USER(9): (setq tpop (cons (ga-control 50 50 xvect yvect) tpop))

(11.389402 9.973565 49.999996
 (1 1 0 0 1 0 0 1 0 0 0 0 0 0 1 1 1 0 1 0 1 0 1 0 1 1 1 1))
1exp(1x) + -3exp(-3x) + 3exp(2x) + 2x^4
USER(10): (setq tpop (cons (ga-control 50 50 xvect yvect) tpop))

(1738952.9 49.999516 50.000004
 (1 1 0 1 1 0 1 1 0 0 0 0 0 0 0 0 0 1 1 1 0 1 1 0 1 1 0 1))
2exp(2x) + -3exp(-3x) + -2x^3 + 2exp(2x)
USER(11): (setq tpop (cons (ga-control 50 50 xvect yvect) tpop))

(8.394118 5.9316444 49.99998
 (1 1 0 0 1 0 1 1 1 1 0 1 0 1 1 0 0 0 0 0 0 0 0 0 1 1 0 0))
1exp(2x) + 3exp(2x) + -3exp(-3x) + -2x^1
USER(12): (setq tpop (cons (ga-control 50 50 xvect yvect) tpop))

(1.6171674 8.19443 50.0
 (1 0 0 0 0 0 0 0 0 1 1 0 1 1 0 0 1 1 1 0 0 1 1 1 0 1 0 1))
-3exp(-3x) + 0x^0 + 0x^1 + 3exp(2x)
USER(13): (setq tpop (cons (ga-control 50 50 xvect yvect) tpop))

(2.0779784 9.200583 50.000004
 (1 1 0 0 1 1 0 0 1 0 1 0 1 1 1 1 0 1 0 1 1 1 0 0 0 0 0 0))
1exp(3x) + 2x^0 + 2exp(0x) + -3exp(-3x)
USER(14): (setq tpop (cons (ga-control 50 50 xvect yvect) tpop))

(3.575251 15.847234 50.000008
 (1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0 1 0 0 1 1 0 0 1))
-3exp(-3x) + 0x^4 + 4exp(2x) + 0x^-2
USER(15): (setq tpop (cons (ga-control 50 50 xvect yvect) tpop))
 
(7.7452435 5.6904173 50.000004
 (1 0 0 0 0 0 0 0 0 0 1 1 1 0 1 1 1 1 1 0 1 0 1 0 0 1 0 1))
-3exp(-3x) + -2x^3 + 4exp(2x) + 1x^2
USER(16): (setq tpop (cons (ga-control 50 50 xvect yvect) tpop))
 
(6.6299396 24.557955 50.0
 (1 0 0 0 0 0 0 1 1 0 1 0 1 0 0 0 0 0 0 1 1 1 1 1 1 1 0 1))
-3exp(-3x) + 2exp(-1x) + -3x^0 + 4exp(2x)
USER(17): (setq tpop (cons (ga-control 50 50 xvect yvect) tpop))
 
(1669007.6 49.998474 49.99999
 (0 0 1 1 0 1 0 0 0 0 1 1 1 0 1 1 1 1 1 0 1 1 0 0 0 0 0 0))
0x^-1 + -2x^3 + 4exp(2x) + -3exp(-3x)
USER(18): (length tpop)
10
USER(19): (setq tpop (reverse tpop))
USER(20): (setq *BEST* (append (encode 0 -2 3) (encode 1 4 2) (encode 1 -3 -3)
 (encode 0 0 0)))
(0 0 0 1 1 1 0 1 1 1 ...)
USER(21): (outputmodel (list 0 0 0 *BEST*) xvect "OUTPUTR.DAT")
30
USER(22): (setq *WORST* NIL)
NIL
[1] USER(25): (setq *WORST* NIL)
NIL
[1] USER(26): (setq *WORST* (cons (list 0 0 0 (append (encode 1 -3 -3) (encode 1 3 2) (encode 0 0 0) (encode 0 0 0))) *WORST*))
((0 0 0 (1 0 0 0 0 0 0 1 1 1 ...)))
[2] USER(28): (setq *WORST* (cons (list 0 0 0 (append (encode 1 1 3) (encode 0 2 0) (encode 1 2 0) (encode 1 -3 -3))) *WORST*))
((0 0 0 (1 1 0 0 1 1 0 0 1 0 ...)) (0 0 0 (1 0 0 0 0 0 0 1 1 1 ...)))
[2] USER(29): (setq *WORST* (cons (list 0 0 0 (append (encode 1 -3 -3) (encode 1 4 2) (encode 0 0 0) (encode 0 0 0))) *WORST*))
((0 0 0 (1 0 0 0 0 0 0 1 1 1 ...)) (0 0 0 (1 1 0 0 1 1 0 0 1 0 ...))
 (0 0 0 (1 0 0 0 0 0 0 1 1 1 ...)))
[2] USER(30): (setq *WORST* (cons (list 0 0 0 (append (encode 1 -3 -3) (encode 1 2 -1) (encode 0 -3 0) (encode 0 0 0))) *WORST*))
((0 0 0 (1 0 0 0 0 0 0 1 1 0 ...)) (0 0 0 (1 0 0 0 0 0 0 1 1 1 ...))
 (0 0 0 (1 1 0 0 1 1 0 0 1 0 ...)) (0 0 0 (1 0 0 0 0 0 0 1 1 1 ...)))
[2] USER(31): (setq *WORST* (cons (list 0 0 0 (append (encode 1 -3 -3) (encode 0 -2 3) (encode 1 4 2) (encode 0 1 2))) *WORST*))
((0 0 0 (1 0 0 0 0 0 0 0 0 0 ...)) (0 0 0 (1 0 0 0 0 0 0 1 1 0 ...))
 (0 0 0 (1 0 0 0 0 0 0 1 1 1 ...)) (0 0 0 (1 1 0 0 1 1 0 0 1 0 ...))
 (0 0 0 (1 0 0 0 0 0 0 1 1 1 ...)))
[2] USER(32): (outputmodel (first *WORST*) xvect "WORST1.DAT")
30
[2] USER(33): (outputmodel (second *WORST*) xvect "WORST2.DAT") 
30
[2] USER(34): (outputmodel (third *WORST*) xvect "WORST3.DAT")
30
[2] USER(35): (outputmodel (fourth *WORST*) xvect "WORST4.DAT")
30
[2] USER(36): (outputmodel (fifth *WORST*) xvect "WORST5.DAT")
30
[2] USER(39): (setq w1 NIL)
NIL
[2] USER(40): (setq w1 (cons (grabdata "WORST1.DAT") w1))
[2] USER(41): (setq w1 (cons (grabdata "WORST2.DAT") w1))
[2] USER(42): (setq w1 (cons (grabdata "WORST3.DAT") w1))
[2] USER(43): (setq w1 (cons (grabdata "WORST4.DAT") w1))
[2] USER(44): (setq w1 (cons (grabdata "WORST5.DAT") w1))
[2] USER(45): (setq w2 (mapcar #'second w1))
[4] USER(48): (setq w3 (mapcar #'+ (first w2) (second w2) (third w2) (fourth w2) (fifth w2)))
(-512.21826 -305.5875 -282.57425 -194.26868 -190.75357 -122.70003
 -116.24327 -88.50867 -83.55702 -83.252144 ...)
[7] USER(53): (setq w4 (mapcar #'(lambda (p1) (/ p1 5)) w3))
(-102.44365 -61.1175 -56.51485 -38.853737 -38.150715 -24.540005
 -23.248653 -17.701733 -16.711405 -16.650429 ...)
[7] USER(54): (with-open-file (fstream "AVGWORST.DAT" :direction :output) (print w4 fstream)
)
(-102.44365 -61.1175 -56.51485 -38.853737 -38.150715 -24.540005
 -23.248653 -17.701733 -16.711405 -16.650429 ...)
[8] USER(56): (exit)
; Exiting Lisp
atom.ecn.purdue.edu% exit
atom.ecn.purdue.edu%
script done on Tue Dec 04 16:33:04 2001