summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEtenil <dev@etenil.net>2026-02-15 12:24:45 +0000
committerEtenil <dev@etenil.net>2026-02-21 14:47:38 +0100
commit77d1b104115d8e29a5217d82ba47fd9e542fbc8a (patch)
tree259a543e4031b4970fc190130930921bd20a5694
parent58623e745797c08356bf9efc5216387d53e775b7 (diff)
Set up ASDF and tests
-rw-r--r--ffnn.asd24
-rw-r--r--package.lisp4
-rw-r--r--src/algo1.lisp (renamed from algo1.lisp)121
-rw-r--r--src/package.lisp2
-rw-r--r--tests/algo1.lisp70
5 files changed, 120 insertions, 101 deletions
diff --git a/ffnn.asd b/ffnn.asd
new file mode 100644
index 0000000..1e5ac64
--- /dev/null
+++ b/ffnn.asd
@@ -0,0 +1,24 @@
+(defsystem "ffnn"
+ :version "0.0.1"
+ :author ""
+ :license ""
+ :depends-on ()
+ :components ((:module "src"
+ :components
+ ((:file "package")
+ (:file "algo1")
+ (:file "algo2"))))
+ :description ""
+ :in-order-to ((test-op (test-op "ffnn/tests"))))
+
+(defsystem "ffnn/tests"
+ :author ""
+ :license ""
+ :depends-on ("ffnn"
+ "rove")
+ :components ((:module "tests"
+ :components
+ ((:file "algo1")
+ (:file "algo2"))))
+ :description "Test system for ffnn"
+ :perform (test-op (op c) (symbol-call :rove :run c)))
diff --git a/package.lisp b/package.lisp
new file mode 100644
index 0000000..4bbd1d2
--- /dev/null
+++ b/package.lisp
@@ -0,0 +1,4 @@
+(defpackage ffnn
+ (:use :cl))
+(in-package :ffnn)
+
diff --git a/algo1.lisp b/src/algo1.lisp
index 5fd4882..c3ef924 100644
--- a/algo1.lisp
+++ b/src/algo1.lisp
@@ -36,6 +36,11 @@
;;;; template and a raw input patch.
;;;; ==========================================================================
+(defpackage ffnn.algo1
+ (:use :cl)
+ (:export #:make-rectified-polynomial)
+ (:export #:sum-memories))
+(in-package :ffnn.algo1)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; 1. THE ACTIVATION FUNCTION ;;;
@@ -88,35 +93,27 @@
;; Returns the total "evidence" for and against this row.
(return (list pluses minuses))))
-(when nil
- ;; Test to understand how sum-one-row works. A plus is added when
- ;; the symbol is in the memory row, if the symbol occurs on the
- ;; index, 2 pluses are added. Eval with SLIME (C-x C-e at the
- ;; closing brace.)
- (sum-one-row 'foo
- '((foo) () (bar))
- '((foo) (foo) (bar))
- 1) ; (3 1) - strong sign that foo belongs there
- (sum-one-row 'foo
- '((bar) () (bar))
- '((bar) (bar) (foo))
- 1) ; (-1 1) - undecided?
- (sum-one-row 'foo
- '((bar) () (bar))
- '((bar) (bar) (bar))
- 1) ; (1 3) - allergy!
- (sum-one-row 'foo
- '((foo) () (bar))
- '((foo) (foo) (bar))
- nil) ; (3 1) - strong sign that foo belongs there
- )
-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; 3. THE SPATIAL AGGREGATOR ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; This loops through the rows of a single memory "block." Think of a
;;; memory block.
+;;;
+;;; This is like calling
+;;; This outputs (2 0)
+;;; (sum-one-row 'foo
+;;; '((foo) (foo))
+;;; '((foo) (foo))
+;;; 0)
+;;; ;; This outputs (2 2)
+;;; (sum-one-row 'foo
+;;; '((bar) (bar))
+;;; '((bar) (bar))
+;;; nil)
+;;; ;; final output: 12
+;;; (- (funcall (make-rectified-polynomial 2) 4)
+;;; (funcall (make-rectified-polynomial 2) 2))
(defun sum-one-memory
(item input memory
&rest keys
@@ -148,43 +145,6 @@
(- (funcall rectified-polynomial row-pluses)
(funcall rectified-polynomial row-minuses)))))
-(when nil
- ;;; Tests for sum-one-memory
- (sum-one-memory 'foo
- '(((foo) (foo))
- ((bar) (bar))) ;; Input
- '(((foo) (foo))
- ((bar) (bar))) ;; Memory
- :rectified-polynomial (make-rectified-polynomial 2)
- :target-row 0 :target-col 0
- :start-row 0 :start-col 0)
-
- ;; The above is like calling (you can try!):
- ;; This outputs (2 0)
- (sum-one-row 'foo
- '((foo) (foo))
- '((foo) (foo))
- 0)
- ;; This outputs (2 2)
- (sum-one-row 'foo
- '((bar) (bar))
- '((bar) (bar))
- nil)
- ;; final output: 12
- (- (funcall (make-rectified-polynomial 2) 4)
- (funcall (make-rectified-polynomial 2) 2))
-
-
- (sum-one-memory 'foo
- '(((foo) (foo))
- ((baz) (baz)))
- '(((foo) (foo))
- ((foo) (foo)))
- :rectified-polynomial (make-rectified-polynomial 2)
- :target-row 0 :target-col 0
- :start-row 0 :start-col 0)
- )
-
;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; 4. Decision making ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -208,47 +168,6 @@
(values NIL old)
(values t old)))))
-(when nil
- ;;; Test cases for sum-memories, eval the defparameters first!
-
- (defparameter *memories*
- '((((foo) (foo)) ((bar) (bar)))
- (((baz) (baz)) ((foo) (foo)))
- (((qux) (qux)) ((qux) (qux)))))
-
- (defparameter *poly-2* (make-rectified-polynomial 2))
-
- ;; Return T
- (sum-memories 'foo
- '(((foo) (foo)) ((bar) (bar))) ;; Input
- *memories* ;; The Library of templates
- :rectified-polynomial *poly-2*
- :start-row 0 :start-col 0
- :target-row 0 :target-col 0)
-
- ;; Returns NIL
- (sum-memories 'foo
- '(((qux) (qux)) ((qux) (qux)))
- *memories*
- :rectified-polynomial *poly-2*
- :start-row 0 :start-col 0
- :target-row 0 :target-col 0)
- ;; returns NIL
- (sum-memories 'foo
- '(((baz) (baz)) ((foo) (foo)))
- *memories*
- :rectified-polynomial *poly-2*
- :start-row 0 :start-col 0
- :target-row 0 :target-col 0)
- ;; returns T (targetting second row)
- (sum-memories 'foo
- '(((baz) (baz)) ((foo) (foo)))
- *memories*
- :rectified-polynomial *poly-2*
- :start-row 0 :start-col 0
- :target-row 1 :target-col 0)
- )
-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Game AI for a tic-tac-toe board! ;;;
diff --git a/src/package.lisp b/src/package.lisp
new file mode 100644
index 0000000..615c02e
--- /dev/null
+++ b/src/package.lisp
@@ -0,0 +1,2 @@
+(defpackage ffnn
+ (:use :cl))
diff --git a/tests/algo1.lisp b/tests/algo1.lisp
new file mode 100644
index 0000000..5d5f340
--- /dev/null
+++ b/tests/algo1.lisp
@@ -0,0 +1,70 @@
+(defpackage ffnn/tests/algo1
+ (:use :cl
+ :ffnn
+ :ffnn.algo1
+ :rove))
+
+(in-package :ffnn/tests/algo1)
+
+
+(deftest check-sum-one-row
+ (testing "sum-one-row"
+ (dolist (case '((foo ((foo) () (bar)) ((foo) (foo) (bar)) 1 (3 1))
+ (foo ((bar) () (bar)) ((bar) (bar) (foo)) 1 (-1 1))
+ (foo ((bar) () (bar)) ((bar) (bar) (bar)) 1 (1 3))
+ (foo ((foo) () (bar)) ((foo) (foo) (bar)) nil (1 1))))
+ (destructuring-bind (item input memory index expected) case
+ (ok (equal (ffnn.algo1::sum-one-row item input memory index)
+ expected))))))
+
+(deftest check-sum-one-memory
+ (testing "Sum one memory"
+ (ok (equal (ffnn.algo1::sum-one-memory 'foo
+ '(((foo) (foo))
+ ((bar) (bar))) ;; Input
+ '(((foo) (foo))
+ ((bar) (bar))) ;; Memory
+ :rectified-polynomial (ffnn.algo1::make-rectified-polynomial 2)
+ :target-row 0 :target-col 0
+ :start-row 0 :start-col 0)
+ 12))
+ (ok (equal (ffnn.algo1::sum-one-memory 'foo
+ '(((foo) (foo))
+ ((baz) (baz)))
+ '(((foo) (foo))
+ ((foo) (foo)))
+ :rectified-polynomial (ffnn.algo1::make-rectified-polynomial 2)
+ :target-row 0 :target-col 0
+ :start-row 0 :start-col 0)
+ 0))))
+
+(deftest check-sum-memories
+ (testing "Sum memories"
+ (let ((memories '((((foo) (foo)) ((bar) (bar)))
+ (((baz) (baz)) ((foo) (foo)))
+ (((qux) (qux)) ((qux) (qux)))))
+ (poly-2 (ffnn.algo1::make-rectified-polynomial 2)))
+ (ok (sum-memories 'foo
+ '(((foo) (foo)) ((bar) (bar))) ;; Input
+ memories ;; The Library of templates
+ :rectified-polynomial poly-2
+ :start-row 0 :start-col 0
+ :target-row 0 :target-col 0))
+ (ng (sum-memories 'foo
+ '(((qux) (qux)) ((qux) (qux)))
+ memories
+ :rectified-polynomial poly-2
+ :start-row 0 :start-col 0
+ :target-row 0 :target-col 0))
+ (ng (sum-memories 'foo
+ '(((baz) (baz)) ((foo) (foo)))
+ memories
+ :rectified-polynomial poly-2
+ :start-row 0 :start-col 0
+ :target-row 0 :target-col 0))
+ (ok (sum-memories 'foo
+ '(((baz) (baz)) ((foo) (foo)))
+ memories
+ :rectified-polynomial poly-2
+ :start-row 0 :start-col 0
+ :target-row 1 :target-col 0)))))