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
-
#silence ⇒ Object
The rails that said nothing, as one entry rather than a list of them.
- #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 |
#silence ⇒ Object
The rails that said nothing, as one entry rather than a list of them.
Their bits are what pushes a clean page below its prior, so a payload carrying only the rails that fired shows a posterior under the prior with nothing to account for it: the numbers on the page do not add up to the decision the page is reporting. One entry keeps them adding up without listing thirty rails that had nothing to say.
60 61 62 63 64 65 |
# File 'lib/vangrail/judgement.rb', line 60 def silence quiet = contributions.reject { |c| c[:fired] } return nil if quiet.empty? { 'rails' => quiet.size, 'bits' => quiet.sum { |c| c[:bits] }.round(2) } end |
#to_h ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/vangrail/judgement.rb', line 67 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) } }, 'silent' => silence, 'skipped' => (skipped unless skipped.empty?), }.compact end |
#to_s ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/vangrail/judgement.rb', line 83 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 |