Class: Fathom::MonteCarloSet
- Inherits:
-
Object
- Object
- Fathom::MonteCarloSet
- Defined in:
- lib/fathom/monte_carlo_set.rb
Instance Attribute Summary collapse
-
#samples ⇒ Object
readonly
Returns the value of attribute samples.
-
#samples_taken ⇒ Object
readonly
Returns the value of attribute samples_taken.
-
#value_description ⇒ Object
readonly
Returns the value of attribute value_description.
Class Method Summary collapse
Instance Method Summary collapse
- #fields ⇒ Object
-
#initialize(value_description) ⇒ MonteCarloSet
constructor
A new instance of MonteCarloSet.
- #print_summary ⇒ Object
- #process(n = 10_000) ⇒ Object
- #reset! ⇒ Object
- #summary(field = nil) ⇒ Object
Constructor Details
#initialize(value_description) ⇒ MonteCarloSet
Returns a new instance of MonteCarloSet.
20 21 22 23 |
# File 'lib/fathom/monte_carlo_set.rb', line 20 def initialize(value_description) @value_description = value_description @samples = {} end |
Instance Attribute Details
#samples ⇒ Object (readonly)
Returns the value of attribute samples.
18 19 20 |
# File 'lib/fathom/monte_carlo_set.rb', line 18 def samples @samples end |
#samples_taken ⇒ Object (readonly)
Returns the value of attribute samples_taken.
18 19 20 |
# File 'lib/fathom/monte_carlo_set.rb', line 18 def samples_taken @samples_taken end |
#value_description ⇒ Object (readonly)
Returns the value of attribute value_description.
18 19 20 |
# File 'lib/fathom/monte_carlo_set.rb', line 18 def value_description @value_description end |
Class Method Details
.define_key(key) ⇒ Object
5 6 7 8 9 |
# File 'lib/fathom/monte_carlo_set.rb', line 5 def define_key(key) define_method(key.to_sym) do self.samples[key.to_sym] end end |
.define_summary_method(field) ⇒ Object
11 12 13 14 15 |
# File 'lib/fathom/monte_carlo_set.rb', line 11 def define_summary_method(field) define_method("#{field}_summary".to_sym) do self.summary(field.to_sym) end end |
Instance Method Details
#fields ⇒ Object
39 40 41 |
# File 'lib/fathom/monte_carlo_set.rb', line 39 def fields @samples.keys end |
#print_summary ⇒ Object
51 52 53 |
# File 'lib/fathom/monte_carlo_set.rb', line 51 def print_summary print_hash(self.summary) end |
#process(n = 10_000) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/fathom/monte_carlo_set.rb', line 25 def process(n=10_000) @samples_taken = n @samples_taken.times do result = value_description.process store(result) end assert_sample_vectors end |
#reset! ⇒ Object
34 35 36 37 |
# File 'lib/fathom/monte_carlo_set.rb', line 34 def reset! @samples = {} @keys_asserted = nil end |
#summary(field = nil) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/fathom/monte_carlo_set.rb', line 43 def summary(field=nil) return summarize_field(field) if field fields.inject({}) do |h, field| h[field] = summarize_field(field) h end end |