Class: Parameters
- Inherits:
-
Object
- Object
- Parameters
- Defined in:
- lib/parameters.rb
Overview
object Coefficient
Instance Attribute Summary collapse
-
#a ⇒ Object
Returns the value of attribute a.
-
#b ⇒ Object
Returns the value of attribute b.
-
#coefficient ⇒ Object
Returns the value of attribute coefficient.
Instance Method Summary collapse
- #calculate_a(serie_a, serie_b) ⇒ Object
- #calculate_b(serie_a, serie_b) ⇒ Object
-
#calculate_coefficient(serie_a, serie_b) ⇒ Object
calculation of the slope between the 2 series sigma(xi - moy_x)(yi - moy y) / squared_root(sigma(xi - moy_x)^2) x squared_root(sigma(yi - moy_y)^2)).
-
#initialize(serie_a, serie_b) ⇒ Parameters
constructor
A new instance of Parameters.
-
#prod_variances(serie_a, serie_b) ⇒ Object
array of (xi - moy_x)(yi - moy_y) i periods i periods.
Constructor Details
#initialize(serie_a, serie_b) ⇒ Parameters
Returns a new instance of Parameters.
9 10 11 12 13 |
# File 'lib/parameters.rb', line 9 def initialize(serie_a, serie_b) @a = calculate_a(serie_a, serie_b) @b = calculate_b(serie_a, serie_b) @coefficient = calculate_coefficient(serie_a, serie_b) end |
Instance Attribute Details
#a ⇒ Object
Returns the value of attribute a.
7 8 9 |
# File 'lib/parameters.rb', line 7 def a @a end |
#b ⇒ Object
Returns the value of attribute b.
7 8 9 |
# File 'lib/parameters.rb', line 7 def b @b end |
#coefficient ⇒ Object
Returns the value of attribute coefficient.
7 8 9 |
# File 'lib/parameters.rb', line 7 def coefficient @coefficient end |
Instance Method Details
#calculate_a(serie_a, serie_b) ⇒ Object
32 33 34 |
# File 'lib/parameters.rb', line 32 def calculate_a(serie_a, serie_b) prod_variances(serie_a, serie_b).reduce(:+) / serie_a.squared_variances.reduce(:+) end |
#calculate_b(serie_a, serie_b) ⇒ Object
36 37 38 |
# File 'lib/parameters.rb', line 36 def calculate_b(serie_a, serie_b) serie_b.average - (@a * serie_a.average) end |
#calculate_coefficient(serie_a, serie_b) ⇒ Object
calculation of the slope between the 2 series sigma(xi - moy_x)(yi - moy y) / squared_root(sigma(xi - moy_x)^2) x squared_root(sigma(yi - moy_y)^2))
17 18 19 20 21 22 |
# File 'lib/parameters.rb', line 17 def calculate_coefficient(serie_a, serie_b) sum_prod_variances = prod_variances(serie_a, serie_b).reduce(:+) squared_root_sum_variances_x = serie_a.squared_variances.reduce(:+)**0.5 squared_root_sum_variances_y = serie_b.squared_variances.reduce(:+)**0.5 sum_prod_variances / (squared_root_sum_variances_x * squared_root_sum_variances_y) end |
#prod_variances(serie_a, serie_b) ⇒ Object
array of (xi - moy_x)(yi - moy_y) i periods i periods
26 27 28 29 30 |
# File 'lib/parameters.rb', line 26 def prod_variances(serie_a, serie_b) prod_variances = serie_a.variances.zip(serie_b.variances) prod_variances.map! { |couple| couple.reduce(:*) } prod_variances end |