sample_from#
- ray.tune.sample_from(func: Callable[[Dict], Any])[source]#
Specify that tune should sample configuration values from this function.
Use
sample_fromto define conditional search spaces, where the value sampled for one parameter depends on the value sampled for another. The callable receives theconfigdict, which exposes the values already sampled for the trial.- Parameters:
func – A callable function to draw a sample from.
- Returns:
A
Functiondomain that samples values by callingfunc.
Example
>>> import numpy as np >>> from ray import tune >>> # Sample ``b`` from a range that depends on the value of ``a``. >>> param_space = { ... "a": tune.randint(5, 10), ... "b": tune.sample_from( ... lambda config: np.random.randint(0, config["a"]) ... ), ... }