コード例 #1
0
    def estimate_parametric(histo,
                            ident,
                            MinInfBound=0,
                            InfBoundStatus="Free"):
        """ Estimate a parametric discrete distribution (binomial,
        Poisson or negative binomial distribution with an additional shift
        parameter)

        :Parameters:
          * histo (histogram, mixture_data, convolution_data, compound_data),
          * ident ("BINOMIAL", "POISSON", "NEGATIVE_BINOMIAL", "UNIFORM")
          * MinInfBound (int): lower bound to the range of possible values (0 - default value - or 1).
          * InfBoundStatus (string): shifting or not of the distribution:
                                      "Free" (default value) or "Fixed". T

        :Usage:

        .. doctest::
            :options: +SKIP

            >>> estimate_parametric(histo, ident, MinInfBound=0, InfBoundStatus="Free")
            >>> Estimate(histo, "NB", MinInfBound=1, InfBoundStatus="Fixed")

        """

        error.CheckType([ident, MinInfBound, InfBoundStatus], [str, int, str])

        flag = bool(InfBoundStatus == "Free")

        try:
            ident_id = dist_type[ident]
        except KeyError:
            raise KeyError("Valid type are %s" % (str(dist_type.keys())))

        return histo.parametric_estimation(ident_id, MinInfBound, flag)
コード例 #2
0
    def estimate_parametric(histo, ident,
                            MinInfBound=0,
                            InfBoundStatus="Free"):
        """ Estimate a parametric discrete distribution (binomial,
        Poisson or negative binomial distribution with an additional shift
        parameter)

        :Parameters:
          * histo (histogram, mixture_data, convolution_data, compound_data),
          * ident ("BINOMIAL", "POISSON", "NEGATIVE_BINOMIAL", "UNIFORM")
          * MinInfBound (int): lower bound to the range of possible values (0 - default value - or 1).
          * InfBoundStatus (string): shifting or not of the distribution:
                                      "Free" (default value) or "Fixed". T

        :Usage:

        .. doctest::
            :options: +SKIP

            >>> estimate_parametric(histo, ident, MinInfBound=0, InfBoundStatus="Free")
            >>> Estimate(histo, "NB", MinInfBound=1, InfBoundStatus="Fixed")

        """

        error.CheckType([ident, MinInfBound, InfBoundStatus],
                        [str, int, str])

        flag = bool(InfBoundStatus == "Free")

        try:
            ident_id = dist_type[ident]
        except KeyError:
            raise KeyError("Valid type are %s" % (str(dist_type.keys())))


        return histo.parametric_estimation(ident_id, MinInfBound, flag)
コード例 #3
0
def Distribution(utype, *args):
    """
    Construction of a parametric discrete distribution (either binomial,
    Poisson, negative binomial or uniform) from the name and the parameters
    of the distribution or from an ASCII file.

    A supplementary shift parameter (argument inf_bound) is required with
    respect to the usual definitions of these discrete distributions.
    Constraints over parameters are given in the file syntax corresponding
    to the type distribution(cf. File Syntax).

    :Parameters:
      * `inf_bound` (int) : lower bound to the range of possible values
        (shift parameter),
      * `sup_bound` (int) : upper bound to the range of possible values \
      (only relevant for binomial or uniform distributions),
      * `param` (int, real) : parameter of either the Poisson distribution or \
      the negative binomial distribution.
      * `proba` (int, float) : probability of success \
      (only relevant for binomial or negative binomial distributions),
      * `file_name` (string).

      .. note:: the names of the parametric discrete distributions can be
        summarized by their first letters:

        * "B" ("BINOMIAL"),
        * "P" ("POISSON"),
        * "NB" ("NEGATIVE_BINOMIAL"),
        * "U" ("UNIFORM"),
        * "M" ("MULTINOMIAL"),


    :Returns:
        If the construction succeeds, an object of type distribution is
        returned, otherwise no object is returned.

    :Examples:

    .. doctest::
        :options: +SKIP

        >>> Distribution("BINOMIAL", inf_bound, sup_bound, proba)
        >>> Distribution("POISSON", inf_bound, param)
        >>> Distribution("NEGATIVE_BINOMIAL", inf_bound, param, proba)
        >>> Distribution("UNIFORM", inf_bound, sup_bound)
        >>> Distribution(file_name)

    .. seealso::
        :func:`~openalea.stat_tool.output.Save`,
        :func:`~openalea.stat_tool.estimate.Estimate`
        :func:`~openalea.stat_tool.simulate.Simulate`.
    """
    # Constructor from Filename or Histogram or parametricmodel
    if(len(args) == 0):
        error.CheckType([utype],
                        [[str, _DiscreteDistributionData, _DiscreteParametricModel]],
                        arg_id=[1])
        result =  _DiscreteParametricModel(utype)
    # from parameters
    if len(args)>0:
        error.CheckArgumentsLength(args, 1)
        if utype in ["B",  "BINOMIAL"]:
            result = Binomial(*args)
        elif utype in ["P", "POISSON"]:
            result = Poisson(*args)
        elif utype in ["M", "MULTINOMIAL"]:
            raise NotImplementedError("Multinomial not yet implemented")
        elif utype in ["NB", "NEGATIVE_BINOMIAL"]:
            result = NegativeBinomial(*args)
        elif utype in ["U", "UNIFORM"]:
            result = Uniform(*args)
        else:
            raise KeyError(" %s not found. Allowed keys are %s"
                           % (utype, distribution_identifier_type.keys()))

    return result