-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunction.h
176 lines (142 loc) · 3.68 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
#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;
bool processed = 0;
Function();
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 double doBackward(int) = 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();
double doBackward(int);
};
/*
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();
double doBackward(int);
};
/*
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();
double doBackward(int);
};
class Subtraction : public Function{
public:
Subtraction(int _id, string _name="");
void doForward();
double doBackward(int);
};
class Division : public Function{
public:
Division(int _id, string _name="");
void doForward();
double doBackward(int);
};
class Cosine : public Function{
public:
Cosine(int _id, string _name="");
void doForward();
double doBackward(int);
};
class Identity : public Function{
public:
Identity(int _id, string _name="");
void doForward();
double doBackward(int);
};
class Tangent : public Function{
public:
Tangent(int _id, string _name="");
void doForward();
double doBackward(int);
};
class ArcCosine : public Function{
public:
ArcCosine(int _id, string _name="");
void doForward();
double doBackward(int);
};
class ArcSine : public Function{
public:
ArcSine(int _id, string _name="");
void doForward();
double doBackward(int);
};
class ArcTangent : public Function{
public:
ArcTangent(int _id, string _name="");
void doForward();
double doBackward(int);
};
class Exponential : public Function{
public:
Exponential(int _id, string _name="");
void doForward();
double doBackward(int);
};
class Log : public Function{
public:
Log(int _id, string _name="");
void doForward();
double doBackward(int);
};
class Log10 : public Function{
public:
Log10(int _id, string _name="");
void doForward();
double doBackward(int);
};
class Power : public Function{
public:
Power(int _id, string _name="");
void doForward();
double doBackward(int);
};
class Sqrt : public Function{
public:
Sqrt(int _id, string _name="");
void doForward();
double doBackward(int);
};
#endif // VARIABLE