aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/math/logic/fuzzy.lux
diff options
context:
space:
mode:
authorEduardo Julian2019-07-24 23:50:16 -0400
committerEduardo Julian2019-07-24 23:50:16 -0400
commit6425e4cfe470b54d76bb316cbdb6fdb21dd63130 (patch)
tree67e0ca73e9f23b36293fbe896337c7a3a336b9bc /stdlib/source/test/lux/math/logic/fuzzy.lux
parent30c19b40f5fd583d19aa7cf495a19c1b91f86320 (diff)
No more "r/"-prefixed functions.
Diffstat (limited to '')
-rw-r--r--stdlib/source/test/lux/math/logic/fuzzy.lux85
1 files changed, 43 insertions, 42 deletions
diff --git a/stdlib/source/test/lux/math/logic/fuzzy.lux b/stdlib/source/test/lux/math/logic/fuzzy.lux
index 3d21a1f21..35dff4a03 100644
--- a/stdlib/source/test/lux/math/logic/fuzzy.lux
+++ b/stdlib/source/test/lux/math/logic/fuzzy.lux
@@ -2,13 +2,14 @@
[lux #*
["%" data/text/format (#+ format)]
[abstract/monad (#+ do)]
- ["r" math/random (#+ Random)]
+ [math
+ ["." random (#+ Random)]]
["_" test (#+ Test)]
[data
["." bit ("#@." equivalence)]
[number
["." nat]
- ["." rev]]
+ ["r" rev]]
[collection
["." list]
["." set]]]]
@@ -21,8 +22,8 @@
[(def: <name>
Test
(<| (_.context (%.name (name-of <triangle>)))
- (do r.monad
- [values (r.set <hash> 3 <gen>)
+ (do random.monad
+ [values (random.set <hash> 3 <gen>)
#let [[x y z] (case (set.to-list values)
(^ (list x y z))
[x y z]
@@ -39,29 +40,29 @@
triangle (<triangle> x y z)]]
($_ _.and
(_.test "The middle value will always have maximum membership."
- (r/= //.true (/.membership middle triangle)))
+ (r.= //.true (/.membership middle triangle)))
(_.test "Boundary values will always have 0 membership."
- (and (r/= //.false (/.membership bottom triangle))
- (r/= //.false (/.membership top triangle))))
+ (and (r.= //.false (/.membership bottom triangle))
+ (r.= //.false (/.membership top triangle))))
(_.test "Values within range, will have membership > 0."
- (bit@= (r/> //.false (/.membership sample triangle))
+ (bit@= (r.> //.false (/.membership sample triangle))
(and (<gt> bottom sample)
(<lt> top sample))))
(_.test "Values outside of range, will have membership = 0."
- (bit@= (r/= //.false (/.membership sample triangle))
+ (bit@= (r.= //.false (/.membership sample triangle))
(or (<lte> bottom sample)
(<gte> top sample))))
))))]
- [rev-triangles "Rev" rev.hash r.rev /.triangle r/< r/<= r/> r/>=]
+ [rev-triangles "Rev" r.hash random.rev /.triangle r.< r.<= r.> r.>=]
)
(template [<name> <desc> <hash> <gen> <trapezoid> <lt> <lte> <gt> <gte>]
[(def: <name>
Test
(<| (_.context (%.name (name-of <trapezoid>)))
- (do r.monad
- [values (r.set <hash> 4 <gen>)
+ (do random.monad
+ [values (random.set <hash> 4 <gen>)
#let [[w x y z] (case (set.to-list values)
(^ (list w x y z))
[w x y z]
@@ -78,96 +79,96 @@
trapezoid (<trapezoid> w x y z)]]
($_ _.and
(_.test "The middle values will always have maximum membership."
- (and (r/= //.true (/.membership middle-bottom trapezoid))
- (r/= //.true (/.membership middle-top trapezoid))))
+ (and (r.= //.true (/.membership middle-bottom trapezoid))
+ (r.= //.true (/.membership middle-top trapezoid))))
(_.test "Boundary values will always have 0 membership."
- (and (r/= //.false (/.membership bottom trapezoid))
- (r/= //.false (/.membership top trapezoid))))
+ (and (r.= //.false (/.membership bottom trapezoid))
+ (r.= //.false (/.membership top trapezoid))))
(_.test "Values within inner range will have membership = 1"
- (bit@= (r/= //.true (/.membership sample trapezoid))
+ (bit@= (r.= //.true (/.membership sample trapezoid))
(and (<gte> middle-bottom sample)
(<lte> middle-top sample))))
(_.test "Values within range, will have membership > 0."
- (bit@= (r/> //.false (/.membership sample trapezoid))
+ (bit@= (r.> //.false (/.membership sample trapezoid))
(and (<gt> bottom sample)
(<lt> top sample))))
(_.test "Values outside of range, will have membership = 0."
- (bit@= (r/= //.false (/.membership sample trapezoid))
+ (bit@= (r.= //.false (/.membership sample trapezoid))
(or (<lte> bottom sample)
(<gte> top sample))))
))))]
- [rev-trapezoids "Rev" rev.hash r.rev /.trapezoid r/< r/<= r/> r/>=]
+ [rev-trapezoids "Rev" r.hash random.rev /.trapezoid r.< r.<= r.> r.>=]
)
(def: #export triangle
(Random (Fuzzy Rev))
- (do r.monad
- [x r.rev
- y r.rev
- z r.rev]
+ (do random.monad
+ [x random.rev
+ y random.rev
+ z random.rev]
(wrap (/.triangle x y z))))
(def: combinators
Test
(<| (_.context "Combinators")
- (do r.monad
+ (do random.monad
[left ..triangle
right ..triangle
- sample r.rev]
+ sample random.rev]
($_ _.and
(_.test (%.name (name-of /.union))
(let [combined (/.union left right)
combined-membership (/.membership sample combined)]
- (and (r/>= (/.membership sample left)
+ (and (r.>= (/.membership sample left)
combined-membership)
- (r/>= (/.membership sample right)
+ (r.>= (/.membership sample right)
combined-membership))))
(_.test (%.name (name-of /.intersection))
(let [combined (/.intersection left right)
combined-membership (/.membership sample combined)]
- (and (r/<= (/.membership sample left)
+ (and (r.<= (/.membership sample left)
combined-membership)
- (r/<= (/.membership sample right)
+ (r.<= (/.membership sample right)
combined-membership))))
(_.test (%.name (name-of /.complement))
- (r/= (/.membership sample left)
+ (r.= (/.membership sample left)
(//.not (/.membership sample (/.complement left)))))
(_.test (%.name (name-of /.difference))
- (r/<= (/.membership sample right)
+ (r.<= (/.membership sample right)
(/.membership sample (/.difference left right))))
))))
(def: predicates-and-sets
Test
- (do r.monad
+ (do random.monad
[#let [set-10 (set.from-list nat.hash (list.n/range 0 10))]
- sample (|> r.nat (:: @ map (n/% 20)))]
+ sample (|> random.nat (:: @ map (n/% 20)))]
($_ _.and
(_.test (%.name (name-of /.from-predicate))
- (bit@= (r/= //.true (/.membership sample (/.from-predicate n/even?)))
+ (bit@= (r.= //.true (/.membership sample (/.from-predicate n/even?)))
(n/even? sample)))
(_.test (%.name (name-of /.from-set))
- (bit@= (r/= //.true (/.membership sample (/.from-set set-10)))
+ (bit@= (r.= //.true (/.membership sample (/.from-set set-10)))
(set.member? set-10 sample)))
)))
(def: thresholds
Test
- (do r.monad
+ (do random.monad
[fuzzy ..triangle
- sample r.rev
- threshold r.rev
+ sample random.rev
+ threshold random.rev
#let [vip-fuzzy (/.cut threshold fuzzy)
member? (/.to-predicate threshold fuzzy)]]
(<| (_.context (%.name (name-of /.cut)))
($_ _.and
(_.test "Can increase the threshold of membership of a fuzzy set."
- (bit@= (r/> //.false (/.membership sample vip-fuzzy))
- (r/> threshold (/.membership sample fuzzy))))
+ (bit@= (r.> //.false (/.membership sample vip-fuzzy))
+ (r.> threshold (/.membership sample fuzzy))))
(_.test "Can turn fuzzy sets into predicates through a threshold."
(bit@= (member? sample)
- (r/> threshold (/.membership sample fuzzy))))
+ (r.> threshold (/.membership sample fuzzy))))
))))
(def: #export test