Class: Cicada::P3DObjectiveFunction
- Inherits:
-
Object
- Object
- Cicada::P3DObjectiveFunction
- Defined in:
- lib/cicada/fitting/p3d_fitter.rb
Overview
An objective function that calculates the negative log likelihood of supplied data points being generated from a p3d distribution with specified parameters.
The data points should be an array of (positive) scalars set using the attribute r.
Instance Attribute Summary collapse
-
#min_prob ⇒ Object
Returns the value of attribute min_prob.
-
#r ⇒ Object
Returns the value of attribute r.
-
#s ⇒ Object
Returns the value of attribute s.
-
#should_fit_s ⇒ Object
Returns the value of attribute should_fit_s.
-
#use_min_prob ⇒ Object
Returns the value of attribute use_min_prob.
Instance Method Summary collapse
-
#evaluate(point) ⇒ Float
Evaluates the negative log-likelihood of the data given the parameters specified.
-
#initialize ⇒ P3DObjectiveFunction
constructor
Constructs an empty P3DObjectiveFunction.
-
#p3d(r, m, s) ⇒ Float
Calculates the probability density of the p3d distribution at a given point.
Constructor Details
#initialize ⇒ P3DObjectiveFunction
Constructs an empty P3DObjectiveFunction.
77 78 79 80 81 82 83 |
# File 'lib/cicada/fitting/p3d_fitter.rb', line 77 def initialize @r = nil @s = nil @min_prob = nil @use_min_prob = false @should_fit_s = true end |
Instance Attribute Details
#min_prob ⇒ Object
Returns the value of attribute min_prob.
86 87 88 |
# File 'lib/cicada/fitting/p3d_fitter.rb', line 86 def min_prob @min_prob end |
#r ⇒ Object
Returns the value of attribute r.
85 86 87 |
# File 'lib/cicada/fitting/p3d_fitter.rb', line 85 def r @r end |
#s ⇒ Object
Returns the value of attribute s.
86 87 88 |
# File 'lib/cicada/fitting/p3d_fitter.rb', line 86 def s @s end |
#should_fit_s ⇒ Object
Returns the value of attribute should_fit_s.
85 86 87 |
# File 'lib/cicada/fitting/p3d_fitter.rb', line 85 def should_fit_s @should_fit_s end |
#use_min_prob ⇒ Object
Returns the value of attribute use_min_prob.
85 86 87 |
# File 'lib/cicada/fitting/p3d_fitter.rb', line 85 def use_min_prob @use_min_prob end |
Instance Method Details
#evaluate(point) ⇒ Float
Evaluates the negative log-likelihood of the data given the parameters specified.
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/cicada/fitting/p3d_fitter.rb', line 137 def evaluate(point) point = point.toArray unless point.is_a? Array m = point[0] s = point[1] s = @s unless @should_fit_s return Float::MAX if (m < 0 or s < 0) r.reduce(0.0) do |sum, ri| temp_neg_log_p = -1.0*Math.log( p3d(ri, m, s)) if (@use_min_prob and temp_neg_log_p > @min_prob) then sum + @min_prob else sum + temp_neg_log_p end end end |
#p3d(r, m, s) ⇒ Float
Calculates the probability density of the p3d distribution at a given point.
124 125 126 |
# File 'lib/cicada/fitting/p3d_fitter.rb', line 124 def p3d(r, m, s) (Math.sqrt(2.0/Math::PI)*r/(2*m*s))*(Math.exp(-1 * (m-r)**2/(2*s**2)) - Math.exp( -1 * (m+r)**2/(2*s**2))) end |