gpytorch.Module¶

class gpytorch.Module[source]
initialize(**kwargs)[source]

Set a value for a parameter

kwargs: (param_name, value) - parameter to initialize. Can also initialize recursively by passing in the full name of a parameter. For example if model has attribute model.likelihood, we can initialize the noise with either model.initialize(**{‘likelihood.noise’: 0.1}) or model.likelihood.initialize(noise=0.1). The former method would allow users to more easily store the initialization values as one object.

Value can take the form of a tensor, a float, or an int

named_added_loss_terms()[source]

Returns an iterator over module variational strategies, yielding both the name of the variational strategy as well as the strategy itself.

Yields:
(string, VariationalStrategy): Tuple containing the name of the
strategy and the strategy
named_priors(memo=None, prefix='')[source]

Returns an iterator over the module’s priors, yielding the name of the prior, the prior, the associated parameter names, and the transformation callable.

Yields:
(string, Prior, tuple((Parameter, callable)), callable): Tuple containing:
• the name of the prior
• the prior
• a tuple of tuples (param, transform), one for each of the parameters associated with the prior
• the prior’s transform to be called on the parameters
register_parameter(name, parameter, prior=None)[source]

Adds a parameter to the module. The parameter can be accessed as an attribute using the given name.

Args:
name (str):
The name of the parameter
parameter (torch.nn.Parameter):
The parameter
register_prior(name, prior, param_or_closure, setting_closure=None)[source]

Adds a prior to the module. The prior can be accessed as an attribute using the given name.

Args:
name (str):
The name of the prior
prior (Prior):
The prior to be registered
param_or_closure (string or callable):
Either the name of the parameter, or a closure (which upon calling evalutes a function on one or more parameters): single parameter without a transform: .register_prior(“foo_prior”, foo_prior, “foo_param”) transform a single parameter (e.g. put a log-Normal prior on it): .register_prior(“foo_prior”, NormalPrior(0, 1), lambda: torch.log(self.foo_param)) function of multiple parameters: .register_prior(“foo2_prior”, foo2_prior, lambda: f(self.param1, self.param2)))
setting_closure (callable, optional):
A function taking in a tensor in (transformed) parameter space and initializing the internal parameter representation to the proper value by applying the inverse transform. Enables setting parametres directly in the transformed space, as well as sampling parameter values from priors (see sample_from_prior)
sample_from_prior`(prior_name)[source]

Sample parameter values from prior. Modifies the module’s parameters in-place.