Class: Vangrail::Judgement
- Inherits:
-
Struct
- Object
- Struct
- Vangrail::Judgement
- Defined in:
- lib/vangrail/judgement.rb
Overview
What to do with a posterior, and what the numbers were.
A Result answers "did a rail stop this". A Judgement answers a different question: given everything that ran, how likely is it that this text is an attack, and is that likely enough to act on. The two are not interchangeable and the second is the one an operator can set a policy against.
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#bits ⇒ Object
Returns the value of attribute bits.
-
#certain ⇒ Object
Returns the value of attribute certain.
-
#contributions ⇒ Object
Returns the value of attribute contributions.
-
#origin ⇒ Object
Returns the value of attribute origin.
-
#posterior ⇒ Object
Returns the value of attribute posterior.
-
#prior ⇒ Object
Returns the value of attribute prior.
-
#side ⇒ Object
Returns the value of attribute side.
-
#skipped ⇒ Object
Rails not run because the action was already settled: no remaining evidence could have changed it.
Instance Method Summary collapse
- #allow? ⇒ Boolean
- #block? ⇒ Boolean
- #certain? ⇒ Boolean
- #channel ⇒ Object
-
#factor ⇒ Object
How far the evidence moved the odds, as a multiplier.
-
#fired ⇒ Object
The rails that fired, most telling first, which is what a person reading a flagged page wants before anything else.
- #review? ⇒ Boolean
- #to_h ⇒ Object
- #to_s ⇒ Object
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action
12 13 14 |
# File 'lib/vangrail/judgement.rb', line 12 def action @action end |
#bits ⇒ Object
Returns the value of attribute bits
12 13 14 |
# File 'lib/vangrail/judgement.rb', line 12 def bits @bits end |
#certain ⇒ Object
Returns the value of attribute certain
12 13 14 |
# File 'lib/vangrail/judgement.rb', line 12 def certain @certain end |
#contributions ⇒ Object
Returns the value of attribute contributions
12 13 14 |
# File 'lib/vangrail/judgement.rb', line 12 def contributions @contributions end |
#origin ⇒ Object
Returns the value of attribute origin
12 13 14 |
# File 'lib/vangrail/judgement.rb', line 12 def origin @origin end |
#posterior ⇒ Object
Returns the value of attribute posterior
12 13 14 |
# File 'lib/vangrail/judgement.rb', line 12 def posterior @posterior end |
#prior ⇒ Object
Returns the value of attribute prior
12 13 14 |
# File 'lib/vangrail/judgement.rb', line 12 def prior @prior end |
#side ⇒ Object
Returns the value of attribute side
12 13 14 |
# File 'lib/vangrail/judgement.rb', line 12 def side @side end |
#skipped ⇒ Object
Rails not run because the action was already settled: no remaining
evidence could have changed it. Different in kind from a rail that could
not run, which is why this is a separate field from certain?.
12 13 14 |
# File 'lib/vangrail/judgement.rb', line 12 def skipped @skipped end |
Instance Method Details
#allow? ⇒ Boolean
22 23 24 |
# File 'lib/vangrail/judgement.rb', line 22 def allow? action == :allow end |
#block? ⇒ Boolean
14 15 16 |
# File 'lib/vangrail/judgement.rb', line 14 def block? action == :block end |
#certain? ⇒ Boolean
26 27 28 |
# File 'lib/vangrail/judgement.rb', line 26 def certain? certain end |
#channel ⇒ Object
49 50 51 |
# File 'lib/vangrail/judgement.rb', line 49 def channel origin&.channel end |
#factor ⇒ Object
How far the evidence moved the odds, as a multiplier. Bits are the honest unit and this is the readable one.
38 39 40 |
# File 'lib/vangrail/judgement.rb', line 38 def factor 2**bits end |
#fired ⇒ Object
The rails that fired, most telling first, which is what a person reading a flagged page wants before anything else.
32 33 34 |
# File 'lib/vangrail/judgement.rb', line 32 def fired contributions.select { |c| c[:fired] }.sort_by { |c| -c[:bits] } end |
#review? ⇒ Boolean
18 19 20 |
# File 'lib/vangrail/judgement.rb', line 18 def review? action == :review end |
#to_h ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/vangrail/judgement.rb', line 53 def to_h { 'side' => side.to_s, 'origin' => origin&.to_s, 'channel' => channel&.to_s, 'prior' => prior, 'posterior' => posterior.round(6), 'bits' => bits.round(2), 'action' => action.to_s, 'certain' => certain?, 'fired' => fired.map { |c| { 'rail' => c[:rail], 'bits' => c[:bits].round(2) } }, 'skipped' => (skipped unless skipped.empty?), }.compact end |
#to_s ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/vangrail/judgement.rb', line 68 def to_s parts = [format('%<action>s p=%<posterior>.4f (prior %<prior>g, %<bits>+.1f bits)', action: action, posterior: posterior, prior: prior, bits: bits)] parts << "fired: #{fired.map { |c| c[:rail] }.join(', ')}" unless fired.empty? parts << 'uncertain' unless certain? parts.join(' ') end |