diff --git a/scribblings/tbn.scrbl b/scribblings/tbn.scrbl index b3e241e..c69eedb 100644 --- a/scribblings/tbn.scrbl +++ b/scribblings/tbn.scrbl @@ -130,3 +130,17 @@ TBFs, and the rest of the elements are taken to be the weights. @ex[ (lists+vars->tbfs/state '(x y) '((1 2 3) (1 1 2))) ]} + +@defproc[(lists+headers->tbfs/state [lsts+headers (Pairof (Listof Variable) (Listof (Listof Real)))]) + (Listof TBF/State)]{ + +Like @racket[lists+vars->tbfs/state], but the names of the variables +are taken from the first line of @racket[lsts+headers]. + +All the lines in @racket[lsts+headers] are assumed to be of the same +lenght, which means in particular that the last element of the first +line (the threshold column) is discarded. + +@ex[ +(lists+headers->tbfs/state '((x y f) (1 2 3) (1 1 2))) +]} diff --git a/tbn.rkt b/tbn.rkt index 8602c73..c61d40a 100644 --- a/tbn.rkt +++ b/tbn.rkt @@ -25,7 +25,7 @@ (struct-out tbf/state) TBF/State tbf/state-w tbf/state-θ make-tbf/state sbf/state? apply-tbf/state - lists+vars->tbfs/state + lists+vars->tbfs/state lists+headers->tbfs/state ) (: apply-tbf-to-state (-> TBF (State (U Zero One)) (U Zero One))) @@ -93,6 +93,18 @@ (check-equal? (lists+vars->tbfs/state '(x y) '((1 2 3) (1 1 2))) (list (tbf/state '#hash((x . 1) (y . 2)) 3) (tbf/state '#hash((x . 1) (y . 1)) 2))))) + + (: lists+headers->tbfs/state (-> (Pairof (Listof Variable) (Listof (Listof Real))) + (Listof TBF/State))) + (define (lists+headers->tbfs/state lsts+headers) + (lists+vars->tbfs/state (drop-right (car lsts+headers) 1) + (cdr lsts+headers))) + + (module+ test + (test-case "lists+headers->tbfs/state" + (check-equal? (lists+headers->tbfs/state '((x y f) (1 2 3) (1 1 2))) + (list (tbf/state '#hash((x . 1) (y . 2)) 3) + (tbf/state '#hash((x . 1) (y . 1)) 2))))) ) (module+ test