functions: Add tbf.

This commit is contained in:
Sergiu Ivanov 2020-06-03 22:51:06 +02:00
parent 6247f28958
commit e237e9e019

View file

@ -10,6 +10,9 @@
(require "utils.rkt") (require "utils.rkt")
(provide (provide
;; Structures
(contract-out
[struct tbf ((weights number?) (threshold (vectorof number?)))])
;; Functions ;; Functions
(contract-out (contract-out
[tabulate (-> procedure? (listof generic-set?) (listof list?))] [tabulate (-> procedure? (listof generic-set?) (listof list?))]
@ -23,7 +26,9 @@
[enumerate-boolean-functions/list (-> number? (stream/c procedure?))] [enumerate-boolean-functions/list (-> number? (stream/c procedure?))]
[random-boolean-table (-> number? (listof (*list/c boolean? boolean?)))] [random-boolean-table (-> number? (listof (*list/c boolean? boolean?)))]
[random-boolean-function (-> number? procedure?)] [random-boolean-function (-> number? procedure?)]
[random-boolean-function/list (-> number? procedure?)])) [random-boolean-function/list (-> number? procedure?)]
[tbf-w (-> tbf? (vectorof number?))]
[tbf-θ (-> tbf? number?)]))
(module+ test (module+ test
(require rackunit)) (require rackunit))
@ -197,3 +202,16 @@
(define f (random-boolean-function/list 2)) (define f (random-boolean-function/list 2))
(check-false (f '(#f #f))) (check-true (f '(#f #t))) (check-false (f '(#f #f))) (check-true (f '(#f #t)))
(check-true (f '(#t #f))) (check-false (f '(#t #t))))) (check-true (f '(#t #f))) (check-false (f '(#t #t)))))
;;; ===========================
;;; Threshold Boolean functions
;;; ===========================
;;; A threshold Boolean function (TBF) is a pair (w, θ), where w is a
;;; vector of weights and θ is the threshold.
(struct tbf (weights threshold) #:transparent)
;;; Unicode shortcuts for accessing the elements of a TBF.
(define tbf-w tbf-weights)
(define tbf-θ tbf-threshold)