wasBayesSharp – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | using System; |
2 | using System.Collections.Generic; |
||
3 | using System.Linq; |
||
4 | |||
5 | namespace BayesSharp.Combiners |
||
6 | { |
||
7 | public class RobinsonCombiner : ICombiner |
||
8 | { |
||
9 | /// <summary> |
||
10 | /// Computes the probability of a message being spam (Robinson's method) |
||
11 | /// P = 1 - prod(1-p)^(1/n) |
||
12 | /// Q = 1 - prod(p)^(1/n) |
||
13 | /// S = (1 + (P-Q)/(P+Q)) / 2 |
||
14 | /// </summary> |
||
15 | /// <param name="numbers">List of numbers to be combined</param> |
||
16 | public double Combine(IEnumerable<double> numbers) |
||
17 | { |
||
18 | var probList = numbers.ToList(); |
||
19 | var nth = 1.0 / probList.Count(); |
||
20 | var p = 1.0 - Math.Pow(probList.Aggregate(1.0, (x, y) => x * (1 - y)), nth); |
||
21 | var q = 1.0 - Math.Pow(probList.Aggregate(1.0, (x, y) => x * y), nth); |
||
22 | var s = (p - q) / (p + q); |
||
23 | return (1 + s) / 2; |
||
24 | } |
||
25 | } |
||
26 | } |