Type vector-boolean->01.
This commit is contained in:
parent
e44d9c7748
commit
f3a8c65e9d
2 changed files with 19 additions and 11 deletions
|
@ -27,7 +27,7 @@
|
||||||
enumerate-boolean-functions/pv enumerate-boolean-functions/list
|
enumerate-boolean-functions/pv enumerate-boolean-functions/list
|
||||||
random-boolean-table random-boolean-function random-boolean-function/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
|
(module+ test
|
||||||
(require typed/rackunit))
|
(require typed/rackunit))
|
||||||
|
@ -360,6 +360,14 @@
|
||||||
(define tbf-w tbf-weights)
|
(define tbf-w tbf-weights)
|
||||||
(define tbf-θ tbf-threshold)
|
(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 untyped racket
|
||||||
(module+ test
|
(module+ test
|
||||||
(require rackunit))
|
(require rackunit))
|
||||||
|
@ -446,7 +454,7 @@
|
||||||
enumerate-boolean-functions/pv enumerate-boolean-functions/list
|
enumerate-boolean-functions/pv enumerate-boolean-functions/list
|
||||||
random-boolean-table random-boolean-function random-boolean-function/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)
|
(require (rename-in (submod 'typed untyped)
|
||||||
[tabulate tabulate/untyped]
|
[tabulate tabulate/untyped]
|
||||||
|
@ -457,7 +465,6 @@
|
||||||
(contract-out
|
(contract-out
|
||||||
[tbf-w (-> tbf? (vectorof number?))]
|
[tbf-w (-> tbf? (vectorof number?))]
|
||||||
[tbf-θ (-> tbf? 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 (-> tbf? (vectorof (or/c 0 1)) (or/c 0 1))]
|
||||||
[apply-tbf/boolean (-> tbf? (vectorof boolean?) boolean?)]
|
[apply-tbf/boolean (-> tbf? (vectorof boolean?) boolean?)]
|
||||||
[list->tbf (-> (cons/c number? (cons/c number? (listof number?))) tbf?)]
|
[list->tbf (-> (cons/c number? (cons/c number? (listof number?))) tbf?)]
|
||||||
|
@ -481,14 +488,6 @@
|
||||||
;;; Threshold Boolean functions
|
;;; 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.
|
;;; Applies the TBF to its inputs.
|
||||||
;;;
|
;;;
|
||||||
;;; Applying a TBF consists in multiplying the weights by the
|
;;; Applying a TBF consists in multiplying the weights by the
|
||||||
|
|
|
@ -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}
|
@section[#:tag "fuctions/untyped"]{Untyped definitions}
|
||||||
|
|
||||||
@defmodule[(submod dds/functions typed untyped)]
|
@defmodule[(submod dds/functions typed untyped)]
|
||||||
|
|
Loading…
Reference in a new issue