Class: Benchmark::Experiment::DescriptiveStatistics
- Inherits:
-
Object
- Object
- Benchmark::Experiment::DescriptiveStatistics
- Defined in:
- lib/benchmark/lab/descriptive_statistics.rb
Instance Attribute Summary collapse
-
#first_quartile ⇒ Object
readonly
Returns the value of attribute first_quartile.
-
#maximum ⇒ Object
readonly
Returns the value of attribute maximum.
-
#median ⇒ Object
readonly
Returns the value of attribute median.
-
#minimum ⇒ Object
readonly
Returns the value of attribute minimum.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#sample ⇒ Object
readonly
Returns the value of attribute sample.
-
#third_quartile ⇒ Object
readonly
Returns the value of attribute third_quartile.
Instance Method Summary collapse
-
#initialize(sample, name = '') ⇒ DescriptiveStatistics
constructor
A new instance of DescriptiveStatistics.
- #interquartile_range ⇒ Object
- #sample_size ⇒ Object
- #to_json(options = {}) ⇒ Object
Constructor Details
#initialize(sample, name = '') ⇒ DescriptiveStatistics
Returns a new instance of DescriptiveStatistics.
4 5 6 7 8 9 10 11 12 |
# File 'lib/benchmark/lab/descriptive_statistics.rb', line 4 def initialize(sample, name = '') # raise exception if empty sample @name = name @sample = sample.sort @minimum, @maximum = @sample.minmax @median = calculate_median_of(@sample) @first_quartile = calculate_first_quartile_of(@sample) @third_quartile = calculate_third_quartile_of(@sample) end |
Instance Attribute Details
#first_quartile ⇒ Object (readonly)
Returns the value of attribute first_quartile.
14 15 16 |
# File 'lib/benchmark/lab/descriptive_statistics.rb', line 14 def first_quartile @first_quartile end |
#maximum ⇒ Object (readonly)
Returns the value of attribute maximum.
14 15 16 |
# File 'lib/benchmark/lab/descriptive_statistics.rb', line 14 def maximum @maximum end |
#median ⇒ Object (readonly)
Returns the value of attribute median.
14 15 16 |
# File 'lib/benchmark/lab/descriptive_statistics.rb', line 14 def median @median end |
#minimum ⇒ Object (readonly)
Returns the value of attribute minimum.
14 15 16 |
# File 'lib/benchmark/lab/descriptive_statistics.rb', line 14 def minimum @minimum end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
14 15 16 |
# File 'lib/benchmark/lab/descriptive_statistics.rb', line 14 def name @name end |
#sample ⇒ Object (readonly)
Returns the value of attribute sample.
14 15 16 |
# File 'lib/benchmark/lab/descriptive_statistics.rb', line 14 def sample @sample end |
#third_quartile ⇒ Object (readonly)
Returns the value of attribute third_quartile.
14 15 16 |
# File 'lib/benchmark/lab/descriptive_statistics.rb', line 14 def third_quartile @third_quartile end |
Instance Method Details
#interquartile_range ⇒ Object
20 21 22 |
# File 'lib/benchmark/lab/descriptive_statistics.rb', line 20 def interquartile_range @third_quartile - @first_quartile end |
#sample_size ⇒ Object
16 17 18 |
# File 'lib/benchmark/lab/descriptive_statistics.rb', line 16 def sample_size sample.size end |
#to_json(options = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/benchmark/lab/descriptive_statistics.rb', line 24 def to_json( = {}) { 'name' => name, 'sample' => sample, 'sample_size' => sample_size, 'minimum' => minimum, 'maximum' => maximum, 'first_quartile' => first_quartile, 'third_quartile' => third_quartile, 'median' => median, 'interquartile_range' => interquartile_range }.to_json end |