Type vector-boolean->01.

This commit is contained in:
Sergiu Ivanov 2022-04-21 13:49:15 +02:00
parent e44d9c7748
commit f3a8c65e9d
2 changed files with 19 additions and 11 deletions

View file

@ -27,7 +27,7 @@
enumerate-boolean-functions/pv enumerate-boolean-functions/list
random-boolean-table random-boolean-function random-boolean-function/list
(struct-out tbf) tbf-w tbf-θ)
(struct-out tbf) tbf-w tbf-θ vector-boolean->01)
(module+ test
(require typed/rackunit))
@ -360,6 +360,14 @@
(define tbf-w tbf-weights)
(define tbf-θ tbf-threshold)
(: vector-boolean->01 (-> (Vectorof Boolean) (Vectorof (U Zero One))))
(define (vector-boolean->01 bool-v)
(vector-map (λ (x) (any->01 x)) bool-v))
(module+ test
(test-case "vector-boolean->01"
(check-equal? (vector-boolean->01 #(#t #f #f)) #(1 0 0))))
(module untyped racket
(module+ test
(require rackunit))
@ -446,7 +454,7 @@
enumerate-boolean-functions/pv enumerate-boolean-functions/list
random-boolean-table random-boolean-function random-boolean-function/list
(struct-out tbf))
(struct-out tbf) vector-boolean->01)
(require (rename-in (submod 'typed untyped)
[tabulate tabulate/untyped]
@ -457,7 +465,6 @@
(contract-out
[tbf-w (-> tbf? (vectorof number?))]
[tbf-θ (-> tbf? number?)]
[vector-boolean->01 (-> (vectorof boolean?) (vectorof (or/c 0 1)))]
[apply-tbf (-> tbf? (vectorof (or/c 0 1)) (or/c 0 1))]
[apply-tbf/boolean (-> tbf? (vectorof boolean?) boolean?)]
[list->tbf (-> (cons/c number? (cons/c number? (listof number?))) tbf?)]
@ -481,14 +488,6 @@
;;; Threshold Boolean functions
;;; ===========================
;;; Converts a Boolean vector to a 0-1 vector.
(define (vector-boolean->01 bool-v)
(vector-map any->01 bool-v))
(module+ test
(test-case "boolean->0-1"
(check-equal? (vector-boolean->01 #(#t #f #f)) #(1 0 0))))
;;; Applies the TBF to its inputs.
;;;
;;; Applying a TBF consists in multiplying the weights by the

View file

@ -383,6 +383,15 @@ Shortcuts for @racket[tbf-weights] and @racket[tbf-threshold].
}
@defproc[(vector-boolean->01 [bool-v (Vectorof Boolean)])
(Vectorof (U Zero One))]{
Converts a Boolean vector to a vector of zeros and ones.
@examples[#:eval functions-evaluator
(vector-boolean->01 #(#t #f #f))
]}
@section[#:tag "fuctions/untyped"]{Untyped definitions}
@defmodule[(submod dds/functions typed untyped)]