Class: FuzzyAssociativeMemory::Triangle
- Defined in:
- lib/fuzzy_associative_memory/triangle.rb
Instance Attribute Summary collapse
-
#center ⇒ Object
readonly
Returns the value of attribute center.
-
#height ⇒ Object
Returns the value of attribute height.
-
#left ⇒ Object
readonly
Returns the value of attribute left.
-
#right ⇒ Object
readonly
Returns the value of attribute right.
Instance Method Summary collapse
- #centroid_x ⇒ Object
-
#initialize(left, center, right, height = 1.0) ⇒ Triangle
constructor
A new instance of Triangle.
- #larsen(ratio) ⇒ Object
- #mamdani(clip_height) ⇒ Object
- #mu(value) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(left, center, right, height = 1.0) ⇒ Triangle
Returns a new instance of Triangle.
14 15 16 17 18 19 20 21 |
# File 'lib/fuzzy_associative_memory/triangle.rb', line 14 def initialize(left, center, right, height=1.0) # TODO validations @center = center.to_f @left = left.to_f @right = right.to_f @height = height.to_f end |
Instance Attribute Details
#center ⇒ Object (readonly)
Returns the value of attribute center.
12 13 14 |
# File 'lib/fuzzy_associative_memory/triangle.rb', line 12 def center @center end |
#height ⇒ Object
Returns the value of attribute height.
12 13 14 |
# File 'lib/fuzzy_associative_memory/triangle.rb', line 12 def height @height end |
#left ⇒ Object (readonly)
Returns the value of attribute left.
12 13 14 |
# File 'lib/fuzzy_associative_memory/triangle.rb', line 12 def left @left end |
#right ⇒ Object (readonly)
Returns the value of attribute right.
12 13 14 |
# File 'lib/fuzzy_associative_memory/triangle.rb', line 12 def right @right end |
Instance Method Details
#centroid_x ⇒ Object
32 33 34 |
# File 'lib/fuzzy_associative_memory/triangle.rb', line 32 def centroid_x (@left + @right + @center) / 3.0 end |
#larsen(ratio) ⇒ Object
40 41 42 43 44 |
# File 'lib/fuzzy_associative_memory/triangle.rb', line 40 def larsen(ratio) t = self.dup t.height=(t.height * ratio) t end |
#mamdani(clip_height) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/fuzzy_associative_memory/triangle.rb', line 46 def mamdani(clip_height) left = @left top_left = @left + (clip_height * (@center - @left)) top_right = @right - (clip_height * (@right - @center)) right = @right FuzzyAssociativeMemory::Trapezoid.new(left, top_left, top_right, right, clip_height) end |
#mu(value) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/fuzzy_associative_memory/triangle.rb', line 23 def mu(value) raise ArgumentError, "value passed to Triangle::mu() cannot be nil" if value.nil? if value < @left || value > @right 0.0 else 1 - ((@center-value).abs / ((@right - @left) / 2.0 )) end end |
#to_s ⇒ Object
55 56 57 |
# File 'lib/fuzzy_associative_memory/triangle.rb', line 55 def to_s "Triangle {#{@left}/#{@center}/#{@right}, height #{@height}}" end |