Class: Malge::ErrorFittedFunction
- Inherits:
-
Object
- Object
- Malge::ErrorFittedFunction
- Defined in:
- lib/malge/errorfittedfunction.rb
Overview
Defined Under Namespace
Classes: AExpBX, AExpBX32, AXInv, AXInv2, AXInv3, AXInv32, NotImplementedError, SizeMismatchError, TypeError, UnableCalculationError
Instance Attribute Summary collapse
-
#coefficients ⇒ Object
readonly
Returns the value of attribute coefficients.
-
#diff_abs_pairs ⇒ Object
readonly
Returns the value of attribute diff_abs_pairs.
-
#raw_pairs ⇒ Object
readonly
Returns the value of attribute raw_pairs.
Instance Method Summary collapse
-
#equation ⇒ Object
Return string which is easily readable for people to know the function.
-
#expected_error(x) ⇒ Object
Return expected error at x, condition variable, on the fitted function.
- #initialize(data_pairs) ⇒ ErrorFittedFunction constructor
-
#most_strict_pair ⇒ Object
Return the value of y at which the most precise data is expected to be obtained.
-
#variance ⇒ Object
Return variance of distribution between each pair of expected error and y, actual data point.
-
#x(y) ⇒ Object
Return value of ‘x’, assumed condition value, correspond to extpected value of ‘y’.
Constructor Details
#initialize(data_pairs) ⇒ ErrorFittedFunction
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/malge/errorfittedfunction.rb', line 19 def initialize(data_pairs) raise TypeError unless data_pairs.class == Array data_pairs.each do |pair| raise TypeError unless pair.class == Array raise SizeMismatchError unless pair.size == 2 end @raw_pairs = data_pairs @diff_abs_pairs = data_pairs.map { |pair| [pair[0], (pair[1] - most_strict_pair[1]).abs] } fit @coefficients.each do |coef| raise UnableCalculationError unless coef.finite? end end |
Instance Attribute Details
#coefficients ⇒ Object (readonly)
Returns the value of attribute coefficients.
10 11 12 |
# File 'lib/malge/errorfittedfunction.rb', line 10 def coefficients @coefficients end |
#diff_abs_pairs ⇒ Object (readonly)
Returns the value of attribute diff_abs_pairs.
10 11 12 |
# File 'lib/malge/errorfittedfunction.rb', line 10 def diff_abs_pairs @diff_abs_pairs end |
#raw_pairs ⇒ Object (readonly)
Returns the value of attribute raw_pairs.
10 11 12 |
# File 'lib/malge/errorfittedfunction.rb', line 10 def raw_pairs @raw_pairs end |
Instance Method Details
#equation ⇒ Object
Return string which is easily readable for people to know the function.
37 38 39 |
# File 'lib/malge/errorfittedfunction.rb', line 37 def equation raise NotImplementedError, "Define #{__method__}() in the inherited class." end |
#expected_error(x) ⇒ Object
Return expected error at x, condition variable, on the fitted function. Note that this method does not return the error between actual and true value.
43 44 45 |
# File 'lib/malge/errorfittedfunction.rb', line 43 def expected_error(x) raise NotImplementedError, "Define #{__method__}() in the inherited class." end |
#most_strict_pair ⇒ Object
Return the value of y at which the most precise data is expected to be obtained.
66 67 68 69 70 71 72 |
# File 'lib/malge/errorfittedfunction.rb', line 66 def most_strict_pair raise NotImplementedError, "Define #{__method__}() in the inherited class." #In the most case, it would be sufficient to select belows. @raw_pairs.max_by{ |pair| pair[0] } @raw_pairs.mix_by{ |pair| pair[0] } end |
#variance ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/malge/errorfittedfunction.rb', line 52 def variance sum = 0.0 @diff_abs_pairs.each do |pair| sum += (pair[1] - expected_error(pair[0]) )**2 end sum end |
#x(y) ⇒ Object
Return value of ‘x’, assumed condition value, correspond to extpected value of ‘y’.
61 62 63 |
# File 'lib/malge/errorfittedfunction.rb', line 61 def x(y) raise NotImplementedError, "Define #{__method__}() in the inherited class." end |