Class: StochasticProcess::Base
- Inherits:
-
Object
- Object
- StochasticProcess::Base
- Defined in:
- lib/stochastic_process/base.rb
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_START_TIME =
0.0
- DEFAULT_END_TIME =
100
- DEFAULT_EVALUATIONS =
1000
Instance Attribute Summary collapse
-
#evaluations ⇒ Object
Returns the value of attribute evaluations.
Instance Method Summary collapse
- #default_path_increment ⇒ Object
- #graph ⇒ Object
-
#initialize(initial_position: 0.0, start_time: DEFAULT_START_TIME, end_time: DEFAULT_END_TIME, evaluations: DEFAULT_EVALUATIONS, path_increment: method(:default_path_increment)) ⇒ Base
constructor
A new instance of Base.
- #interval_length ⇒ Object
- #mesh ⇒ Object
- #mesh=(m) ⇒ Object
Constructor Details
#initialize(initial_position: 0.0, start_time: DEFAULT_START_TIME, end_time: DEFAULT_END_TIME, evaluations: DEFAULT_EVALUATIONS, path_increment: method(:default_path_increment)) ⇒ Base
Returns a new instance of Base.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/stochastic_process/base.rb', line 9 def initialize(initial_position: 0.0, start_time: DEFAULT_START_TIME, end_time: DEFAULT_END_TIME, evaluations: DEFAULT_EVALUATIONS, path_increment: method(:default_path_increment)) @initial_position = initial_position @start_time = start_time @end_time = end_time @evaluations = evaluations @path_increment = path_increment end |
Instance Attribute Details
#evaluations ⇒ Object
Returns the value of attribute evaluations.
7 8 9 |
# File 'lib/stochastic_process/base.rb', line 7 def evaluations @evaluations end |
Instance Method Details
#default_path_increment ⇒ Object
21 22 23 |
# File 'lib/stochastic_process/base.rb', line 21 def default_path_increment return 0 end |
#graph ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/stochastic_process/base.rb', line 40 def graph a = [] m = mesh() a.push({x: @start_time, y: @initial_position}) @evaluations.times do |i| # iterates from 0 to @evaluations - 1 a.push({x: @start_time + (i + 1) * m, y: a[i][:y] + @path_increment.call}) end return a end |
#interval_length ⇒ Object
25 26 27 |
# File 'lib/stochastic_process/base.rb', line 25 def interval_length (@end_time - @start_time).abs.to_f end |
#mesh ⇒ Object
29 30 31 |
# File 'lib/stochastic_process/base.rb', line 29 def mesh interval_length / @evaluations end |
#mesh=(m) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/stochastic_process/base.rb', line 33 def mesh=(m) if m <= 0 raise("Only positive numbers allowed!") end @evaluations = interval_length / m.to_f end |