lale/search/lale_grid_search_cv.py
def SearchSpaceNumberToGSValues(
    key: str, hp: SearchSpaceNumber, num_samples: Optional[int] = None
) -> List[GSValue]:
    """Returns either a list of values intended to be sampled uniformly"""
    samples: int
    if num_samples is None:
        samples = DEFAULT_SAMPLES_PER_DISTRIBUTION
    else:
        samples = num_samples

    # Add preliminary support for PGO
    if hp.pgo is not None:
        ret = list(hp.pgo.samples(samples))
        return ret

    # if we are not doing PGO
    dist = "uniform"
    if hp.distribution:
        dist = hp.distribution
    if hp.maximum is None:
        raise ValueError(
            f"maximum not specified for a number with distribution {dist} for {key}"
        )
    max = hp.getInclusiveMax()
    assert max is not None
    if hp.minimum is None:
        raise ValueError(
            f"minimum not specified for a number with distribution {dist} for {key}"
        )
    min = hp.getInclusiveMin()
    assert min is not None

    dt: np.dtype
    if hp.discrete:
        dt = np.dtype(int)
    else:
        dt = np.dtype(float)

    default = hp.default()
    if default is not None:
        # always use the default as one of the samples
        # TODO: ensure that the default is valid according to the schema
        if samples <= 1:
            return [default]
        samples = samples - 1
    if dist == "uniform" or dist == "integer":
        ret = np.linspace(min, max, num=samples, dtype=dt).tolist()
    elif dist == "loguniform":
        ret = np.logspace(min, max, num=samples, dtype=dt).tolist()
    else:
        raise ValueError(f"unknown/unsupported distribution {dist} for {key}")
    if default is not None:
        ret.append(default)
    return ret
Returns either a list of values intended to be sampled uniformly
Returns either a list of values intended to be sampled uniformly
Returns either a list of values intended to be sampled uniformly
def SearchSpaceNumberToGSValues(
    key: str, hp: SearchSpaceNumber, num_samples: Optional[int] = None
) -> List[GSValue]:
    samples: int
    if num_samples is None:
        samples = DEFAULT_SAMPLES_PER_DISTRIBUTION
    else:
        samples = num_samples
    if hp.pgo is not None:
        ret = list(hp.pgo.samples(samples))
        return ret
    dist = "uniform"
    if hp.distribution:
        dist = hp.distribution
    if hp.maximum is None:
        raise ValueError(
            f"maximum not specified for a number with distribution {dist} for {key}"
        )
    max = hp.getInclusiveMax()
    assert max is not None
    if hp.minimum is None:
        raise ValueError(
            f"minimum not specified for a number with distribution {dist} for {key}"
        )
    min = hp.getInclusiveMin()
    assert min is not None
    dt: np.dtype
    if hp.discrete:
        dt = np.dtype(int)
    else:
        dt = np.dtype(float)
    default = hp.default()
    if default is not None:
        if samples <= 1:
            return [default]
        samples = samples - 1
    if dist == "uniform" or dist == "integer":
        ret = np.linspace(min, max, num=samples, dtype=dt).tolist()
    elif dist == "loguniform":
        ret = np.logspace(min, max, num=samples, dtype=dt).tolist()
    else:
        raise ValueError(f"unknown/unsupported distribution {dist} for {key}")
    if default is not None:
        ret.append(default)
    return ret
def SearchSpaceNumberToGSValues ( key : str , hp : SearchSpaceNumber , num_samples : Optional [ int ] = None ) -> List [ GSValue ] : samples : int if num_samples is None : samples = DEFAULT_SAMPLES_PER_DISTRIBUTION else : samples = num_samples if hp . pgo is not None : ret = list ( hp . pgo . samples ( samples ) ) return ret dist = "uniform" if hp . distribution : dist = hp . distribution if hp . maximum is None : raise ValueError ( f"maximum not specified for a number with distribution {dist} for {key}" ) max = hp . getInclusiveMax ( ) assert max is not None if hp . minimum is None : raise ValueError ( f"minimum not specified for a number with distribution {dist} for {key}" ) min = hp . getInclusiveMin ( ) assert min is not None dt : np . dtype if hp . discrete : dt = np . dtype ( int ) else : dt = np . dtype ( float ) default = hp . default ( ) if default is not None : if samples <= 1 : return [ default ] samples = samples - 1 if dist == "uniform" or dist == "integer" : ret = np . linspace ( min , max , num = samples , dtype = dt ) . tolist ( ) elif dist == "loguniform" : ret = np . logspace ( min , max , num = samples , dtype = dt ) . tolist ( ) else : raise ValueError ( f"unknown/unsupported distribution {dist} for {key}" ) if default is not None : ret . append ( default ) return ret
Returns either a list of values intended to be sampled uniformly
Returns either a list of values intended to be sampled uniformly
"""Returns either a list of values intended to be sampled uniformly""" # Add preliminary support for PGO # if we are not doing PGO # always use the default as one of the samples # TODO: ensure that the default is valid according to the schema
key
str
hp
SearchSpaceNumber
num_samples
Optional[int]