Class: Vangrail::JointRiskModel
- Inherits:
-
Object
- Object
- Vangrail::JointRiskModel
- Includes:
- JointRiskMixtureInference, JointRiskOod
- Defined in:
- lib/vangrail/joint_risk.rb
Overview
Standard-library inference for a compact joint posterior approximation.
Defined Under Namespace
Classes: Abstention
Constant Summary collapse
- CONTEXT_FIELDS =
{ side: 'sides', origin: 'origins', language: 'languages', domain: 'domains', }.freeze
- SYSTEM_CLOCK =
-> { Time.now.utc }
Instance Attribute Summary collapse
-
#artifact ⇒ Object
readonly
Returns the value of attribute artifact.
-
#clock ⇒ Object
readonly
Returns the value of attribute clock.
Instance Method Summary collapse
- #estimate(results, side:, origin:, language:, domain:, prior: nil, scenario: nil, confidence: 0.95) ⇒ Object
-
#initialize(artifact, clock: SYSTEM_CLOCK) ⇒ JointRiskModel
constructor
A new instance of JointRiskModel.
Constructor Details
#initialize(artifact, clock: SYSTEM_CLOCK) ⇒ JointRiskModel
Returns a new instance of JointRiskModel.
100 101 102 103 104 105 106 |
# File 'lib/vangrail/joint_risk.rb', line 100 def initialize(artifact, clock: SYSTEM_CLOCK) raise ArgumentError, 'artifact must be a JointRiskArtifact' unless artifact.is_a?(JointRiskArtifact) raise ArgumentError, 'clock must respond to call' unless clock.respond_to?(:call) @artifact = artifact @clock = clock end |
Instance Attribute Details
#artifact ⇒ Object (readonly)
Returns the value of attribute artifact.
98 99 100 |
# File 'lib/vangrail/joint_risk.rb', line 98 def artifact @artifact end |
#clock ⇒ Object (readonly)
Returns the value of attribute clock.
98 99 100 |
# File 'lib/vangrail/joint_risk.rb', line 98 def clock @clock end |
Instance Method Details
#estimate(results, side:, origin:, language:, domain:, prior: nil, scenario: nil, confidence: 0.95) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/vangrail/joint_risk.rb', line 108 def estimate(results, side:, origin:, language:, domain:, prior: nil, scenario: nil, confidence: 0.95) prior, scenario = resolve_scenario(prior, scenario) validate_probability!(prior, 'prior') validate_probability!(confidence, 'confidence') context = normalized_context(side: side, origin: origin, language: language, domain: domain) validate_context!(context) validate_calibration_age! values = inference(results, side, context, prior, scenario, confidence) RiskEstimate.new(**artifact_identity, status: :ok, **values) rescue Abstention => e RiskEstimate.new( **artifact_identity, status: :abstained, reason: e., context: defined?(context) ? context : {}, ) end |