-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunction.h
228 lines (193 loc) · 4.91 KB
/
function.h
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#ifndef FUNCTION_H
#define FUNCTION_H
#include <vector>
#include <string>
#include "variable.h"
using namespace std;
/*
An abstract subclass of node class and represents the functions.
Due to the different functionality, we have variable and function classes.
*/
class Function : public Node{
public:
// represents the list of variables that are inputs of this function
vector<Variable *> inputs;
// represents the output variable of the function.
Variable * output = nullptr;
Function(); //default constructor
Function(int _id, string _name=""); // custom constructor
~Function(); // destructor
// adds given variable as an input of this function
void addInput(Variable *input);
// sets the output variable of the function
void setOutput(Variable *_output);
// following two functions are inherited features from node class
vector<Node *> getIncomings();
vector<Node *> getOutgoings();
// following two functions will be implemented by the subclasses of Function class
// performs forward pass and sets the value of output variable
virtual void doForward() = 0;
// performs backward pass and sets the derivative values of the input variables
virtual void doBackward() = 0;
};
/*
Subclass of function class that provides forward and backward pass functionalities
for multiplication
*/
class Multiplication : public Function{
public:
Multiplication(int _id, string _name="");
void doForward();
void doBackward();
};
/*
Subclass of function class that provides forward and backward pass functionalities
for addition
*/
class Addition : public Function{
public:
Addition(int _id, string _name="");
void doForward();
void doBackward();
};
/*
Subclass of function class that provides forward and backward pass functionalities
for subtraction
*/
class Subtraction : public Function{
public:
Subtraction(int _id, string _name="");
void doForward();
void doBackward();
};
/*
Subclass of function class that provides forward and backward pass functionalities
for division
*/
class Division : public Function{
public:
Division(int _id, string _name="");
void doForward();
void doBackward();
};
/*
Subclass of function class that provides forward and backward pass functionalities
for sine
*/
class Sine : public Function{
public:
Sine(int _id, string _name="");
void doForward();
void doBackward();
};
/*
Subclass of function class that provides forward and backward pass functionalities
for cosine
*/
class Cosine : public Function{
public:
Cosine(int _id, string _name="");
void doForward();
void doBackward();
};
/*
Subclass of function class that provides forward and backward pass functionalities
for identity
*/
class Identity : public Function{
public:
Identity(int _id, string _name="");
void doForward();
void doBackward();
};
/*
Subclass of function class that provides forward and backward pass functionalities
for tangent
*/
class Tangent : public Function{
public:
Tangent(int _id, string _name="");
void doForward();
void doBackward();
};
/*
Subclass of function class that provides forward and backward pass functionalities
for arccosine
*/
class ArcCosine : public Function{
public:
ArcCosine(int _id, string _name="");
void doForward();
void doBackward();
};
/*
Subclass of function class that provides forward and backward pass functionalities
for arcsine
*/
class ArcSine : public Function{
public:
ArcSine(int _id, string _name="");
void doForward();
void doBackward();
};
/*
Subclass of function class that provides forward and backward pass functionalities
for arctangent
*/
class ArcTangent : public Function{
public:
ArcTangent(int _id, string _name="");
void doForward();
void doBackward();
};
/*
Subclass of function class that provides forward and backward pass functionalities
for exponential
*/
class Exponential : public Function{
public:
Exponential(int _id, string _name="");
void doForward();
void doBackward();
};
/*
Subclass of function class that provides forward and backward pass functionalities
for log
*/
class Log : public Function{
public:
Log(int _id, string _name="");
void doForward();
void doBackward();
};
/*
Subclass of function class that provides forward and backward pass functionalities
for log10
*/
class Log10 : public Function{
public:
Log10(int _id, string _name="");
void doForward();
void doBackward();
};
/*
Subclass of function class that provides forward and backward pass functionalities
for power
*/
class Power : public Function{
public:
Power(int _id, string _name="");
void doForward();
void doBackward();
};
/*
Subclass of function class that provides forward and backward pass functionalities
for square root
*/
class Sqrt : public Function{
public:
Sqrt(int _id, string _name="");
void doForward();
void doBackward();
};
#endif // VARIABLE