thouska / spotpy

A Statistical Parameter Optimization Tool
https://spotpy.readthedocs.io/en/latest/
MIT License
250 stars 150 forks source link

Discrete Parameters #186

Open philippkraft opened 6 years ago

philippkraft commented 6 years ago

All parameters sample from a continuous distribution. But not all parameters are on a cardinal scale. To sample from nominal and ordinal scales we should provide a discrete parameter.

This is needed to keep the full functionality for the DDS algorithm #185 but would also open the door for other samplers that respect the parameter distribution.

thouska commented 5 years ago

This has been picked up by @bees4ever at #195. Each parameters can be set now with a new flag which can be set to treat them as integer values. This is used so far only for DDS. Needs still to be implemented for all other algorithms.

philippkraft commented 4 years ago

I would prefer a clear new parameter class for discrete parameters, as discrete distributions are not the same as continuous distributions. But it would not work for algorithms that do not respect the distribution of the parameter. Something like this:

class UniformDiscrete(Base):
    """
    A parameter sampling from a discrete range of integer numbers.

    .. warning:: This sampler should be unproblematic for undirected samplers (eg. mc and lhs),
                 but the behaviour for directed samplers like sceua, dds, rope is not explored.

    """
    __rndargs__ = 'low', 'high'

    @staticmethod
    def sample(low, high, size):
        return np.float(rnd.randint(low, high, size))

    def __init__(self, *args, **kwargs):
        """
        :name: Name of the parameter
        :low: Lower limit of the parameter
        :high: Upper limit, should be larger than `left`.
        :step:     (optional) number for step size required for some algorithms,
                eg. mcmc need a parameter of the variance for the next step
                default is quantile(0.5) - quantile(0.4) of
        :optguess: (optional) number for start point of parameter
                default is median of rndfunc(*rndargs, size=1000)
                rndfunc(*rndargs, size=1000)
        """

        super(UniformDiscrete, self).__init__(rnd.randint, 'randint', *args, **kwargs)