-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathnodes-activations.h
More file actions
57 lines (48 loc) · 2.66 KB
/
nodes-activations.h
File metadata and controls
57 lines (48 loc) · 2.66 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef DYNET_NODES_ACTIVATIONS_H_
#define DYNET_NODES_ACTIVATIONS_H_
#include "dynet/dynet.h"
#include "dynet/nodes-macros.h"
namespace dynet {
// y = max(0,x)
struct Rectify : public Node {
explicit Rectify(const std::initializer_list<VariableIndex>& a) : Node(a) {}
virtual bool supports_multibatch() const override { return true; }
virtual int autobatch_sig(const ComputationGraph &cg, SigMap &sm) const override { Sig s(nt::rectify); return sm.get_idx(s); }
virtual std::vector<int> autobatch_concat(const ComputationGraph & cg) const override { return std::vector<int>(1, 1); }
DYNET_NODE_DEFINE_DEV_IMPL()
};
// y = \sigma(x_1)
struct LogisticSigmoid : public Node {
explicit LogisticSigmoid(const std::initializer_list<VariableIndex>& a) : Node(a) {}
virtual bool supports_multibatch() const override { return true; }
virtual int autobatch_sig(const ComputationGraph &cg, SigMap &sm) const override { Sig s(nt::logistic); return sm.get_idx(s); }
virtual std::vector<int> autobatch_concat(const ComputationGraph & cg) const override { return std::vector<int>(1, 1); }
DYNET_NODE_DEFINE_DEV_IMPL()
};
// y = x / (1 + |x|)
struct SoftSign : public Node {
explicit SoftSign(const std::initializer_list<VariableIndex>& a) : Node(a) {}
virtual bool supports_multibatch() const override { return true; }
virtual int autobatch_sig(const ComputationGraph &cg, SigMap &sm) const override { Sig s(nt::softsign); return sm.get_idx(s); }
virtual std::vector<int> autobatch_concat(const ComputationGraph & cg) const override { return std::vector<int>(1, 1); }
DYNET_NODE_DEFINE_DEV_IMPL()
};
// y = erf x_1
struct Erf : public Node {
explicit Erf(const std::initializer_list<VariableIndex>& a) : Node(a) {}
virtual bool supports_multibatch() const override { return true; }
virtual int autobatch_sig(const ComputationGraph &cg, SigMap &sm) const override { Sig s(nt::erf); return sm.get_idx(s); }
virtual std::vector<int> autobatch_concat(const ComputationGraph & cg) const override { return std::vector<int>(1, 1); }
DYNET_NODE_DEFINE_DEV_IMPL()
};
// y = ELU(0,x)
struct ExponentialLinearUnit : public Node {
explicit ExponentialLinearUnit(const std::initializer_list<VariableIndex>& a, float lambda=1.f, float alpha=1.f) : Node(a), lambda(lambda), alpha(alpha) {}
virtual bool supports_multibatch() const override { return true; }
virtual int autobatch_sig(const ComputationGraph &cg, SigMap &sm) const override { Sig s(nt::rectify); return sm.get_idx(s); }
virtual std::vector<int> autobatch_concat(const ComputationGraph & cg) const override { return std::vector<int>(1, 1); }
DYNET_NODE_DEFINE_DEV_IMPL()
float lambda, alpha;
};
} // namespace dynet
#endif