Class: Vangrail::RiskScenario
- Inherits:
-
Object
- Object
- Vangrail::RiskScenario
- Defined in:
- lib/vangrail/risk_scenario.rb
Overview
Deployment assumptions changed only by externally adjudicated outcomes.
Instance Attribute Summary collapse
-
#prevalence ⇒ Object
readonly
Returns the value of attribute prevalence.
-
#threats ⇒ Object
readonly
Returns the value of attribute threats.
Instance Method Summary collapse
- #adjudicate(label:, family: nil) ⇒ Object
-
#initialize(prevalence:, threats:) ⇒ RiskScenario
constructor
A new instance of RiskScenario.
- #prior ⇒ Object
- #threat_mixture ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(prevalence:, threats:) ⇒ RiskScenario
Returns a new instance of RiskScenario.
121 122 123 124 125 126 127 128 129 |
# File 'lib/vangrail/risk_scenario.rb', line 121 def initialize(prevalence:, threats:) unless prevalence.is_a?(BetaBinomialPrior) && threats.is_a?(DirichletThreatPrior) raise ArgumentError, 'scenario needs beta-binomial prevalence and Dirichlet threats' end @prevalence = prevalence @threats = threats freeze end |
Instance Attribute Details
#prevalence ⇒ Object (readonly)
Returns the value of attribute prevalence.
119 120 121 |
# File 'lib/vangrail/risk_scenario.rb', line 119 def prevalence @prevalence end |
#threats ⇒ Object (readonly)
Returns the value of attribute threats.
119 120 121 |
# File 'lib/vangrail/risk_scenario.rb', line 119 def threats @threats end |
Instance Method Details
#adjudicate(label:, family: nil) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/vangrail/risk_scenario.rb', line 139 def adjudicate(label:, family: nil) case label.to_sym when :attack raise ArgumentError, 'an adjudicated attack needs a threat family' if family.nil? self.class.new(prevalence: prevalence.adjudicate(:attack), threats: threats.adjudicate(family)) when :benign raise ArgumentError, 'a benign adjudication cannot name a threat family' unless family.nil? self.class.new(prevalence: prevalence.adjudicate(:benign), threats: threats) else raise ArgumentError, "unknown adjudicated label #{label.inspect}" end end |
#prior ⇒ Object
131 132 133 |
# File 'lib/vangrail/risk_scenario.rb', line 131 def prior prevalence.mean end |
#threat_mixture ⇒ Object
135 136 137 |
# File 'lib/vangrail/risk_scenario.rb', line 135 def threat_mixture threats.mean end |
#to_h ⇒ Object
154 155 156 |
# File 'lib/vangrail/risk_scenario.rb', line 154 def to_h { 'prevalence' => prevalence.to_h, 'threats' => threats.to_h }.freeze end |