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.
83 84 85 86 87 88 89 90 91 |
# File 'lib/cicada/fitting/p3d_fitter.rb', line 83 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.
95 96 97 |
# File 'lib/cicada/fitting/p3d_fitter.rb', line 95 def min_prob @min_prob end |
#r ⇒ Object
Returns the value of attribute r.
93 94 95 |
# File 'lib/cicada/fitting/p3d_fitter.rb', line 93 def r @r end |
#s ⇒ Object
Returns the value of attribute s.
95 96 97 |
# File 'lib/cicada/fitting/p3d_fitter.rb', line 95 def s @s end |
#should_fit_s ⇒ Object
Returns the value of attribute should_fit_s.
93 94 95 |
# File 'lib/cicada/fitting/p3d_fitter.rb', line 93 def should_fit_s @should_fit_s end |
#use_min_prob ⇒ Object
Returns the value of attribute use_min_prob.
93 94 95 |
# File 'lib/cicada/fitting/p3d_fitter.rb', line 93 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.
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/cicada/fitting/p3d_fitter.rb', line 150 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.
135 136 137 138 139 |
# File 'lib/cicada/fitting/p3d_fitter.rb', line 135 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 |