Class: Musicality::Function::Sigmoid
- Inherits:
-
Musicality::Function
- Object
- Musicality::Function
- Musicality::Function::Sigmoid
- Defined in:
- lib/musicality/notation/util/function.rb
Constant Summary collapse
- SIGM_DOMAIN =
def self.inv_sigm y
-Math::log((1-y)/y.to_f)
end
-5..5
- SIGM_RANGE =
Sigmoid.sigm(SIGM_DOMAIN.first)..Sigmoid.sigm(SIGM_DOMAIN.last)
- SIGM_SPAN =
SIGM_RANGE.last - SIGM_RANGE.first
Instance Attribute Summary collapse
-
#dy ⇒ Object
readonly
Returns the value of attribute dy.
-
#y0 ⇒ Object
readonly
Returns the value of attribute y0.
Attributes inherited from Musicality::Function
Class Method Summary collapse
-
.find_y0(domain, pt, y1) ⇒ Object
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.
- .sigm(x) ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(p0, p1) ⇒ Sigmoid
constructor
A new instance of Sigmoid.
Methods inherited from Musicality::Function
#at, #sample, transform_domains
Constructor Details
#initialize(p0, p1) ⇒ Sigmoid
Returns a new instance of Sigmoid.
87 88 89 90 91 92 93 94 95 96 97 |
# 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 |
Instance Attribute Details
#dy ⇒ Object (readonly)
Returns the value of attribute dy.
86 87 88 |
# File 'lib/musicality/notation/util/function.rb', line 86 def dy @dy end |
#y0 ⇒ Object (readonly)
Returns the value of attribute y0.
86 87 88 |
# File 'lib/musicality/notation/util/function.rb', line 86 def y0 @y0 end |
Class Method Details
.find_y0(domain, pt, y1) ⇒ Object
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.
109 110 111 112 113 114 |
# 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 |
.sigm(x) ⇒ Object
74 75 76 |
# File 'lib/musicality/notation/util/function.rb', line 74 def self.sigm x 1.0 / (1 + Math::exp(-x)) end |
Instance Method Details
#==(other) ⇒ Object
116 117 118 |
# File 'lib/musicality/notation/util/function.rb', line 116 def ==(other) super(other) && @y0 == other.y0 && @dy == other.dy end |