Class: Benchmark::Experiment::DescriptiveStatistics

Inherits:
Object
  • Object
show all
Defined in:
lib/benchmark/lab/descriptive_statistics.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_quartileObject (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

#maximumObject (readonly)

Returns the value of attribute maximum.



14
15
16
# File 'lib/benchmark/lab/descriptive_statistics.rb', line 14

def maximum
  @maximum
end

#medianObject (readonly)

Returns the value of attribute median.



14
15
16
# File 'lib/benchmark/lab/descriptive_statistics.rb', line 14

def median
  @median
end

#minimumObject (readonly)

Returns the value of attribute minimum.



14
15
16
# File 'lib/benchmark/lab/descriptive_statistics.rb', line 14

def minimum
  @minimum
end

#nameObject (readonly)

Returns the value of attribute name.



14
15
16
# File 'lib/benchmark/lab/descriptive_statistics.rb', line 14

def name
  @name
end

#sampleObject (readonly)

Returns the value of attribute sample.



14
15
16
# File 'lib/benchmark/lab/descriptive_statistics.rb', line 14

def sample
  @sample
end

#third_quartileObject (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_rangeObject



20
21
22
# File 'lib/benchmark/lab/descriptive_statistics.rb', line 20

def interquartile_range
  @third_quartile - @first_quartile
end

#sample_sizeObject



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(options = {})
  {
    '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