Class: FuzzyLogic::Set
- Inherits:
-
Object
- Object
- FuzzyLogic::Set
- Defined in:
- lib/fuzzy-logic/set.rb
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
Returns the value of attribute height.
Instance Method Summary collapse
- #and(other) ⇒ Object
- #core(value, alphacut = nil) ⇒ Object
- #get(value, alphacut = nil) ⇒ Object
-
#initialize(height = nil, &fuzzyproc) ⇒ Set
constructor
A new instance of Set.
- #not ⇒ Object
- #or(other) ⇒ Object
- #support(value, alphacut = nil) ⇒ Object
Constructor Details
#initialize(height = nil, &fuzzyproc) ⇒ Set
Returns a new instance of Set.
9 10 11 12 13 14 15 16 |
# File 'lib/fuzzy-logic/set.rb', line 9 def initialize(height=nil, &fuzzyproc) if height != nil then raise ArgumentError, "Initial Height should be numeric" unless height.is_a? Numeric raise ArgumentError, "Initial Height should be between 0 and 1" if height < 0 or height > 1 end @fuzzyproc = fuzzyproc @height = height end |
Instance Attribute Details
#height ⇒ Object (readonly)
Returns the value of attribute height.
7 8 9 |
# File 'lib/fuzzy-logic/set.rb', line 7 def height @height end |
Instance Method Details
#and(other) ⇒ Object
44 45 46 |
# File 'lib/fuzzy-logic/set.rb', line 44 def and(other) FuzzyLogic::Generate.and(self, other) end |
#core(value, alphacut = nil) ⇒ Object
22 23 24 |
# File 'lib/fuzzy-logic/set.rb', line 22 def core(value, alphacut=nil) get(value, alphacut) == 1 end |
#get(value, alphacut = nil) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/fuzzy-logic/set.rb', line 26 def get(value, alphacut=nil) raise ArgumentError, "Value of fuzzy-set should be Comparable" unless value.is_a? Comparable out = @fuzzyproc.call(value) raise TypeError, "Output of fuzzy-set should be Numeric" unless out.is_a? Numeric raise TypeError, "Output of fuzzy-set is out of range. Should be between 0 and 1" if out < 0 or out > 1 @height ||= out @height = out if out > @height if alphacut then raise ArgumentError, "Alphacut of fuzzy-set should be Comparable" unless alphacut.is_a? Numeric out = 0 if alphacut > out end return out end |
#not ⇒ Object
52 53 54 |
# File 'lib/fuzzy-logic/set.rb', line 52 def not FuzzyLogic::Generate.not(self) end |
#or(other) ⇒ Object
48 49 50 |
# File 'lib/fuzzy-logic/set.rb', line 48 def or(other) FuzzyLogic::Generate.or(self, other) end |
#support(value, alphacut = nil) ⇒ Object
18 19 20 |
# File 'lib/fuzzy-logic/set.rb', line 18 def support(value, alphacut=nil) get(value, alphacut) > 0 end |