diff options
author | Jonghoon Jin <jhjin0@gmail.com> | 2015-10-01 00:06:22 +0300 |
---|---|---|
committer | Jonghoon Jin <jhjin0@gmail.com> | 2015-10-05 21:29:40 +0300 |
commit | 7e4a9fa348b8a65f28e3b20415b3c7286d1d90e4 (patch) | |
tree | 52d108f406a8cb9407fc7dc184ec8b7bb34fc15f /HardTanh.lua | |
parent | bcea7ce973898ec2b46a9ea0d52504aeabd48e5a (diff) |
Use custom range in HardTanh and mask it as Clamp
allows HardTanh to use a custom interval for linear region when min/max values
are specified in declaration. Thus its implementation can be shared with new
Clamp function.
Diffstat (limited to 'HardTanh.lua')
-rw-r--r-- | HardTanh.lua | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/HardTanh.lua b/HardTanh.lua index 3391479..555e6fb 100644 --- a/HardTanh.lua +++ b/HardTanh.lua @@ -1,6 +1,15 @@ -local HardTanh = torch.class('nn.HardTanh', 'nn.Module') +local HardTanh, parent = torch.class('nn.HardTanh', 'nn.Module') + +function HardTanh:__init(min_value, max_value) + parent.__init(self) + self.min_val = min_value or -1 + self.max_val = max_value or 1 + assert(self.max_val>self.min_val, 'max_value must be larger than min_value') +end function HardTanh:updateOutput(input) + self.min_val = self.min_val or -1 + self.max_val = self.max_val or 1 return input.nn.HardTanh_updateOutput(self, input) end |