fuzzy-logic 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +13 -2
- data/lib/fuzzy-logic.rb +1 -1
- data/lib/fuzzy-logic/collection.rb +4 -0
- data/lib/fuzzy-logic/set.rb +12 -0
- data/spec/fuzzy-logic/collection_spec.rb +5 -0
- data/spec/fuzzy-logic/set_spec.rb +28 -0
- metadata +6 -6
data/README.md
CHANGED
@@ -65,7 +65,14 @@ The return is a normal Fuzzy-Set
|
|
65
65
|
# combinations
|
66
66
|
triangle_and_trapez = FuzzyLogic::Generate.and(triangle, trapez)
|
67
67
|
triangle_or_trapez = FuzzyLogic::Generate.or( triangle, trapez)
|
68
|
-
not_in_trapez = FuzzyLogic::Generate.not( trapez )
|
68
|
+
not_in_trapez = FuzzyLogic::Generate.not( trapez ) # not is just like this: Set.new { |n| 1 - trapez.get(n) }
|
69
|
+
|
70
|
+
for combinations there are also helpers
|
71
|
+
|
72
|
+
# shortcut of combinations
|
73
|
+
triangle_and_trapez = triangle.and trapez
|
74
|
+
triangle_or_trapez = triangle.or trapez
|
75
|
+
not_in_trapez = trapez.not
|
69
76
|
|
70
77
|
### Use Fuzzy-Collection
|
71
78
|
|
@@ -83,10 +90,14 @@ The return is a normal Fuzzy-Set
|
|
83
90
|
|
84
91
|
temp[:hot] = FuzzyLogic::Generate.trapezoid(25, 35, 100, 101)
|
85
92
|
temp[:cold] = FuzzyLogic::Generate.trapezoid(-101, -100, 5, 15)
|
93
|
+
|
86
94
|
temp[:cool_to_warm] = FuzzyLogic::Generate.and( FuzzyLogic::Generate.not(temp[:hot]), FuzzyLogic::Generate.not(temp[:cold]))
|
95
|
+
|
96
|
+
# or the short version
|
97
|
+
temp[:cool_2_warm] = temp[:hot].not.and temp[:cold].not
|
87
98
|
|
88
99
|
temp.get(20)
|
89
|
-
# => { :cool_to_warm => 1.0 }
|
100
|
+
# => { :cool_to_warm => 1.0, :cool_2_warm => 1.0 }
|
90
101
|
|
91
102
|
## Contributing
|
92
103
|
|
data/lib/fuzzy-logic.rb
CHANGED
@@ -20,6 +20,10 @@ module FuzzyLogic
|
|
20
20
|
@sets[fuzzysetname.to_sym] = fuzzyset
|
21
21
|
end
|
22
22
|
|
23
|
+
def [](fuzzysetname)
|
24
|
+
@sets[fuzzysetname.to_sym]
|
25
|
+
end
|
26
|
+
|
23
27
|
def get(n, all=false)
|
24
28
|
raise TypeError, "Test of Fuzzy-Collection is not valid" unless [true, false].include? @test.call(n)
|
25
29
|
raise ArgumentError, "Argument is not valid" unless @test.call(n)
|
data/lib/fuzzy-logic/set.rb
CHANGED
@@ -40,5 +40,17 @@ module FuzzyLogic
|
|
40
40
|
|
41
41
|
return out
|
42
42
|
end
|
43
|
+
|
44
|
+
def and(other)
|
45
|
+
FuzzyLogic::Generate.and(self, other)
|
46
|
+
end
|
47
|
+
|
48
|
+
def or(other)
|
49
|
+
FuzzyLogic::Generate.or(self, other)
|
50
|
+
end
|
51
|
+
|
52
|
+
def not
|
53
|
+
FuzzyLogic::Generate.not(self)
|
54
|
+
end
|
43
55
|
end
|
44
56
|
end
|
@@ -43,6 +43,11 @@ describe FuzzyLogic::Collection do
|
|
43
43
|
@collection.get(25).wont_be_empty
|
44
44
|
@collection.get(0, true).wont_be_empty
|
45
45
|
end
|
46
|
+
|
47
|
+
it "should return a fuzzy-set on hash-indexing or nil if its not presence" do
|
48
|
+
@collection[:test].must_be :is_a?, FuzzyLogic::Set
|
49
|
+
@collection[:i_am_an_invalid_key].must_be_nil
|
50
|
+
end
|
46
51
|
|
47
52
|
it "should be empty on 0" do
|
48
53
|
@collection.get(0).must_be_empty
|
@@ -12,6 +12,10 @@ describe FuzzyLogic::Set do
|
|
12
12
|
o
|
13
13
|
}
|
14
14
|
|
15
|
+
@another_valid_set = FuzzyLogic::Set.new(1) { |n|
|
16
|
+
n > 10 ? 0.0 : 1.0
|
17
|
+
}
|
18
|
+
|
15
19
|
@invalid_set = FuzzyLogic::Set.new(1) { |n|
|
16
20
|
"i am invalid."
|
17
21
|
}
|
@@ -135,4 +139,28 @@ describe FuzzyLogic::Set do
|
|
135
139
|
@valid_set.core(29, 0.5).must_equal false
|
136
140
|
end
|
137
141
|
end
|
142
|
+
|
143
|
+
describe "add_helpers to every set" do
|
144
|
+
it "should have a helper for and generator" do
|
145
|
+
(0..40).to_a.each { |i|
|
146
|
+
@valid_set.and(@another_valid_set).get(i).must_equal FuzzyLogic::Generate.and(@valid_set, @another_valid_set).get(i)
|
147
|
+
}
|
148
|
+
end
|
149
|
+
it "should have a helper for or generator" do
|
150
|
+
(0..40).to_a.each { |i|
|
151
|
+
@valid_set.or(@another_valid_set).get(i).must_equal FuzzyLogic::Generate.or(@valid_set, @another_valid_set).get(i)
|
152
|
+
}
|
153
|
+
end
|
154
|
+
it "should have a helper for not generator" do
|
155
|
+
(0..40).to_a.each { |i|
|
156
|
+
@valid_set.not.get(i).must_equal FuzzyLogic::Generate.not(@valid_set).get(i)
|
157
|
+
}
|
158
|
+
end
|
159
|
+
it "can combined together" do
|
160
|
+
test_set = FuzzyLogic::Generate.and(FuzzyLogic::Generate.not(@valid_set), FuzzyLogic::Generate.not(@another_valid_set))
|
161
|
+
(0..40).to_a.each { |i|
|
162
|
+
@valid_set.not.and(@another_valid_set.not).get(i).must_equal test_set.get(i)
|
163
|
+
}
|
164
|
+
end
|
165
|
+
end
|
138
166
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fuzzy-logic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: guard-minitest
|
16
|
-
requirement: &
|
16
|
+
requirement: &73273200 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *73273200
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rb-inotify
|
27
|
-
requirement: &
|
27
|
+
requirement: &73272940 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: 0.8.8
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *73272940
|
36
36
|
description: fuzzy-logic and fuzzy-rules are really handy for some problems.
|
37
37
|
email:
|
38
38
|
- ae@writedown.eu
|