clean-up: code improvements, remove obsolete stuff
This commit is contained in:
parent
cff6311103
commit
fc83700642
1 changed files with 10 additions and 21 deletions
31
decons.lisp
31
decons.lisp
|
@ -5,12 +5,10 @@
|
|||
(:local-nicknames (:shape :scopes/shape)
|
||||
(:util :scopes/util))
|
||||
(:export #:rapply #:rreduce #:radd #:rmul #:rsub #:rdiv
|
||||
#:combine #:default-deviation #:l2-loss
|
||||
#:*trials* #:trial #:try
|
||||
#:default-deviation #:l2-loss #:trial
|
||||
#:line
|
||||
#:lgx
|
||||
#:*obj*
|
||||
))
|
||||
#:*obj* #:*trials* #:try))
|
||||
|
||||
(in-package :decons)
|
||||
|
||||
|
@ -45,24 +43,15 @@
|
|||
(defun rsub (a b) (rapply #'- a b))
|
||||
(defun rdiv (a b) (rapply #'/ a b))
|
||||
|
||||
;;;; combine
|
||||
|
||||
(defun combine (l1 l2)
|
||||
(mapcar (lambda (x) (scons (pop l1) x)) l2))
|
||||
|
||||
(defgeneric scons (a b)
|
||||
(:method (a b) (list a b))
|
||||
(:method (a (b list)) (cons a b)))
|
||||
|
||||
;;;; loss calculation
|
||||
;;;; loss calculation, collect trial data (parameters, resulting loss)
|
||||
|
||||
(defun sqr (x) (* x x))
|
||||
|
||||
(defun sum (data) (reduce #'+ data))
|
||||
|
||||
(defun default-deviation (observed calculated &key (norm #'sqr))
|
||||
(sum (mapcar (lambda (p) (funcall norm (apply #'- p)))
|
||||
(combine observed calculated))))
|
||||
(sum (mapcar (lambda (a b) (funcall norm (- a b)))
|
||||
observed calculated)))
|
||||
|
||||
(defun l2-loss (target &key (deviation #'default-deviation))
|
||||
(lambda (dataset) ; expectant function
|
||||
|
@ -71,8 +60,6 @@
|
|||
(calculated (funcall objective theta)))
|
||||
(funcall deviation (cadr dataset) calculated)))))
|
||||
|
||||
(defvar *trials* nil)
|
||||
|
||||
(defclass trial ()
|
||||
((theta :reader theta :initarg :theta)
|
||||
(loss :reader loss :initarg :loss)))
|
||||
|
@ -80,9 +67,6 @@
|
|||
(defmethod print-object ((tr trial) stream)
|
||||
(shape:print-slots tr stream 'theta 'loss))
|
||||
|
||||
(defun try (obj theta)
|
||||
(push (make-instance 'trial :theta theta :loss (funcall obj theta)) *trials*))
|
||||
|
||||
;;;; logging (printing) functions for debugging purposes
|
||||
|
||||
(defun lgx (op)
|
||||
|
@ -99,3 +83,8 @@
|
|||
;;;; working area
|
||||
|
||||
(defvar *obj* nil)
|
||||
|
||||
(defvar *trials* nil)
|
||||
|
||||
(defun try (obj theta)
|
||||
(push (make-instance 'trial :theta theta :loss (funcall obj theta)) *trials*))
|
||||
|
|
Loading…
Add table
Reference in a new issue