Ticket #11572: trac_11572_added_distributions.patch

File trac_11572_added_distributions.patch, 31.7 KB (added by Kamhamea, 8 years ago)

Patch adds a list of probability distributions

  • sage/gsl/gsl_random.pxi

    # HG changeset patch
    # User mato.nagel@gmx.net
    # Date 1309845002 -7200
    # Node ID d22c8024cd5e57063ee4f46240b6f3183c9b7159
    # Parent  120c07be6358d93bcff503363d379c26b8342f2b
    i
    Trac 11572 New probability distributions added
    
    diff -r 120c07be6358 -r d22c8024cd5e sage/gsl/gsl_random.pxi
    a b  
    3535  double gsl_ran_flat_pdf (double x,  double a,  double b)
    3636 
    3737  double gsl_ran_gamma ( gsl_rng * r,  double a,  double b)
    38   double gsl_ran_gamma_int ( gsl_rng * r,  unsigned int a)
    3938  double gsl_ran_gamma_pdf ( double x,  double a,  double b)
    4039 
    4140  double gsl_ran_gaussian ( gsl_rng * r,  double sigma)
     
    111110  double gsl_ran_tdist ( gsl_rng * r,  double nu)
    112111  double gsl_ran_tdist_pdf ( double x,  double nu)
    113112 
     113  double gsl_ran_fdist ( gsl_rng * r,  double a,  double b)
     114  double gsl_ran_fdist_pdf ( double x,  double a,  double b)
     115
    114116  double gsl_ran_laplace ( gsl_rng * r,  double a)
    115117  double gsl_ran_laplace_pdf ( double x,  double a)
    116118 
     
    197199  double gsl_cdf_fdist_P ( double x,  double nu1,  double nu2)
    198200  double gsl_cdf_fdist_Q ( double x,  double nu1,  double nu2)
    199201 
     202  double gsl_cdf_fdist_Pinv(double x, double a, double b)
     203  double gsl_cdf_fdist_Qinv(double x, double a, double b)
     204
    200205  double gsl_cdf_beta_P ( double x,  double a,  double b)
    201206  double gsl_cdf_beta_Q ( double x,  double a,  double b)
    202207
     
    243248 
    244249  double gsl_cdf_logistic_Pinv ( double P,  double a)
    245250  double gsl_cdf_logistic_Qinv ( double Q,  double a)
     251
     252  double gsl_cdf_binomial_P (unsigned int k, double p, unsigned int n)
     253  double gsl_cdf_binomial_Q (unsigned int k, double p, unsigned int n)
     254
     255  double gsl_cdf_poisson_P (unsigned int k, double mu)
     256  double gsl_cdf_poisson_Q (unsigned int k, double mu)
     257
     258  double gsl_cdf_geometric_P (unsigned int k, double p)
     259  double gsl_cdf_geometric_Q (unsigned int k, double p)
     260
     261  double gsl_cdf_negative_binomial_P (unsigned int k, double p, double n)
     262  double gsl_cdf_negative_binomial_Q (unsigned int k, double p, double n)
     263
     264  double gsl_cdf_pascal_P (unsigned int k, double p, unsigned int n)
     265  double gsl_cdf_pascal_Q (unsigned int k, double p, unsigned int n)
     266
     267  double gsl_cdf_hypergeometric_P (unsigned int k, unsigned int n1,
     268                                 unsigned int n2, unsigned int t)
     269  double gsl_cdf_hypergeometric_Q (unsigned int k, unsigned int n1,
     270                                 unsigned int n2, unsigned int t)
  • sage/gsl/probability_distribution.pyx

    diff -r 120c07be6358 -r d22c8024cd5e sage/gsl/probability_distribution.pyx
    a b  
    66- ``RealDistribution``: various real-valued probability distributions.
    77
    88- ``SphericalDistribution``: uniformly distributed points on the
    9   surface of an `$n-1$` sphere in `$n$` dimensional euclidean space.
     9  surface of an `n-1` sphere in `n` dimensional euclidean space.
    1010
    1111- ``GeneralDiscreteDistribution``: user-defined discrete distributions.
    1212
     
    1919- Carlo Hamalainen (2008-08): full doctest coverage, more documentation,
    2020  GeneralDiscreteDistribution, misc fixes.
    2121
     22- Kwankyu Lee (2010-05-29): F-distribution support.
     23
    2224REFERENCES:
    2325
    2426    GNU gsl library, General discrete distributions
     
    4749from sage.modules.free_module_element import vector
    4850
    4951
    50 #TODO: Add more distributions available in gsl
    51 #available but not currently wrapped are exponential, laplace, cauchy, landau, gamma,
    52 #gamma, beta logistic.
     52#TODO: Add more distributions
     53# still available in gsl but not currently wrapped are
     54# Erlang distribution which is simplified gamma distribution
     55# Bernoulli which is simplified binomial
     56# Dirichlet distribution which is multivariate generalization of the beta distribution
     57# flat which is identical to uniform
     58# logarithmic distribution
     59# multinomial distribution which is a generalization of the binomial distribution.
     60# Lévy distribution
     61#
     62# not available in gsl
     63# Wilcoxon distribution
    5364
    5465cdef enum:
    5566    uniform
     
    5869    lognormal
    5970    pareto
    6071    t
     72    F
    6173    chisquared
    6274    exppow
    6375    weibull
    6476    beta
     77    expon
     78    laplace
     79    cauchy
     80    landau
     81    gamma
     82    logistic
     83    gumbel1
     84    gumbel2
     85    binom
     86    pois
     87    geom
     88    nbinom
     89    hyper
     90   
    6591 
    6692cdef class ProbabilityDistribution:
    6793    """
     
    365391        sage: T.cum_distribution_function_inv(.5)
    366392        2.0
    367393 
    368     The student's t distribution has one parameter ``nu``::
     394    The t-distribution has one parameter ``nu``::
    369395
    370396        sage: nu = 1
    371397        sage: T = RealDistribution('t', nu)
     
    378404        sage: T.cum_distribution_function_inv(.5)
    379405        0.0
    380406 
    381     The chi squared distribution has one parameter ``nu``::
     407    The F-distribution has two parameters ``nu1`` and ``nu2``::     
     408
     409        sage: nu1 = 9; nu2 = 17                             
     410        sage: F = RealDistribution('F', [nu1,nu2])
     411        sage: F.get_random_element() # random
     412        1.65211335491
     413        sage: F.distribution_function(1)
     414        0.669502550519
     415        sage: F.cum_distribution_function(3.68)
     416        0.98997177723
     417        sage: F.cum_distribution_function_inv(0.99)
     418        3.68224152405
     419 
     420    The chi-squared distribution has one parameter ``nu``::
    382421
    383422        sage: nu = 1
    384423        sage: T = RealDistribution('chisquared', nu)
     
    415454        0.0
    416455        sage: T.cum_distribution_function(1)
    417456        1.0
     457        sage: T.cum_distribution_function_inv(1)
     458        1.0
    418459
    419460    The weibull distribution has two parameters ``a`` and ``b``::
    420461
     
    430471        sage: T.cum_distribution_function_inv(.5)
    431472        0.69314718056
    432473
     474    The exponential distribution has one parameter ``mu``::
     475
     476        sage: mu = 1
     477        sage: T = RealDistribution('exp', [mu])
     478        sage: T.get_random_element() # random
     479        0.539605826512
     480        sage: T.distribution_function(0)
     481        1.0
     482        sage: T.cum_distribution_function(1)
     483        0.632120558829
     484        sage: T.cum_distribution_function_inv(.63)
     485        0.994252273344
     486
     487    The laplace distribution has one parameter ``mu``::
     488
     489        sage: mu = 1
     490        sage: T = RealDistribution('laplace', [mu])
     491        sage: T.get_random_element() # random
     492        0.61130679195
     493        sage: T.distribution_function(0)
     494        0.5
     495        sage: T.cum_distribution_function(1)
     496        0.816060279414
     497        T.cum_distribution_function_inv(.816)
     498        0.999672340813
     499
     500    The cauchy distribution has one parameter ``a``::
     501
     502        sage: a = 1
     503        sage: T = RealDistribution('cauchy', [a])
     504        sage: T.get_random_element() # random
     505        0.244430093406
     506        sage: T.distribution_function(0)
     507        0.318309886184
     508        sage: T.cum_distribution_function(1)
     509        0.75
     510        T.cum_distribution_function_inv(.75)
     511        1.0
     512
     513    The landau distribution has no parameters::
     514
     515        sage: T = RealDistribution('landau')
     516        sage: T.get_random_element() # random
     517        4.03287345475
     518        sage: T.distribution_function(0)
     519        0.1788541609
     520
     521    The gamma distribution has two parameters ``a`` and ``b``::
     522
     523        sage: a = 9
     524        sage: b = 0.5
     525        sage: T = RealDistribution('gamma', [a, b])
     526        sage: T.get_random_element() # random
     527        7.18005786995
     528        sage: T.distribution_function(4)
     529        0.279173063901
     530        sage: T.cum_distribution_function(3)
     531        0.152762506015
     532        sage: T.cum_distribution_function_inv(.152)
     533        2.99630319428
     534
     535    The logistic distribution has 1 parameter ``sigma``::
     536 
     537        sage: sigma = 1
     538        sage: T = RealDistribution('logistic', [sigma])
     539        sage: T.get_random_element() # random
     540        2.12029493681
     541        sage: T.distribution_function(0)
     542        0.25
     543        sage: T.cum_distribution_function(1)
     544        0.73105857863
     545        sage: T.cum_distribution_function_inv(.73)
     546        0.994622575144
     547 
     548    The gumbel type 1 distribution has two parameters ``a`` and ``b``::
     549
     550        sage: a = 1
     551        sage: b = 1
     552        sage: T = RealDistribution('gumbel1', [a, b])
     553        sage: T.get_random_element() # random
     554        -1.10577509408
     555        sage: T.distribution_function(0)
     556        0.367879441171
     557        sage: T.cum_distribution_function(1)
     558        0.692200627555
     559        sage: T.cum_distribution_function_inv(.69)
     560        0.991381583151
     561
     562    The gumbel type 2 distribution has two parameters ``a`` and ``b``::
     563
     564        sage: a = 1
     565        sage: b = 1
     566        sage: T = RealDistribution('gumbel2', [a, b])
     567        sage: T.get_random_element() # random
     568        24.5074179476
     569        sage: T.distribution_function(1)
     570        0.367879441171
     571        sage: T.cum_distribution_function(3)
     572        0.716531310574
     573        sage: T.cum_distribution_function_inv(.71)
     574        2.91979064481
     575
     576    The binomial distribution has two parameters ``n`` and ``p``::
     577
     578        sage: n = 20
     579        sage: p = 0.1
     580        sage: T = RealDistribution('binom', [p, n])
     581        sage: T.get_random_element() # random
     582        2.0
     583        sage: T.distribution_function(1)
     584        0.270170343535
     585        sage: T.cum_distribution_function(3)
     586        0.867046676566
     587
     588    The poisson distribution has one parameter ``p``::
     589
     590        sage: p = 1
     591        sage: T = RealDistribution('pois', [p])
     592        sage: T.get_random_element() # random
     593        2.0
     594        sage: T.distribution_function(1)
     595        0.367879441171
     596        sage: T.cum_distribution_function(3)
     597        0.981011843124
     598
     599    The geometric distribution has one parameter ``p``::
     600
     601        sage: p = 0.2
     602        sage: T = RealDistribution('geom', [p])
     603        sage: T.get_random_element() # random
     604        1.0
     605        sage: T.distribution_function(1)
     606        0.2
     607        sage: T.cum_distribution_function(3)
     608        0.488
     609
     610    The negative binomial distribution has two parameters ``p`` and ``r``::
     611
     612        sage: p = 0.6
     613        sage: r = 1
     614        sage: T = RealDistribution('nbinom', [p,r])
     615        sage: T.get_random_element() # random
     616        1.0
     617        sage: T.distribution_function(1)
     618        0.24
     619        sage: T.cum_distribution_function(3)
     620        0.9744
     621
     622    The hypergeometric distribution has three parameters ``n1``, ``n2``, and ``t``::
     623
     624        sage: n1 = 25
     625        sage: n2 = 40
     626        sage: t = 10
     627        sage: T = RealDistribution('hyper', [n1,n2,t])
     628        sage: T.get_random_element() # random
     629        7.0
     630        sage: T.distribution_function(2)
     631        0.096
     632        sage: T.cum_distribution_function(2)
     633        0.936
     634
    433635    It is possible to select which random number generator drives the
    434636    sampling as well as the seed.  The default is the Mersenne
    435637    twister. Also available are the RANDLXS algorithm and the
     
    537739
    538740    def get_random_element(self):
    539741        """
    540         Get a random sample the probability distribution.
     742        Get a random sample from the probability distribution.
    541743
    542744        EXAMPLE::
    543745
     
    560762            result = gsl_ran_pareto(self.r, self.parameters[0], self.parameters[1])
    561763        elif self.distribution_type == t:
    562764            result = gsl_ran_tdist(self.r, self.parameters[0])
     765        elif self.distribution_type == F:
     766            result = gsl_ran_fdist(self.r, self.parameters[0], self.parameters[1])
    563767        elif self.distribution_type == chisquared:
    564768            result = gsl_ran_chisq(self.r, self.parameters[0])
    565769        elif self.distribution_type == exppow:
     
    568772            result = gsl_ran_weibull(self.r, self.parameters[0], self.parameters[1])
    569773        elif self.distribution_type == beta:
    570774            result = gsl_ran_beta(self.r, self.parameters[0], self.parameters[1])
    571  
     775        elif self.distribution_type == expon:
     776            result = gsl_ran_exponential(self.r, self.parameters[0])
     777        elif self.distribution_type == laplace:
     778            result = gsl_ran_laplace(self.r, self.parameters[0])
     779        elif self.distribution_type == cauchy:
     780            result = gsl_ran_cauchy(self.r, self.parameters[0])
     781        elif self.distribution_type == landau:
     782            result = gsl_ran_landau(self.r)
     783        elif self.distribution_type == gamma:
     784            result = gsl_ran_gamma(self.r, self.parameters[0], self.parameters[1])
     785        elif self.distribution_type == logistic:
     786            result = gsl_ran_logistic(self.r, self.parameters[0])
     787        elif self.distribution_type == gumbel1:
     788            result = gsl_ran_gumbel1(self.r, self.parameters[0], self.parameters[1])
     789        elif self.distribution_type == gumbel2:
     790            result = gsl_ran_gumbel2(self.r, self.parameters[0], self.parameters[1])
     791        elif self.distribution_type == binom:
     792            result = gsl_ran_binomial(self.r, self.parameters[0], int(self.parameters[1]))
     793        elif self.distribution_type == pois:
     794            result = gsl_ran_poisson(self.r, self.parameters[0])
     795        elif self.distribution_type == geom:
     796            result = gsl_ran_geometric(self.r, self.parameters[0])
     797        elif self.distribution_type == nbinom:
     798            result = gsl_ran_negative_binomial(self.r, self.parameters[0], self.parameters[1])
     799        elif self.distribution_type == hyper:
     800            result = gsl_ran_hypergeometric(self.r, int(self.parameters[0]), int(self.parameters[1]), int(self.parameters[2]))
     801        else:
     802            raise TypeError, "Probability distribution not supported"
     803   
    572804        return sage.rings.real_double.RDF(result)
    573805    def set_distribution(self, name = 'uniform', parameters = []):
    574806        """
     
    642874            self.parameters = <double*>malloc(sizeof(double))
    643875            self.parameters[0] = float(parameters)
    644876            self.distribution_type = t
    645  
     877        elif name == 'F':
     878            if len(parameters) != 2:
     879                raise TypeError, "F-distribution requires two real parameters"
     880            try:
     881                map(float, parameters)
     882            except:
     883                raise TypeError, "F-distribution requires real parameters"
     884            self.parameters = <double *>malloc(sizeof(double)*2)
     885            self.parameters[0] = float(parameters[0])
     886            self.parameters[1] = float(parameters[1])
     887            self.distribution_type = F       
    646888        elif name == 'chisquared':
    647889            try:
    648890                float(parameters)
     
    690932            self.parameters[1] = float(parameters[1])
    691933            self.distribution_type = beta
    692934 
     935        elif name == 'exp':
     936            if len(parameters) != 1:
     937                raise TypeError, "exponential distribution requires one real parameter"
     938            try:
     939                map(float, parameters)
     940            except:
     941                raise TypeError, "exponential distribution requires a real parameter"
     942
     943            self.parameters = <double *>malloc(sizeof(double)*1)
     944            self.parameters[0] = float(parameters[0])
     945            self.distribution_type = expon
     946 
     947        elif name == 'laplace':
     948            if len(parameters) != 1:
     949                raise TypeError, "laplace distribution requires one real parameter"
     950            try:
     951                map(float, parameters)
     952            except:
     953                raise TypeError, "laplace distribution requires a real parameter"
     954
     955            self.parameters = <double *>malloc(sizeof(double)*1)
     956            self.parameters[0] = float(parameters[0])
     957            self.distribution_type = laplace
     958 
     959        elif name == 'cauchy':
     960            if len(parameters) != 1:
     961                raise TypeError, "cauchy distribution requires one real parameter"
     962            try:
     963                map(float, parameters)
     964            except:
     965                raise TypeError, "cauchy distribution requires a real parameter"
     966
     967            self.parameters = <double *>malloc(sizeof(double)*1)
     968            self.parameters[0] = float(parameters[0])
     969            self.distribution_type = cauchy
     970 
     971        elif name == 'landau':
     972            if len(parameters) != 0:
     973                raise TypeError, "landau distribution requires no real parameter"
     974            try:
     975                map(float, parameters)
     976            except:
     977                raise TypeError, "landau distribution requires no real parameter"
     978
     979            self.parameters = <double *>malloc(sizeof(double)*1)
     980            self.distribution_type = landau
     981 
     982        elif name == 'gamma':
     983            if len(parameters) != 2:
     984                raise TypeError, "gamma distribution requires two real parameters"
     985            try:
     986                map(float, parameters)
     987            except:
     988                raise TypeError, "gamma distribution requires real parameters"
     989
     990            self.parameters = <double *>malloc(sizeof(double)*2)
     991            self.parameters[0] = float(parameters[0])
     992            self.parameters[1] = float(parameters[1])
     993            self.distribution_type = gamma
     994 
     995        elif name == 'logistic':
     996            if len(parameters) != 1:
     997                raise TypeError, "logistic distribution requires one real parameter"
     998            try:
     999                map(float, parameters)
     1000            except:
     1001                raise TypeError, "logistic distribution requires one real parameter"
     1002
     1003            self.parameters = <double *>malloc(sizeof(double)*1)
     1004            self.parameters[0] = float(parameters[0])
     1005            self.distribution_type = logistic
     1006 
     1007        elif name == 'gumbel1':
     1008            if len(parameters) != 2:
     1009                raise TypeError, "gumbel type 1 distribution requires two real parameters"
     1010            try:
     1011                map(float, parameters)
     1012            except:
     1013                raise TypeError, "gumbel type 1 distribution requires real parameters"
     1014
     1015            self.parameters = <double *>malloc(sizeof(double)*2)
     1016            self.parameters[0] = float(parameters[0])
     1017            self.parameters[1] = float(parameters[1])
     1018            self.distribution_type = gumbel1
     1019
     1020        elif name == 'gumbel2':
     1021            if len(parameters) != 2:
     1022                raise TypeError, "gumbel type 2 distribution requires two real parameters"
     1023            try:
     1024                map(float, parameters)
     1025            except:
     1026                raise TypeError, "gumbel type 2 distribution requires real parameters"
     1027
     1028            self.parameters = <double *>malloc(sizeof(double)*2)
     1029            self.parameters[0] = float(parameters[0])
     1030            self.parameters[1] = float(parameters[1])
     1031            self.distribution_type = gumbel2
     1032
     1033        elif name == 'binom':
     1034            if len(parameters) != 2:
     1035                raise TypeError, "binomial distribution requires one real and one integer parameters"
     1036            try:
     1037                map(float, parameters)
     1038            except:
     1039                raise TypeError, "binomial distribution requires one real and one integer parameters"
     1040
     1041            self.parameters = <double *>malloc(sizeof(double)*2)
     1042            self.parameters[0] = float(parameters[0])
     1043            self.parameters[1] = int(parameters[1])
     1044            self.distribution_type = binom
     1045 
     1046        elif name == 'pois':
     1047            if len(parameters) != 1:
     1048                raise TypeError, "Poisson distribution requires one real parameters"
     1049            try:
     1050                map(float, parameters)
     1051            except:
     1052                raise TypeError, "Poisson distribution requires one real parameter"
     1053
     1054            self.parameters = <double *>malloc(sizeof(double)*1)
     1055            self.parameters[0] = float(parameters[0])
     1056            self.distribution_type = pois
     1057 
     1058        elif name == 'geom':
     1059            if len(parameters) != 1:
     1060                raise TypeError, "geometric distribution requires one real parameters"
     1061            try:
     1062                map(float, parameters)
     1063            except:
     1064                raise TypeError, "geometric distribution requires one real parameter"
     1065
     1066            self.parameters = <double *>malloc(sizeof(double)*1)
     1067            self.parameters[0] = float(parameters[0])
     1068            self.distribution_type = geom
     1069
     1070        elif name == 'nbinom':
     1071            if len(parameters) != 2:
     1072                raise TypeError, "negative binomial distribution requires two real parameters"
     1073            try:
     1074                map(float, parameters)
     1075            except:
     1076                raise TypeError, "negative binomial distribution requires real parameters"
     1077
     1078            self.parameters = <double *>malloc(sizeof(double)*2)
     1079            self.parameters[0] = float(parameters[0])
     1080            self.parameters[1] = float(parameters[1])
     1081            self.distribution_type = nbinom
     1082 
     1083        elif name == 'hyper':
     1084            if len(parameters) != 3:
     1085                raise TypeError, "hypergeometric distribution requires three integer parameters"
     1086            try:
     1087                map(float, parameters)
     1088            except:
     1089                raise TypeError, "hypergeometric distribution requires integer parameters"
     1090
     1091            self.parameters = <double *>malloc(sizeof(double)*3)
     1092            self.parameters[0] = int(parameters[0])
     1093            self.parameters[1] = int(parameters[1])
     1094            self.parameters[2] = int(parameters[2])
     1095            self.distribution_type = hyper
    6931096 
    6941097        else:
    695             raise TypeError, "Not a valid probability distribution"
     1098            raise TypeError, "Probability distribution not supported"
    6961099 
    6971100        self.name = name
    6981101 
     
    7481151            return sage.rings.real_double.RDF(gsl_ran_pareto_pdf(x, self.parameters[0], self.parameters[1]))
    7491152        elif self.distribution_type == t:
    7501153            return sage.rings.real_double.RDF(gsl_ran_tdist_pdf(x, self.parameters[0]))
     1154        elif self.distribution_type == F:
     1155            return sage.rings.real_double.RDF(gsl_ran_fdist_pdf(x, self.parameters[0], self.parameters[1]))
    7511156        elif self.distribution_type == chisquared:
    7521157            return sage.rings.real_double.RDF(gsl_ran_chisq_pdf(x, self.parameters[0]))
    7531158        elif self.distribution_type == exppow:
     
    7561161            return sage.rings.real_double.RDF(gsl_ran_weibull_pdf(x, self.parameters[0], self.parameters[1]))
    7571162        elif self.distribution_type == beta:
    7581163            return sage.rings.real_double.RDF(gsl_ran_beta_pdf(x, self.parameters[0], self.parameters[1]))
    759  
     1164        elif self.distribution_type == expon:
     1165            return sage.rings.real_double.RDF(gsl_ran_exponential_pdf(x, self.parameters[0]))
     1166        elif self.distribution_type == laplace:
     1167            return sage.rings.real_double.RDF(gsl_ran_laplace_pdf(x, self.parameters[0]))
     1168        elif self.distribution_type == cauchy:
     1169            return sage.rings.real_double.RDF(gsl_ran_cauchy_pdf(x, self.parameters[0]))
     1170        elif self.distribution_type == landau:
     1171            return sage.rings.real_double.RDF(gsl_ran_landau_pdf(x))
     1172        elif self.distribution_type == gamma:
     1173            return sage.rings.real_double.RDF(gsl_ran_gamma_pdf(x, self.parameters[0], self.parameters[1]))
     1174        elif self.distribution_type == logistic:
     1175            return sage.rings.real_double.RDF(gsl_ran_logistic_pdf(x, self.parameters[0]))
     1176        elif self.distribution_type == gumbel1:
     1177            return sage.rings.real_double.RDF(gsl_ran_gumbel1_pdf(x, self.parameters[0], self.parameters[1]))
     1178        elif self.distribution_type == gumbel2:
     1179            return sage.rings.real_double.RDF(gsl_ran_gumbel2_pdf(x, self.parameters[0], self.parameters[1]))
     1180        elif self.distribution_type == binom:
     1181            return sage.rings.real_double.RDF(gsl_ran_binomial_pdf(x, self.parameters[0], int(self.parameters[1])))
     1182        elif self.distribution_type == pois:
     1183            return sage.rings.real_double.RDF(gsl_ran_poisson_pdf(x, self.parameters[0]))
     1184        elif self.distribution_type == geom:
     1185            return sage.rings.real_double.RDF(gsl_ran_geometric_pdf(x, self.parameters[0]))
     1186        elif self.distribution_type == nbinom:
     1187            return sage.rings.real_double.RDF(gsl_ran_negative_binomial_pdf(x, self.parameters[0], self.parameters[1]))
     1188        elif self.distribution_type == hyper:
     1189            return sage.rings.real_double.RDF(gsl_ran_hypergeometric_pdf(x, int(self.parameters[0]), int(self.parameters[1]), int(self.parameters[2])))
     1190        else:
     1191            raise TypeError, "Probability distribution not supported"
    7601192
    7611193    def cum_distribution_function(self, x):
    7621194        """
     
    7811213            return sage.rings.real_double.RDF(gsl_cdf_pareto_P(x, self.parameters[0], self.parameters[1]))
    7821214        elif self.distribution_type == t:
    7831215            return sage.rings.real_double.RDF(gsl_cdf_tdist_P(x, self.parameters[0]))
     1216        elif self.distribution_type == F:
     1217            return sage.rings.real_double.RDF(gsl_cdf_fdist_P(x, self.parameters[0], self.parameters[1]))
    7841218        elif self.distribution_type == chisquared:
    7851219            return sage.rings.real_double.RDF(gsl_cdf_chisq_P(x, self.parameters[0]))
    7861220        elif self.distribution_type == exppow:
     
    7891223            return sage.rings.real_double.RDF(gsl_cdf_weibull_P(x, self.parameters[0], self.parameters[1]))
    7901224        elif self.distribution_type == beta:
    7911225            return sage.rings.real_double.RDF(gsl_cdf_beta_P(x, self.parameters[0], self.parameters[1]))
     1226        elif self.distribution_type == expon:
     1227            return sage.rings.real_double.RDF(gsl_cdf_exponential_P(x, self.parameters[0]))
     1228        elif self.distribution_type == laplace:
     1229            return sage.rings.real_double.RDF(gsl_cdf_laplace_P(x, self.parameters[0]))
     1230        elif self.distribution_type == cauchy:
     1231            return sage.rings.real_double.RDF(gsl_cdf_cauchy_P(x, self.parameters[0]))
     1232        elif self.distribution_type == landau:
     1233            raise TypeError, "Cumulative probability function for landau distribution not defined"
     1234        elif self.distribution_type == gamma:
     1235            return sage.rings.real_double.RDF(gsl_cdf_gamma_P(x, self.parameters[0], self.parameters[1]))
     1236        elif self.distribution_type == logistic:
     1237            return sage.rings.real_double.RDF(gsl_cdf_logistic_P(x, self.parameters[0]))
     1238        elif self.distribution_type == gumbel1:
     1239            return sage.rings.real_double.RDF(gsl_cdf_gumbel1_P(x, self.parameters[0], self.parameters[1]))
     1240        elif self.distribution_type == gumbel2:
     1241            return sage.rings.real_double.RDF(gsl_cdf_gumbel2_P(x, self.parameters[0], self.parameters[1]))
     1242        elif self.distribution_type == binom:
     1243            return sage.rings.real_double.RDF(gsl_cdf_binomial_P(x, self.parameters[0], int(self.parameters[1])))
     1244        elif self.distribution_type == pois:
     1245            return sage.rings.real_double.RDF(gsl_cdf_poisson_P(x, self.parameters[0]))
     1246        elif self.distribution_type == geom:
     1247            return sage.rings.real_double.RDF(gsl_cdf_geometric_P(x, self.parameters[0]))
     1248        elif self.distribution_type == nbinom:
     1249            return sage.rings.real_double.RDF(gsl_cdf_negative_binomial_P(x, self.parameters[0], self.parameters[1]))
     1250        elif self.distribution_type == hyper:
     1251            return sage.rings.real_double.RDF(gsl_cdf_hypergeometric_P(x, int(self.parameters[0]), int(self.parameters[1]), int(self.parameters[2])))
     1252        else:
     1253            raise TypeError, "Probability distribution not supported"
    7921254 
    7931255
    7941256    def cum_distribution_function_inv(self, x):
     
    8141276            return sage.rings.real_double.RDF(gsl_cdf_pareto_Pinv(x, self.parameters[0], self.parameters[1]))
    8151277        elif self.distribution_type == t:
    8161278            return sage.rings.real_double.RDF(gsl_cdf_tdist_Pinv(x, self.parameters[0]))
     1279        elif self.distribution_type == F:
     1280            return sage.rings.real_double.RDF(gsl_cdf_fdist_Pinv(x, self.parameters[0], self.parameters[1]))
    8171281        elif self.distribution_type == chisquared:
    8181282            return sage.rings.real_double.RDF(gsl_cdf_chisq_Pinv(x, self.parameters[0]))
    8191283        elif self.distribution_type == exppow:
    820             raise NotImplementedError, "gsl does not provide inverse for exponential power"
    821 #            return sage.rings.real_double.RDF(gsl_cdf_exppow_Pinv(x, self.parameters[0], self.parameters[1]))
     1284            raise NotImplementedError, "Inverted cumulative probability function for exponential power distribution not defined"
    8221285        elif self.distribution_type == weibull:
    8231286            return sage.rings.real_double.RDF(gsl_cdf_weibull_Pinv(x, self.parameters[0], self.parameters[1]))
    8241287        elif self.distribution_type == beta:
    8251288            return sage.rings.real_double.RDF(gsl_cdf_beta_Pinv(x, self.parameters[0], self.parameters[1]))
     1289        elif self.distribution_type == expon:
     1290            return sage.rings.real_double.RDF(gsl_cdf_exponential_Pinv(x, self.parameters[0]))
     1291        elif self.distribution_type == laplace:
     1292            return sage.rings.real_double.RDF(gsl_cdf_laplace_Pinv(x, self.parameters[0]))
     1293        elif self.distribution_type == cauchy:
     1294            return sage.rings.real_double.RDF(gsl_cdf_cauchy_Pinv(x, self.parameters[0]))
     1295        elif self.distribution_type == landau:
     1296            raise NotImplementedError, "Inverted cumulative probability function for landau distribution not defined"
     1297        elif self.distribution_type == gamma:
     1298            return sage.rings.real_double.RDF(gsl_cdf_gamma_Pinv(x, self.parameters[0], self.parameters[1]))
     1299        elif self.distribution_type == logistic:
     1300            return sage.rings.real_double.RDF(gsl_cdf_logistic_Pinv(x, self.parameters[0]))
     1301        elif self.distribution_type == gumbel1:
     1302            return sage.rings.real_double.RDF(gsl_cdf_gumbel1_Pinv(x, self.parameters[0], self.parameters[1]))
     1303        elif self.distribution_type == gumbel2:
     1304            return sage.rings.real_double.RDF(gsl_cdf_gumbel2_Pinv(x, self.parameters[0], self.parameters[1]))
     1305        elif self.distribution_type == binom:
     1306            raise NotImplementedError, "Inverted cumulative probability function for binomial distribution not defined"
     1307        elif self.distribution_type == pois:
     1308            raise NotImplementedError, "Inverted cumulative probability function for poisson distribution not defined"
     1309        elif self.distribution_type == geom:
     1310            raise NotImplementedError, "Inverted cumulative probability function for geometric distribution not defined"
     1311        elif self.distribution_type == nbinom:
     1312            raise NotImplementedError, "Inverted cumulative probability function for negative binomial distribution not defined"
     1313        elif self.distribution_type == hyper:
     1314            raise NotImplementedError, "Inverted cumulative probability function for hypergeometric distribution not defined"
     1315        else:
     1316            raise TypeError, "Probability distribution not supported"
    8261317 
    8271318    def plot(self, *args, **kwds):
    8281319        """
     
    8351326            sage: T = RealDistribution('uniform', [0, 2])
    8361327            sage: P = T.plot()
    8371328        """
    838 
    839         return sage.plot.plot.plot(self.distribution_function, *args, **kwds)
     1329        if self.distribution_type == binom:
     1330            if len(args) == 0:
     1331                n1 = 0
     1332                n2 = int(self.parameters[1])
     1333            elif len(args) == 1:
     1334                n1 = args[0]
     1335                n2 = int(self.parameters[1])
     1336            else:
     1337                n1 = args[0]
     1338                n2 = args[1]
     1339        elif self.distribution_type == pois or self.distribution_type == geom or self.distribution_type == nbinom or self.distribution_type == hyper:
     1340            if len(args) < 2:
     1341                n1 = 0
     1342                n2 = 20
     1343            else:
     1344                n1 = args[0]
     1345                n2 = args[1]
     1346        else:
     1347            return sage.plot.plot.plot(self.distribution_function, *args, **kwds)
     1348           
     1349        L = []
     1350        for i in range (n1,n2):
     1351            L.append((i,0))
     1352            L.append((i,self.distribution_function(i)))
     1353            L.append((i,0))
     1354        return sage.plot.line.line(L, **kwds)
    8401355 
    8411356cdef class GeneralDiscreteDistribution(ProbabilityDistribution):
    8421357    """