-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathElementProcess.m
35 lines (32 loc) · 1.01 KB
/
ElementProcess.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
classdef ElementProcess < dagnn.ElementWise
properties
Scale = 1;
Shift = 0;
Power = 1;
end
methods
function outputs = forward(self, inputs, params)
% y = (Shitf + Scale * X) .^ Power
if self.Power == 1
outputs{1} = self.Shift + self.Scale * inputs{1};
else
outputs{1} = (self.Shift + self.Scale * inputs{1}) .^ self.Power;
end
end
function [derInputs, derParams] = backward(self, inputs, params, derOutputs)
% dy/dx = Scale * Power * (Shift + Scale * X) .^ (Power - 1)
if self.Power == 1
derInputs{1} = self.Scale .* derOutputs{1};
else
derInputs{1} = self.Scale .* self.Power .* (self.Shift + self.Scale * inputs{1}) .^ (self.Power - 1) .* derOutputs{1};
end
derParams = {};
end
function self = ElementProcess(varargin)
self.load(varargin);
if self.Power == 0 || self.Scale == 0
error('Error Setting')
end
end
end
end