networks: Split the randomness functions into their own section.
This commit is contained in:
parent
6c75a073c0
commit
bba2dfad12
2 changed files with 14 additions and 8 deletions
|
@ -224,12 +224,13 @@
|
||||||
(let ([f1 (stream-first (enumerate-boolean-functions 1))]
|
(let ([f1 (stream-first (enumerate-boolean-functions 1))]
|
||||||
[f1/list (stream-first (enumerate-boolean-functions/list 1))])
|
[f1/list (stream-first (enumerate-boolean-functions/list 1))])
|
||||||
(check-false (f1 #f)) (check-false (f1 #t))
|
(check-false (f1 #f)) (check-false (f1 #t))
|
||||||
(check-false (f1/list '(#f))) (check-false (f1/list '(#t))))
|
(check-false (f1/list '(#f))) (check-false (f1/list '(#t)))))
|
||||||
|
|
||||||
(random-seed 0)
|
(test-case "Random Boolean functions and networks"
|
||||||
(check-equal? (random-boolean-table 2) '((#f #f #t) (#f #t #t) (#t #f #f) (#t #t #f)))
|
(random-seed 0)
|
||||||
(let ([f (random-boolean-function 2)])
|
(check-equal? (random-boolean-table 2) '((#f #f #t) (#f #t #t) (#t #f #f) (#t #t #f)))
|
||||||
(check-true (f #f #f)) (check-false (f #f #t)) (check-true (f #t #f)) (check-false (f #t #t)))
|
(let ([f (random-boolean-function 2)])
|
||||||
(let ([f (random-boolean-function/list 2)])
|
(check-true (f #f #f)) (check-false (f #f #t)) (check-true (f #t #f)) (check-false (f #t #t)))
|
||||||
(check-false (f '(#f #f))) (check-true (f '(#f #t)))
|
(let ([f (random-boolean-function/list 2)])
|
||||||
(check-true (f '(#t #f))) (check-false (f '(#t #t)))))
|
(check-false (f '(#f #f))) (check-true (f '(#f #t)))
|
||||||
|
(check-true (f '(#t #f))) (check-false (f '(#t #t)))))
|
||||||
|
|
|
@ -477,6 +477,11 @@
|
||||||
(define (enumerate-boolean-functions/list n)
|
(define (enumerate-boolean-functions/list n)
|
||||||
(stream-map table->function/list (enumerate-boolean-tables n)))
|
(stream-map table->function/list (enumerate-boolean-tables n)))
|
||||||
|
|
||||||
|
|
||||||
|
;;; =====================================
|
||||||
|
;;; Random Boolean functions and networks
|
||||||
|
;;; =====================================
|
||||||
|
|
||||||
;;; Generates a random truth table for a Boolean function of arity n.
|
;;; Generates a random truth table for a Boolean function of arity n.
|
||||||
(define (random-boolean-table n)
|
(define (random-boolean-table n)
|
||||||
(define/match (num->bool x) [(0) #f] [(1) #t])
|
(define/match (num->bool x) [(0) #f] [(1) #t])
|
||||||
|
|
Loading…
Reference in a new issue