tailieunhanh - Mastering Algorithms with Perl phần 9

Phần thú vị nhất của là định nghĩa của TAnimal lớp học, trong đó bao gồm một phương pháp ảo trừu tượng: giọng nói. Nó cũng rất quan trọng để thông báo rằng mỗi lớp học có nguồn gốc ghi đè định nghĩa này và cho biết thêm một phương pháp mới ảo, ăn. | Page 594 The Bernoulli Distribution bernoulli x p returns 1- p if x is 0 p if x is 1 0 otherwise. sub bernoulli my x p @_ return unless p 0 p 1 return x x 1 p 0 1 - p sub bernoulli_expected _ 0 sub bernoulli_variance _ 0 1 - _ 0 The Beta Distribution beta x a b returns the Beta distribution for x given the Beta parameters a and b. sub beta my x a b @_ return unless a 0 and b 0 return factorial a b - 1 factorial a - 1 factorial b - 1 x a - 1 1 - x b - 1 sub beta_expected _ 0 _ 0 _ 1 sub beta variance _ 0 1 7 _ 0 _ 1 2 _ 0 _ 1 1 The Binomial Distribution binomial x n p binomial_expected n p - sub binomial my x n p @_ return unless x 0 x int x n 0 n int n p 0 p 1 return factorial n factorial x factorial n - x p x 1 - p n - x sub binomial_expected _ 0 _ 1 sub binomial_variance _ 0 _ 1 1 - _ 1 The Cauchy Distribution use constant pi_inverse atan2 1 1 sub cauchy my x a b @_ return unless a 0 return pi_inverse a a 2 x - b 2 sub cauchy_expected _ 1 Page 595 The Chi Square Distribution sub chi_square my x n @_ return 0 unless x 0 return 1 factorial n 2 - 1 2 - n 2 x n 2 - 1 exp - x 2 sub chi_square_expected _ 0 sub chi_square_variance 2 _ 0 The Erlang Distribution sub erlang my x a n @_ return unless a 0 n 0 n int n return 0 unless x 0 return a n x n-1 exp - a x factorial n-1 sub erlang_expected _ 1 _ 0 sub erlang_variance _ 1 _ 0 2 The Exponential Distribution sub exponential my x a @_ return unless a 0 return 0 unless x 0 return a exp - a x sub exponential_expected 1 _ 0 sub exponential_variance 1 _ 0 2 The Gamma Distribution sub gamma my x a b @_ return unless a -1 b 0 return 0 unless x 0 return x a exp - x b factorial a b a 1 sub gamma_expected _ 0 1 _ 1 sub gamma_variance _ 0 1 _ 1 2 The Gaussian Normal Distribution use constant two_pi_sqrt_inverse 1 sqrt 8 atan2 1 1 sub gaussian my x mean variance @_ return two_pi_sqrt_inverse Page 596 exp - x - mean 2 2 variance sqrt variance We don t provide subroutines to compute the expected value and variance .

TỪ KHÓA LIÊN QUAN