Class: Malge::ErrorFittedFunction::AExpBX

Inherits:
Malge::ErrorFittedFunction show all
Defined in:
lib/malge/errorfittedfunction/aexpbx.rb

Overview

Assumed y = a * exp(a *x)

NOTE: @coefficients might become negative value. Need discussion for dealing?

NOTE: Zero value for |y - y_last| is simply ignored due to impossible log evaluation.

Instance Attribute Summary

Attributes inherited from Malge::ErrorFittedFunction

#coefficients, #diff_abs_pairs, #raw_pairs

Instance Method Summary collapse

Methods inherited from Malge::ErrorFittedFunction

#initialize, #variance

Constructor Details

This class inherits a constructor from Malge::ErrorFittedFunction

Instance Method Details

#equationObject



24
25
26
# File 'lib/malge/errorfittedfunction/aexpbx.rb', line 24

def equation
  sprintf("f(x) = %f \* exp(%f \* x)", * @coefficients)
end

#expected_error(x) ⇒ Object



28
29
30
# File 'lib/malge/errorfittedfunction/aexpbx.rb', line 28

def expected_error(x)
  @coefficients[0] * Math::exp( @coefficients[1] * x)
end

#fitObject



13
14
15
16
17
18
19
20
21
22
# File 'lib/malge/errorfittedfunction/aexpbx.rb', line 13

def fit
  inv_pairs =  @diff_abs_pairs.map {|pair|
    x = pair[0]
    y = Math::log(pair[1])
    [x,y]
  }
  inv_pairs.delete_if {|pair| ! pair[1].finite?} 
  @coefficients = Malge::LeastSquare.least_square_1st_degree(inv_pairs)
  @coefficients[0] = Math::exp @coefficients[0]
end

#most_strict_pairObject



41
42
43
# File 'lib/malge/errorfittedfunction/aexpbx.rb', line 41

def most_strict_pair
  @raw_pairs.max_by{ |pair| pair[0] }
end

#x(y) ⇒ Object

y = a * exp(a *x) a * exp(a *x) = y exp(a *x) = y/a a *x = log( y/a) x = log( y/a)/a



37
38
39
# File 'lib/malge/errorfittedfunction/aexpbx.rb', line 37

def x(y)
  return Math::log( y / @coefficients[0])/@coefficients[1]
end