trying to calculate the loss gradient when varying parameters
This commit is contained in:
parent
19ca8adbfc
commit
8025938b81
1 changed files with 11 additions and 1 deletions
12
decons.lisp
12
decons.lisp
|
@ -5,7 +5,7 @@
|
|||
(:local-nicknames (:shape :scopes/shape)
|
||||
(:util :scopes/util))
|
||||
(:export #:rapply #:rreduce #:radd #:rmul #:rsub #:rdiv
|
||||
#:default-deviation #:l2-loss #:trial
|
||||
#:default-deviation #:l2-loss #:trial #:gradient
|
||||
#:line
|
||||
#:*obj* #:*trials* #:try))
|
||||
|
||||
|
@ -66,6 +66,16 @@
|
|||
(defmethod print-object ((tr trial) stream)
|
||||
(shape:print-slots tr stream 'theta 'loss))
|
||||
|
||||
(defun gradient (target dataset)
|
||||
(let ((expect (funcall (l2-loss target) dataset)))
|
||||
(lambda (theta)
|
||||
(let* ((loss0 (funcall expect theta))
|
||||
(loss1 (funcall expect (vary theta))))
|
||||
(- loss0 loss1)))))
|
||||
|
||||
(defun vary (theta)
|
||||
(mapcar (lambda (x) (- x 0.01)) theta))
|
||||
|
||||
;;;; parameterized target functions
|
||||
|
||||
(defun line (x)
|
||||
|
|
Loading…
Add table
Reference in a new issue