class Musicality::Function::Sigmoid

Constants

SIGM_DOMAIN

def self.inv_sigm y

-Math::log((1-y)/y.to_f)

end

SIGM_RANGE
SIGM_SPAN

Attributes

dy[R]
y0[R]

Public Class Methods

find_y0(domain, pt, y1) click to toggle source

Given a domain, an xy-point in that domain, and the y-value at the end of the domain, find the y-value at the start of the domain, assuming the the function is sigmoid.

# File lib/musicality/notation/util/function.rb, line 109
def self.find_y0 domain, pt, y1
  x,y = pt
  x_ = Function.transform_domains(domain, SIGM_DOMAIN, x)
  y_ = (sigm(x_) - SIGM_RANGE.first) / SIGM_SPAN
  return Function::Linear.new([y_,y],[1,y1]).at(0)
end
new(p0, p1) click to toggle source
Calls superclass method Musicality::Function::new
# File lib/musicality/notation/util/function.rb, line 87
def initialize p0, p1
  @y0, y1 = p0[1], p1[1]
  @dy = y1 - @y0
  @external_domain = p0[0]..p1[0]

  super() do |x|
    x_ = Function.transform_domains(@external_domain, SIGM_DOMAIN, x)
    y_ = (Sigmoid.sigm(x_) - SIGM_RANGE.first) / SIGM_SPAN
    @y0 + y_ * @dy
  end
end
sigm(x) click to toggle source
# File lib/musicality/notation/util/function.rb, line 74
def self.sigm x
  1.0 / (1 + Math::exp(-x))
end

Public Instance Methods

==(other) click to toggle source
Calls superclass method Musicality::Function#==
# File lib/musicality/notation/util/function.rb, line 116
def ==(other)
  super(other) && @y0 == other.y0 && @dy == other.dy
end