Type tbf/state, tbf/state-w, and tbf/state-θ.

This commit is contained in:
Sergiu Ivanov 2023-03-29 01:16:12 +02:00
parent fa88c15454
commit 490127593c
2 changed files with 35 additions and 0 deletions

View file

@ -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)))
]}

10
tbn.rkt
View file

@ -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