-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
36 lines (27 loc) · 1003 Bytes
/
main.py
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
import os
import logging
import conjugatedescent
import coordinatedescent
import gradientdescent
logging.basicConfig(level=logging.DEBUG)
log = logging.getLogger(__name__)
def _choose_operation(requested_operation: str):
if requested_operation == 'CONJUGATE_GRADIENT':
optimizer = conjugatedescent.ConjugateGradientDescent()
elif requested_operation == 'COORDINATE_DESCENT':
optimizer = coordinatedescent.CoordinateDescent()
else:
optimizer = gradientdescent.GradientDescent()
log.debug(f'Done activating {type(optimizer).__name__} optimizer for algorithm={requested_operation}')
return optimizer
def main():
optimizer = _choose_operation(os.getenv('ALGORITHM'))
minimiser, min_value, gradient = optimizer.execute()
result = f'''
=====Function F(X1, X2) has a local minimum at {minimiser}=========
- Min Value = {min_value}
- Slope = {gradient}
'''
print(result.strip())
if __name__ == '__main__':
main()