plenoptic.regularize.penalize_range#
- plenoptic.regularize.penalize_range(img, allowed_range=(0.0, 1.0), **kwargs)[source]#
Calculate quadratic penalty on values outside of
allowed_range.Provides a ‘soft’ pixel-range regularization by imposing a quadratic penalty on any values outside the allowed_range. All values within the allowed_range have a penalty of 0.
To use as a
penalty_functionin synthesis methods,functools.partialmust be used to fix theallowed_range(see Examples).- Parameters:
- Return type:
- Returns:
penalty – Penalty for values outside range.
Examples
Initialize metamer with allowed range (0.2, 0.8):
>>> import plenoptic as po >>> img = po.data.einstein() >>> model = po.models.Gaussian(30).eval() >>> po.remove_grad(model) >>> # Make function penalizing values outside (0.2, 0.8) >>> def custom_range(x): ... penalty = po.regularize.penalize_range(x, allowed_range=(0.2, 0.8)) ... return penalty >>> met_default = po.Metamer(img, model) >>> met_custom = po.Metamer(img, model, penalty_function=custom_range) >>> # Compare the value of the penalties >>> met_default.penalty_function(img) tensor(0.) >>> met_custom.penalty_function(img) tensor(49.3881)