Class: StochasticProcess::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/stochastic_process/base.rb

Direct Known Subclasses

BrownianMotion

Constant Summary collapse

DEFAULT_START_TIME =
0.0
DEFAULT_END_TIME =
100
DEFAULT_EVALUATIONS =
1000

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#evaluationsObject

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_incrementObject



21
22
23
# File 'lib/stochastic_process/base.rb', line 21

def default_path_increment
  return 0
end

#graphObject



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_lengthObject



25
26
27
# File 'lib/stochastic_process/base.rb', line 25

def interval_length
  (@end_time - @start_time).abs.to_f
end

#meshObject



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