From 490127593c3df704c7d74b2f9f4a6a4d75b4b4a7 Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Wed, 29 Mar 2023 01:16:12 +0200 Subject: [PATCH] =?UTF-8?q?Type=20tbf/state,=20tbf/state-w,=20and=20tbf/st?= =?UTF-8?q?ate-=CE=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scribblings/tbn.scrbl | 25 +++++++++++++++++++++++++ tbn.rkt | 10 ++++++++++ 2 files changed, 35 insertions(+) diff --git a/scribblings/tbn.scrbl b/scribblings/tbn.scrbl index a2be9d7..539579f 100644 --- a/scribblings/tbn.scrbl +++ b/scribblings/tbn.scrbl @@ -45,3 +45,28 @@ inputs of the TBF must match the number of variables in the state. (require "functions.rkt") (apply-tbf-to-state (tbf #(1 1) 1) (hash 'x1 0 'x2 1)) ]} + +@defstruct*[tbf/state ([weights (VariableMapping Real)] + [threshold Real])]{ + +A state TBF is a @racket[TBF] with named inputs. A state TBF can be +applied to states in an unambiguous ways. + +} + +@deftype[TBF/State]{ + +The type of the instances of @racket[tbf/state]. + +} + +@deftogether[(@defproc[(tbf/state-w [tbfs TBF/State]) (VariableMapping Real)] + @defproc[(tbf/state-θ [tbfs TBF/State]) Real])]{ + +Shorter synonyms for field accessors of @racket[tbf/state]. + +@ex[ +(let ([tbfs (tbf/state (hash 'a 1 'b 1) 1)]) + (values (tbf/state-w tbfs) + (tbf/state-θ tbfs))) +]} diff --git a/tbn.rkt b/tbn.rkt index 2927eb0..34f9625 100644 --- a/tbn.rkt +++ b/tbn.rkt @@ -14,6 +14,8 @@ (provide apply-tbf-to-state + + (struct-out tbf/state) TBF/State tbf/state-w tbf/state-θ ) (: apply-tbf-to-state (-> TBF (State (U Zero One)) (U Zero One))) @@ -26,6 +28,14 @@ (define st (hash 'x1 0 'x2 1)) (define f (tbf #(1 1) 1)) (check-equal? (apply-tbf-to-state f st) 0))) + + (struct tbf/state ([weights : (VariableMapping Real)] + [threshold : Real]) + #:transparent + #:type-name TBF/State) + (define tbf/state-w tbf/state-weights) + (define tbf/state-θ tbf/state-threshold) + ) (module+ test