Class: Croupier::Distributions::Triangular
- Inherits:
-
Croupier::Distribution
- Object
- Croupier::Distribution
- Croupier::Distributions::Triangular
- Defined in:
- lib/croupier/distributions/triangular.rb
Overview
Triangular Distribution Continuous probability distribution whose lower limit is a, upper limit b and mode c (a <= c <= b).
Instance Attribute Summary
Attributes inherited from Croupier::Distribution
#description, #name, #parameters
Class Method Summary collapse
Instance Method Summary collapse
- #default_parameters ⇒ Object
-
#initialize(options = {}) ⇒ Triangular
constructor
A new instance of Triangular.
- #inv_cdf(n) ⇒ Object
Methods inherited from Croupier::Distribution
#configure, #generate_number, #generate_sample, #params
Constructor Details
#initialize(options = {}) ⇒ Triangular
Returns a new instance of Triangular.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/croupier/distributions/triangular.rb', line 10 def initialize(={}) @name = "Triangular distribution" @description = "Continuous probability distribution whose lower limit is a, upper limit b and mode c (a <= c <= b)" configure() raise Croupier::InputParamsError, "Invalid interval values" if params[:a] >= params[:b] if params[:c] < params[:a] || params[:b] < params[:c] warn("Mode is not in the support. Mode value will be change to median.") params[:c] = (params[:a]+params[:b])/2; end @F_c = (params[:c]-params[:a])/(params[:b]-params[:a]) end |
Class Method Details
.cli_name ⇒ Object
34 35 36 |
# File 'lib/croupier/distributions/triangular.rb', line 34 def self.cli_name "triangular" end |
.cli_options ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/croupier/distributions/triangular.rb', line 38 def self. {:options => [ [:a, 'lower limit', {:type=>:float, :default => 0.0}], [:b, 'upper limit', {:type=>:float, :default => 1.0}], [:c, 'mode' , {:type=>:float, :default => 0.5}] ], :banner => "Triangular distribution. Continuous distribution whose support is the interval (a,b), with mode c." } end |
Instance Method Details
#default_parameters ⇒ Object
30 31 32 |
# File 'lib/croupier/distributions/triangular.rb', line 30 def default_parameters {:a => 0.0, :b => 1.0, :c => 0.5} end |
#inv_cdf(n) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/croupier/distributions/triangular.rb', line 22 def inv_cdf n if n < @F_c params[:a] + Math.sqrt( n * (params[:b] - params[:a]) * (params[:c] - params[:a]) ) else params[:b] - Math.sqrt( (1-n) * (params[:b] - params[:a]) * (params[:b] - params[:c]) ) end end |