From 8025938b81e58d3786373816e254f13a5adeeec4 Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Mon, 26 May 2025 16:11:54 +0200 Subject: [PATCH] trying to calculate the loss gradient when varying parameters --- decons.lisp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/decons.lisp b/decons.lisp index ee92a0b..1fa871f 100644 --- a/decons.lisp +++ b/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)