pyzag.reparametrization

Helper methods for reparameterizing modules, for example to scale parameter values and gradients

class pyzag.reparametrization.RangeRescale(lb: Tensor | float, ub: Tensor | float, clamp: bool = True)

Bases: Module

Scale parameter within bounds

forward(X: Tensor) Tensor

Go from scaled to natural parameters

Parameters:

X (torch.tensor) – scaled parameter values

reverse(X: Tensor) Tensor

Go from natural to scaled parameter values

Parameters:

X (torch.tensor) – natural parameter values

forward_std_dev(X: Tensor) Tensor

Go from the standard deviation of a scaled normal to the actual standard deviation

Parameters:

X (torch.tensor) – scaled standard deviation

reverse_std_dev(X: Tensor) Tensor

Go from the standard deviation of the actual normal to the standard deviation of the scaled normal

Parameters:

X (torch.tensor) – natural standard deviation

class pyzag.reparametrization.Reparameterizer(map_dict: Mapping[str, RangeRescale], error_not_provided: bool = False)

Bases: object

Reparameterize a torch Module by adding the appropriate rescale function to each parameter

Parameters:

map_dict (dict mapping str to rescaler) – dictionary mapping the parameter name to the appropriate rescaler

Keyword Arguments:

error_not_provided (bool) – if True, error out if a rescaler is missing