Class: BigBench::PostProcessor::Environment::NormalDistribution

Inherits:
Object
  • Object
show all
Includes:
BigBench::PostProcessor::Environment
Defined in:
lib/bigbench/post_processor/environment.rb

Overview

Calculates a gaussion normal distribution with the mean a variance of the supplied y values

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BigBench::PostProcessor::Environment

#appearing, #cluster, #each_benchmark, #each_tracking, #normal_distribution, #polynomial_regression, reset!, #scope, #scope_to_benchmark, #statistics, #trackings

Constructor Details

#initialize(x, y, degree) ⇒ NormalDistribution

Returns a new instance of NormalDistribution.



289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# File 'lib/bigbench/post_processor/environment.rb', line 289

def initialize x, y, degree
  @mean, @x = y.average, x
  @sd = y.inject(0){ |result, element| result + (element - @mean).abs }.to_f / y.size.to_f
  
  # Setup functions that map the guassian normal distribution
  @distribution = lambda { |x| 1 / Math.sqrt(2 * Math::PI * @sd) * Math::E**( -0.5 * (x - @mean)**2 / @sd) }
  
  # Setup x to match the center mean
  @x = []
  upper_limit = @mean + (6 * @sd)
  lower_limit = @mean - (6 * @sd)
  delta_limit = upper_limit - lower_limit
  steps = 120
  step_size  = delta_limit / steps 
  steps.times{ |step| @x << (step * step_size) + lower_limit }
  
  # Store formula for printing
  @formula = "1 / sqrt(2 * pi * #{@sd}) * e**( -0.5 * (x - #{@mean})**2 / #{@sd})"
end

Instance Attribute Details

#formulaObject (readonly)

Returns the value of attribute formula.



287
288
289
# File 'lib/bigbench/post_processor/environment.rb', line 287

def formula
  @formula
end

#meanObject (readonly)

Returns the value of attribute mean.



284
285
286
# File 'lib/bigbench/post_processor/environment.rb', line 284

def mean
  @mean
end

#sdObject (readonly)

Returns the value of attribute sd.



285
286
287
# File 'lib/bigbench/post_processor/environment.rb', line 285

def sd
  @sd
end

#xObject (readonly)

Returns the value of attribute x.



286
287
288
# File 'lib/bigbench/post_processor/environment.rb', line 286

def x
  @x
end

Instance Method Details

#yObject

Returns an array with the distribution values like this:

[0.0, 0.1, 1.2, 4.5, 10.8, 4.5, 1.2, 0.1, 0.0]


313
314
315
# File 'lib/bigbench/post_processor/environment.rb', line 313

def y
  @x.map{ |x| @distribution.call(x).round(3) }
end