LeakyClamp¶
- class pfhedge.nn.LeakyClamp(clamped_slope=0.01, inverted_output='mean')[source]¶
Leakily clamp all elements in
input
into the range .The bounds
and can be tensors.If
:If
:See also
- Parameters
clamped_slope (float, default=0.01) – Controls the slope in the clampled regions.
inverted_output ({'mean', ''max'}, default='mean') – Controls the output when
. ‘max’ is consistent withtorch.clamp()
.
- Shape:
input:
where means any number of additional dimensions.min:
or any size broadcastable toinput
.max:
or any size broadcastable toinput
.output:
, same shape as the input.
Examples
>>> import torch >>> from pfhedge.nn import LeakyClamp >>> m = LeakyClamp() >>> input = torch.linspace(-2, 12, 15) * 0.1 >>> input tensor([-0.2000, -0.1000, 0.0000, 0.1000, 0.2000, 0.3000, 0.4000, 0.5000, 0.6000, 0.7000, 0.8000, 0.9000, 1.0000, 1.1000, 1.2000]) >>> m(input, 0.0, 1.0) tensor([-2.0000e-03, -1.0000e-03, 0.0000e+00, 1.0000e-01, 2.0000e-01, 3.0000e-01, 4.0000e-01, 5.0000e-01, 6.0000e-01, 7.0000e-01, 8.0000e-01, 9.0000e-01, 1.0000e+00, 1.0010e+00, 1.0020e+00])
- forward(input, min=None, max=None)[source]¶
Clamp all elements in
input
into the range .- Parameters
input (torch.Tensor) – The input tensor.
min (torch.Tensor, optional) – Lower-bound of the range to be clamped to.
max (torch.Tensor, optional) – Upper-bound of the range to be clamped to.
- Returns
torch.Tensor