设置¶
示例用法
# Simple getting and setting.
print(pyro.settings.get())  # print all settings
print(pyro.settings.get("cholesky_relative_jitter"))  # print one
pyro.settings.set(cholesky_relative_jitter=0.5)  # set one
pyro.settings.set(**my_settings)  # set many
# Use as a contextmanager.
with pyro.settings.context(cholesky_relative_jitter=0.5):
    my_function()
# Use as a decorator.
fn = pyro.settings.context(cholesky_relative_jitter=0.5)(my_function)
fn()
# Register a new setting.
pyro.settings.register(
    "binomial_approx_sample_thresh",  # alias
    "pyro.distributions.torch",       # module
    "Binomial.approx_sample_thresh",  # deep name
)
# Register a new setting on a user-provided validator.
@pyro.settings.register(
    "binomial_approx_sample_thresh",  # alias
    "pyro.distributions.torch",       # module
    "Binomial.approx_sample_thresh",  # deep name
)
def validate_thresh(thresh):  # called each time setting is set
    assert isinstance(thresh, float)
    assert thresh > 0
默认设置¶
- binomial_approx_log_prob_tol = 0.0 
- binomial_approx_sample_thresh = inf 
- cholesky_relative_jitter = 4.0 
- module_local_params = False 
- validate_distributions_pyro = True 
- validate_distributions_torch = True 
- validate_infer = True 
- validate_poutine = True 
设置接口¶
- context(**kwargs) Iterator[None][source]¶
- 用于临时覆盖一个或多个设置的上下文管理器。这也可以作为装饰器使用。 - 参数
- **kwargs – alias=value 对。 
 
- register(alias: str, modulename: str, deepname: str, validator: Optional[Callable] = None) Callable[source]¶
- 注册一个全局设置。 - 这应该在定义设置的模块中声明。 - 这可以用作声明 - settings.register("my_setting", __name__, "MY_SETTING") - 或用作用户定义验证器函数的装饰器 - @settings.register("my_setting", __name__, "MY_SETTING") def _validate_my_setting(value): assert isinstance(value, float) assert 0 < value