class FuzzyAssociativeMemory::Triangle

Attributes

center[R]
height[R]
left[R]
right[R]

Public Class Methods

new(left, center, right, height=1.0) click to toggle source
# 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

Public Instance Methods

centroid_x() click to toggle source
# File lib/fuzzy_associative_memory/triangle.rb, line 32
def centroid_x
  (@left + @right + @center) / 3.0
end
height=(new_height) click to toggle source
# File lib/fuzzy_associative_memory/triangle.rb, line 36
def height=(new_height)
  @height = new_height
end
larsen(ratio) click to toggle source
# 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) click to toggle source
# File lib/fuzzy_associative_memory/triangle.rb, line 46
def mamdani(clip_height)
  top_left  = @left + (clip_height * (@center - @left))
  top_right = @right - (clip_height * (@right - @center))

  FuzzyAssociativeMemory::Trapezoid.new(@left, top_left, top_right, @right, clip_height)
end
mu(value) click to toggle source
# 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() click to toggle source
# File lib/fuzzy_associative_memory/triangle.rb, line 53
def to_s
  "Triangle {#{@left}/#{@center}/#{@right}, height #{@height}}"
end