Skip to content

Documentation for FloatRange

Float range.

Class for easily creating an interval of numbers to be tested in the optimization process.

Source code in photonai/optimization/hyperparameters.py
class FloatRange(NumberRange):
    """Float range.

    Class for easily creating an interval of numbers
    to be tested in the optimization process.

    """
    def __init__(self, start: float, stop: float, range_type: str = 'linspace',
                 step: float = None, num: int = None, **kwargs):
        """
        Initialize the object.

        Parameters:
            start:
                The start value for generating the lower bound.
                The resulting interval includes the value.

            stop:
                The stop value for generating the upper bound.

                - if range_type == "range":
                    The end value is not included in the interval (see documentation of numpy.arange).
                - if range_type == "linspace"
                    The end value is included in the interval,
                    unless endpoint is set to False (see documentation of numpy.linspace).
                - if range_type == "logspace"
                    The end value is included in the interval,
                    unless endpoint is set to False (see documentation of numpy.logspace).
                - if range_type == "geomspace"
                    The end value is included in the interval,
                    unless endpoint is set to False (see documentation of numpy.logspace).

            range_type:
                Which method to use for generating the number interval.
                Possible options,

                - "range": numpy.arange is used to generate a list
                    of values separated by the same step width.
                - "linspace": numpy.linspace is used to generate a certain
                    number of values between start and stop.
                - "logspace": numpy.logspace is used to generate a logarithmically
                    distributed range of a certain length.
                - "geomspace": numpy.geomspace is used to generate numbers spaced
                    evenly on a log scale (geometric progression).

            step:
                If range_type == 'range', the spacing between values.

            num:
                If range_type == 'linspace', range_type == 'logspace', or range_type == 'geomspace',
                the number of samples to generate.

            kwargs:
                Further parameters that should be passed to the numpy function chosen with range_type.

        """
        super(FloatRange, self).__init__(start, stop, range_type, step, num, np.float64, **kwargs)

    def get_random_value(self, definite_list: bool = False):
        """
        Method for random search to get a random value based on the underlying domain.

        Parameters:
            definite_list:
                 Choice  between an element of a discrete list or a value within an interval.
                 As example, the num parameter would vanishes when this parameter
                 is set to False.

        """
        if definite_list:
            if not self.values:
                msg = "No values were set. Please use transform method."
                logger.error(msg)
                raise ValueError(msg)
            return random.choice(self.values)
        else:
            return random.uniform(self.start, self.stop)

__init__(self, start, stop, range_type='linspace', step=None, num=None, **kwargs) special

Initialize the object.

Parameters:

Name Type Description Default
start float

The start value for generating the lower bound. The resulting interval includes the value.

required
stop float

The stop value for generating the upper bound.

  • if range_type == "range": The end value is not included in the interval (see documentation of numpy.arange).
  • if range_type == "linspace" The end value is included in the interval, unless endpoint is set to False (see documentation of numpy.linspace).
  • if range_type == "logspace" The end value is included in the interval, unless endpoint is set to False (see documentation of numpy.logspace).
  • if range_type == "geomspace" The end value is included in the interval, unless endpoint is set to False (see documentation of numpy.logspace).
required
range_type str

Which method to use for generating the number interval. Possible options,

  • "range": numpy.arange is used to generate a list of values separated by the same step width.
  • "linspace": numpy.linspace is used to generate a certain number of values between start and stop.
  • "logspace": numpy.logspace is used to generate a logarithmically distributed range of a certain length.
  • "geomspace": numpy.geomspace is used to generate numbers spaced evenly on a log scale (geometric progression).
'linspace'
step float

If range_type == 'range', the spacing between values.

None
num int

If range_type == 'linspace', range_type == 'logspace', or range_type == 'geomspace', the number of samples to generate.

None
kwargs

Further parameters that should be passed to the numpy function chosen with range_type.

{}
Source code in photonai/optimization/hyperparameters.py
def __init__(self, start: float, stop: float, range_type: str = 'linspace',
             step: float = None, num: int = None, **kwargs):
    """
    Initialize the object.

    Parameters:
        start:
            The start value for generating the lower bound.
            The resulting interval includes the value.

        stop:
            The stop value for generating the upper bound.

            - if range_type == "range":
                The end value is not included in the interval (see documentation of numpy.arange).
            - if range_type == "linspace"
                The end value is included in the interval,
                unless endpoint is set to False (see documentation of numpy.linspace).
            - if range_type == "logspace"
                The end value is included in the interval,
                unless endpoint is set to False (see documentation of numpy.logspace).
            - if range_type == "geomspace"
                The end value is included in the interval,
                unless endpoint is set to False (see documentation of numpy.logspace).

        range_type:
            Which method to use for generating the number interval.
            Possible options,

            - "range": numpy.arange is used to generate a list
                of values separated by the same step width.
            - "linspace": numpy.linspace is used to generate a certain
                number of values between start and stop.
            - "logspace": numpy.logspace is used to generate a logarithmically
                distributed range of a certain length.
            - "geomspace": numpy.geomspace is used to generate numbers spaced
                evenly on a log scale (geometric progression).

        step:
            If range_type == 'range', the spacing between values.

        num:
            If range_type == 'linspace', range_type == 'logspace', or range_type == 'geomspace',
            the number of samples to generate.

        kwargs:
            Further parameters that should be passed to the numpy function chosen with range_type.

    """
    super(FloatRange, self).__init__(start, stop, range_type, step, num, np.float64, **kwargs)

get_random_value(self, definite_list=False)

Method for random search to get a random value based on the underlying domain.

Parameters:

Name Type Description Default
definite_list bool

Choice between an element of a discrete list or a value within an interval. As example, the num parameter would vanishes when this parameter is set to False.

False
Source code in photonai/optimization/hyperparameters.py
def get_random_value(self, definite_list: bool = False):
    """
    Method for random search to get a random value based on the underlying domain.

    Parameters:
        definite_list:
             Choice  between an element of a discrete list or a value within an interval.
             As example, the num parameter would vanishes when this parameter
             is set to False.

    """
    if definite_list:
        if not self.values:
            msg = "No values were set. Please use transform method."
            logger.error(msg)
            raise ValueError(msg)
        return random.choice(self.values)
    else:
        return random.uniform(self.start, self.stop)