Class: Statistical::Distribution::Bernoulli

Inherits:
TwoPoint
  • Object
show all
Defined in:
lib/statistical/distribution/bernoulli.rb

Overview

Note:

The states used to represent success & failure must be Numeric. Using it on generic state lables can cause strange outcomes!

Note:

state_failure < state_sucesss, for the sake of sanity.

This is a convenience class implemented for syntactic sugar. ‘TwoPoint.new(p)` already mimics and is infact the behaviour of this class

Author:

  • Vaibhav Yenamandra

Instance Attribute Summary collapse

Attributes inherited from TwoPoint

#states, #support

Instance Method Summary collapse

Methods inherited from TwoPoint

#cdf, #mean, #pdf, #quantile, #variance

Constructor Details

#initialize(prob_success = 0.5) ⇒ Bernoulli

Returns a new instance of the Bernoulli distribution

Parameters:

  • prob_success (Float) (defaults to: 0.5)

    The probability of success



23
24
25
26
# File 'lib/statistical/distribution/bernoulli.rb', line 23

def initialize(prob_success = 0.5)
  super(prob_success)
  self
end

Instance Attribute Details

#pFloat (readonly)

probability of the success state (= 1)

Returns:

  • (Float)

    the current value of p



16
17
18
# File 'lib/statistical/distribution/bernoulli.rb', line 16

def p
  @p
end

#qFloat (readonly)

probability of the failure state (= 0)

Returns:

  • (Float)

    the current value of q



16
17
18
# File 'lib/statistical/distribution/bernoulli.rb', line 16

def q
  @q
end