-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClamp.m
40 lines (28 loc) · 1011 Bytes
/
Clamp.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
classdef Clamp < SingleParentNode
properties
bounds(2, 1) double
end
methods
function obj = Clamp(parent, bounds, varargin)
obj = obj@SingleParentNode(parent, varargin{:});
obj.bounds = bounds;
end
end
methods (Access = protected)
function value = evalElement(obj)
value = min(max(obj.parents.evalImpl(), obj.bounds(1)), obj.bounds(2));
end
function computeScaleElement(obj)
obj.scale = min(max(obj.parents.scale, obj.bounds(1)), obj.bounds(2));
end
function height = getCompiledHeight(~)
height = 1;
end
function [headObj, tailObj] = replaceNonlinearElement(obj)
m = mean(obj.bounds);
d = diff(obj.bounds) / 2;
tailObj = Linear(obj.parents, [-m/d 1/d]);
headObj = Linear(Tanh(tailObj), [m d]);
end
end
end