Add lists+headers->tbfs/state.

This commit is contained in:
Sergiu Ivanov 2023-04-03 16:24:33 +02:00
parent 764b4612f1
commit 3455b8aae1
2 changed files with 27 additions and 1 deletions

View file

@ -130,3 +130,17 @@ TBFs, and the rest of the elements are taken to be the weights.
@ex[ @ex[
(lists+vars->tbfs/state '(x y) '((1 2 3) (1 1 2))) (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)))
]}

14
tbn.rkt
View file

@ -25,7 +25,7 @@
(struct-out tbf/state) TBF/State tbf/state-w tbf/state-θ make-tbf/state (struct-out tbf/state) TBF/State tbf/state-w tbf/state-θ make-tbf/state
sbf/state? apply-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))) (: 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))) (check-equal? (lists+vars->tbfs/state '(x y) '((1 2 3) (1 1 2)))
(list (tbf/state '#hash((x . 1) (y . 2)) 3) (list (tbf/state '#hash((x . 1) (y . 2)) 3)
(tbf/state '#hash((x . 1) (y . 1)) 2))))) (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 (module+ test