csys: provide generic synapse op: modify-value

This commit is contained in:
Helmut Merz 2026-09-08 19:20:25 +02:00
parent 385cbefe16
commit d4b032f156

View file

@ -14,7 +14,7 @@
#:neuron #:std-proc #:eff-proc #:neuron #:std-proc #:eff-proc
#:handle-action #:basic-actions #:forward #:notify #:handle-action #:basic-actions #:forward #:notify
#:no-op #:printer #:value-add #:create #:connect #:no-op #:printer #:value-add #:create #:connect
#:multiply #:modify-value #:multiply #:divide
#:send-message #:send-create #:send-connect #:send-switch)) #:send-message #:send-create #:send-connect #:send-switch))
(in-package :scopes/csys) (in-package :scopes/csys)
@ -154,7 +154,7 @@
(setf (value scope) (shape:data-value msg :value)) (setf (value scope) (shape:data-value msg :value))
(values msg scope))) (values msg scope)))
(defun value-add (&key (bias 0) (threshold 1) (limits '(0 10))) (defun value-add (&key (bias 0) (threshold 1) (limits '(0 15)))
(lambda (msg scope) (lambda (msg scope)
(let* ((val (getf (shape:data msg) :value)) (let* ((val (getf (shape:data msg) :value))
(newval (+ val (value scope))) (newval (+ val (value scope)))
@ -210,12 +210,18 @@
;;;; synapse ops ;;;; synapse ops
(defun multiply (n) (defun modify-value (fn &rest args)
(lambda (msg) (lambda (msg)
(let* ((data (copy-list (shape:data msg)))) (let ((data (copy-list (shape:data msg))))
(setf (getf data :value) (* (getf data :value 0) n)) (setf (getf data :value) (apply fn (getf data :value 0) args))
(message:create (shape:head msg) :data data)))) (message:create (shape:head msg) :data data))))
(defun multiply (n)
(modify-value #'* n))
(defun divide (n)
(modify-value #'floor n))
;;;; public shortcuts ;;;; public shortcuts
(defun send-message (cell head data) (defun send-message (cell head data)