Add lists+vars->sbfs/state, lists+headers->sbfs/state, lists->sbfs/state.
This commit is contained in:
parent
43d782f149
commit
b611115f8c
2 changed files with 57 additions and 0 deletions
|
@ -155,3 +155,22 @@ variable, starting from 0.
|
||||||
@ex[
|
@ex[
|
||||||
(lists->tbfs/state '((1 2 3) (1 1 2)))
|
(lists->tbfs/state '((1 2 3) (1 1 2)))
|
||||||
]}
|
]}
|
||||||
|
|
||||||
|
@deftogether[(@defproc[(lists+vars->sbfs/state [vars (Listof Variable)]
|
||||||
|
[lsts (Listof (Listof Real))])
|
||||||
|
(Listof TBF/State)]
|
||||||
|
@defproc[(lists+headers->sbfs/state
|
||||||
|
[lsts (Pairof (Listof Variable) (Listof (Listof Real)))])
|
||||||
|
(Listof TBF/State)]
|
||||||
|
@defproc[(lists->sbfs/state [lsts (Listof (Listof Real))])
|
||||||
|
(Listof TBF/State)])]{
|
||||||
|
|
||||||
|
Like the corresponding TBF-related functions, but which create SBFs.
|
||||||
|
In other words, the input lists are treated as lists of weights, and
|
||||||
|
the thresholds are set to 0.
|
||||||
|
|
||||||
|
@ex[
|
||||||
|
(lists+vars->sbfs/state '(x y) '((1 2) (1 1)))
|
||||||
|
(lists+headers->sbfs/state '((x y) (1 2) (1 1)))
|
||||||
|
(lists->sbfs/state '((1 2) (1 1)))
|
||||||
|
]}
|
||||||
|
|
38
tbn.rkt
38
tbn.rkt
|
@ -26,6 +26,7 @@
|
||||||
sbf/state? apply-tbf/state
|
sbf/state? apply-tbf/state
|
||||||
|
|
||||||
lists+vars->tbfs/state lists+headers->tbfs/state lists->tbfs/state
|
lists+vars->tbfs/state lists+headers->tbfs/state lists->tbfs/state
|
||||||
|
lists+vars->sbfs/state lists+headers->sbfs/state lists->sbfs/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)))
|
||||||
|
@ -118,6 +119,43 @@
|
||||||
(check-equal? (lists->tbfs/state '((1 2 3) (1 1 2)))
|
(check-equal? (lists->tbfs/state '((1 2 3) (1 1 2)))
|
||||||
(list (tbf/state '#hash((x0 . 1) (x1 . 2)) 3)
|
(list (tbf/state '#hash((x0 . 1) (x1 . 2)) 3)
|
||||||
(tbf/state '#hash((x0 . 1) (x1 . 1)) 2)))))
|
(tbf/state '#hash((x0 . 1) (x1 . 1)) 2)))))
|
||||||
|
|
||||||
|
(: lists+vars->sbfs/state (-> (Listof Variable) (Listof (Listof Real))
|
||||||
|
(Listof TBF/State)))
|
||||||
|
(define (lists+vars->sbfs/state vars lsts)
|
||||||
|
(for/list ([lst (in-list lsts)])
|
||||||
|
(make-tbf/state (map (inst cons Variable Real) vars lst) 0)))
|
||||||
|
|
||||||
|
(module+ test
|
||||||
|
(test-case "lists+vars->sbfs/state"
|
||||||
|
(check-equal? (lists+vars->sbfs/state '(x y) '((1 2) (1 1)))
|
||||||
|
(list (tbf/state '#hash((x . 1) (y . 2)) 0)
|
||||||
|
(tbf/state '#hash((x . 1) (y . 1)) 0)))))
|
||||||
|
|
||||||
|
(: lists+headers->sbfs/state (-> (Pairof (Listof Variable) (Listof (Listof Real)))
|
||||||
|
(Listof TBF/State)))
|
||||||
|
(define (lists+headers->sbfs/state lsts)
|
||||||
|
(lists+vars->sbfs/state (car lsts) (cdr lsts)))
|
||||||
|
|
||||||
|
(module+ test
|
||||||
|
(test-case "lists+headers->sbfs/state"
|
||||||
|
(check-equal? (lists+headers->sbfs/state '((x y) (1 2) (1 1)))
|
||||||
|
(list (tbf/state '#hash((x . 1) (y . 2)) 0)
|
||||||
|
(tbf/state '#hash((x . 1) (y . 1)) 0)))))
|
||||||
|
|
||||||
|
(: lists->sbfs/state (-> (Listof (Listof Real)) (Listof TBF/State)))
|
||||||
|
(define (lists->sbfs/state lsts)
|
||||||
|
(lists+vars->sbfs/state
|
||||||
|
(for/list ([i (in-range (length (car lsts)))])
|
||||||
|
(string->symbol (format "x~a" i)))
|
||||||
|
lsts))
|
||||||
|
|
||||||
|
(module+ test
|
||||||
|
(test-case "lists->sbfs/state"
|
||||||
|
(check-equal? (lists->sbfs/state '((1 2) (1 1)))
|
||||||
|
(list
|
||||||
|
(tbf/state '#hash((x0 . 1) (x1 . 2)) 0)
|
||||||
|
(tbf/state '#hash((x0 . 1) (x1 . 1)) 0)))))
|
||||||
)
|
)
|
||||||
|
|
||||||
(module+ test
|
(module+ test
|
||||||
|
|
Loading…
Reference in a new issue