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,8 +224,9 @@
|
||||||
(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)))))
|
||||||
|
|
||||||
|
(test-case "Random Boolean functions and networks"
|
||||||
(random-seed 0)
|
(random-seed 0)
|
||||||
(check-equal? (random-boolean-table 2) '((#f #f #t) (#f #t #t) (#t #f #f) (#t #t #f)))
|
(check-equal? (random-boolean-table 2) '((#f #f #t) (#f #t #t) (#t #f #f) (#t #t #f)))
|
||||||
(let ([f (random-boolean-function 2)])
|
(let ([f (random-boolean-function 2)])
|
||||||
|
|
|
@ -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