Module: Bishop
- Defined in:
- lib/bishop.rb
Defined Under Namespace
Classes: Bayes, BayesData, Tokenizer
Class Method Summary
collapse
Class Method Details
.chi2p(chi, df) ⇒ Object
307
308
309
310
311
312
313
314
315
|
# File 'lib/bishop.rb', line 307
def self.chi2p( chi, df )
m = chi / 2
sum = term = Math.exp( -m )
(1 .. df/2).each do |i|
term *= m/i
sum += term
end
[1.0, sum].min
end
|
.robinson(probs, ignore) ⇒ Object
281
282
283
284
285
286
287
|
# File 'lib/bishop.rb', line 281
def self.robinson( probs, ignore )
nth = 1.0/probs.length
what_is_p = 1.0 - probs.map { |p| 1.0 - p[1] }.inject( 1.0 ) { |s,v| s * v } ** nth
what_is_q = 1.0 - probs.map { |p| p[1] }.inject { |s,v| s * v } ** nth
what_is_s = ( what_is_p - what_is_q ) / ( what_is_p + what_is_q )
( 1 + what_is_s ) / 2
end
|
.robinson_fisher(probs, ignore) ⇒ Object
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
|
# File 'lib/bishop.rb', line 289
def self.robinson_fisher( probs, ignore )
n = probs.length
begin
h = chi2p( -2.0 * Math.log( probs.map { |p| p[1] }.inject( 1.0 ) { |s,v| s*v } ), 2*n )
rescue
h = 0.0
end
begin
s = chi2p( -2.0 * Math.log( probs.map { |p| 1.0 - p[1] }.inject( 1.0 ) { |s,v| s*v } ), 2*n )
rescue
s = 0.0
end
( 1 + h - s ) / 2
end
|