Class: Vangrail::RiskEstimate
- Inherits:
-
Object
- Object
- Vangrail::RiskEstimate
- Defined in:
- lib/vangrail/joint_risk.rb
Overview
Calibrated posterior and interval emitted by a JointRiskModel.
Instance Attribute Summary collapse
-
#artifact_id ⇒ Object
readonly
Returns the value of attribute artifact_id.
-
#calibration_id ⇒ Object
readonly
Returns the value of attribute calibration_id.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#cost ⇒ Object
readonly
Returns the value of attribute cost.
-
#features ⇒ Object
readonly
Returns the value of attribute features.
-
#interval ⇒ Object
readonly
Returns the value of attribute interval.
-
#posterior ⇒ Object
readonly
Returns the value of attribute posterior.
-
#posterior_method ⇒ Object
readonly
Returns the value of attribute posterior_method.
-
#reason ⇒ Object
readonly
Returns the value of attribute reason.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #abstained? ⇒ Boolean
- #certain?(policy) ⇒ Boolean
-
#initialize(artifact_id:, posterior_method:, calibration_id:, status:, posterior: nil, interval: nil, reason: nil, features: {}, cost: {}, context: {}) ⇒ RiskEstimate
constructor
A new instance of RiskEstimate.
-
#restriction(policy = Policy::DEFAULT) ⇒ Object
Converts empirical risk into a restriction consumed by ReferenceMonitor.
- #to_h ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(artifact_id:, posterior_method:, calibration_id:, status:, posterior: nil, interval: nil, reason: nil, features: {}, cost: {}, context: {}) ⇒ RiskEstimate
Returns a new instance of RiskEstimate.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/vangrail/joint_risk.rb', line 17 def initialize(artifact_id:, posterior_method:, calibration_id:, status:, posterior: nil, interval: nil, reason: nil, features: {}, cost: {}, context: {}) @artifact_id = artifact_id.to_s.freeze @posterior_method = posterior_method.to_s.freeze @calibration_id = calibration_id.to_s.freeze @status = status.to_sym @posterior = posterior @interval = interval&.dup&.freeze @reason = reason&.to_s&.freeze @features = features.dup.freeze @cost = cost.dup.freeze @context = context.dup.freeze freeze end |
Instance Attribute Details
#artifact_id ⇒ Object (readonly)
Returns the value of attribute artifact_id.
14 15 16 |
# File 'lib/vangrail/joint_risk.rb', line 14 def artifact_id @artifact_id end |
#calibration_id ⇒ Object (readonly)
Returns the value of attribute calibration_id.
14 15 16 |
# File 'lib/vangrail/joint_risk.rb', line 14 def calibration_id @calibration_id end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
14 15 16 |
# File 'lib/vangrail/joint_risk.rb', line 14 def context @context end |
#cost ⇒ Object (readonly)
Returns the value of attribute cost.
14 15 16 |
# File 'lib/vangrail/joint_risk.rb', line 14 def cost @cost end |
#features ⇒ Object (readonly)
Returns the value of attribute features.
14 15 16 |
# File 'lib/vangrail/joint_risk.rb', line 14 def features @features end |
#interval ⇒ Object (readonly)
Returns the value of attribute interval.
14 15 16 |
# File 'lib/vangrail/joint_risk.rb', line 14 def interval @interval end |
#posterior ⇒ Object (readonly)
Returns the value of attribute posterior.
14 15 16 |
# File 'lib/vangrail/joint_risk.rb', line 14 def posterior @posterior end |
#posterior_method ⇒ Object (readonly)
Returns the value of attribute posterior_method.
14 15 16 |
# File 'lib/vangrail/joint_risk.rb', line 14 def posterior_method @posterior_method end |
#reason ⇒ Object (readonly)
Returns the value of attribute reason.
14 15 16 |
# File 'lib/vangrail/joint_risk.rb', line 14 def reason @reason end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
14 15 16 |
# File 'lib/vangrail/joint_risk.rb', line 14 def status @status end |
Instance Method Details
#abstained? ⇒ Boolean
37 38 39 |
# File 'lib/vangrail/joint_risk.rb', line 37 def abstained? status == :abstained end |
#certain?(policy) ⇒ Boolean
41 42 43 44 45 |
# File 'lib/vangrail/joint_risk.rb', line 41 def certain?(policy) return false unless valid? && interval policy.action_for(interval.first) == policy.action_for(interval.last) end |
#restriction(policy = Policy::DEFAULT) ⇒ Object
Converts empirical risk into a restriction consumed by ReferenceMonitor. An allow result never creates authority; it only declines to remove an existing grant.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/vangrail/joint_risk.rb', line 50 def restriction(policy = Policy::DEFAULT) return Result.unchecked(rail: 'joint_risk', reason: reason, raw: to_h) if abstained? unless certain?(policy) return Result.unchecked( rail: 'joint_risk', reason: 'posterior interval crosses a policy boundary', raw: to_h, ) end action = policy.action_for(posterior) return Result.passed(rail: 'joint_risk', raw: to_h) if action == :allow Result.blocked(rail: 'joint_risk', reason: "risk policy requires #{action}", raw: to_h) end |
#to_h ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/vangrail/joint_risk.rb', line 66 def to_h { 'artifact_id' => artifact_id, 'posterior_method' => posterior_method, 'calibration_id' => calibration_id, 'status' => status.to_s, 'posterior' => posterior, 'interval' => interval, 'features' => features, 'cost' => cost, 'context' => context, 'reason' => reason, }.compact end |
#valid? ⇒ Boolean
33 34 35 |
# File 'lib/vangrail/joint_risk.rb', line 33 def valid? status == :ok end |