-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctions.py
More file actions
23 lines (19 loc) · 921 Bytes
/
Functions.py
File metadata and controls
23 lines (19 loc) · 921 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Function:
#Defines a function, and defined functions to call it on different points.
def __init__(self, func, func_g, name):
#Initialises the function with a function, its gradient and a name
self.func = func
self.func_d = func_g
self.name = name
def __call__(self, vector):
#When calling the function, it evaluates the function at a point. EG func(x)
return self.func(vector)
def evaluate_gradient(self, vector):
#Evaluates the gradient of the function at a point. E.G. func.evaluate_gradient(x)
return self.func_d(vector)
class Constraint(Function):
#A child class of Function, that defines a constraint function
def __init__(self, func, func_g, name, equality=False):
super().__init__(func, func_g, name)
#Defines if the constraint is an inequality or equality constraint
self.equality = equality