From ed679278030dda12b682033185ccaa1ecb170495 Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Wed, 29 Mar 2023 01:21:29 +0200 Subject: [PATCH] Type make-tbf/state. --- scribblings/tbn.scrbl | 11 +++++++++++ tbn.rkt | 11 ++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/scribblings/tbn.scrbl b/scribblings/tbn.scrbl index 539579f..044e0da 100644 --- a/scribblings/tbn.scrbl +++ b/scribblings/tbn.scrbl @@ -70,3 +70,14 @@ Shorter synonyms for field accessors of @racket[tbf/state]. (values (tbf/state-w tbfs) (tbf/state-θ tbfs))) ]} + +@defproc[(make-tbf/state [pairs (Listof (Pairof Variable Real))] + [threshold Real]) + TBF/State]{ + +Makes a @racket[TBF/State] from a list of pairs of names of variables +and weights, as well as a threshold. + +@ex[ +(make-tbf/state '((x1 . 1) (x2 . 1)) 1) +]} diff --git a/tbn.rkt b/tbn.rkt index 34f9625..116f805 100644 --- a/tbn.rkt +++ b/tbn.rkt @@ -15,7 +15,7 @@ (provide apply-tbf-to-state - (struct-out tbf/state) TBF/State tbf/state-w tbf/state-θ + (struct-out tbf/state) TBF/State tbf/state-w tbf/state-θ make-tbf/state ) (: apply-tbf-to-state (-> TBF (State (U Zero One)) (U Zero One))) @@ -36,6 +36,15 @@ (define tbf/state-w tbf/state-weights) (define tbf/state-θ tbf/state-threshold) + (: make-tbf/state (-> (Listof (Pairof Variable Real)) Real TBF/State)) + (define (make-tbf/state pairs threshold) + (tbf/state (make-immutable-hash pairs) threshold)) + + (module+ test + (test-case "tbf/state" + (define f (make-tbf/state '((x1 . 1) (x2 . 1)) 1)) + (check-equal? (tbf/state-w f) #hash((x1 . 1) (x2 . 1))) + (check-equal? (tbf/state-θ f) 1))) ) (module+ test