Class: Fathom::MCNode
Instance Attribute Summary collapse
-
#samples_taken ⇒ Object
readonly
Returns the value of attribute samples_taken.
-
#value_description ⇒ Object
Returns the value of attribute value_description.
Attributes inherited from Node
#description, #distribution, #name, #values
Instance Method Summary collapse
- #fields ⇒ Object
-
#initialize(opts = {}, &block) ⇒ MCNode
constructor
A new instance of MCNode.
- #process(n = 10_000) ⇒ Object
- #reset! ⇒ Object
Methods inherited from Node
#add_child, #add_parent, #children, #inspect, #name_sym, #parents, #register_child, #register_parent, #simple_inspect
Constructor Details
#initialize(opts = {}, &block) ⇒ MCNode
Returns a new instance of MCNode.
7 8 9 10 11 12 13 |
# File 'lib/fathom/node/mc_node.rb', line 7 def initialize(opts={}, &block) super(opts) @value_description = opts[:value_description] @value_description ||= block if block_given? raise ArgumentError, "Must provide a value_description from either a parameter or by passing in a block" unless @value_description end |
Instance Attribute Details
#samples_taken ⇒ Object (readonly)
Returns the value of attribute samples_taken.
4 5 6 |
# File 'lib/fathom/node/mc_node.rb', line 4 def samples_taken @samples_taken end |
#value_description ⇒ Object
Returns the value of attribute value_description.
5 6 7 |
# File 'lib/fathom/node/mc_node.rb', line 5 def value_description @value_description end |
Instance Method Details
#fields ⇒ Object
29 30 31 |
# File 'lib/fathom/node/mc_node.rb', line 29 def fields self.children.map {|c| c.name_sym}.compact end |
#process(n = 10_000) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/fathom/node/mc_node.rb', line 15 def process(n=10_000) @samples_taken, @samples = n, {} @samples_taken.times do result = value_description.call(self) store(result) end assert_nodes end |
#reset! ⇒ Object
24 25 26 27 |
# File 'lib/fathom/node/mc_node.rb', line 24 def reset! @samples_taken, @samples = nil, {} @samples_asserted = false end |