-
Notifications
You must be signed in to change notification settings - Fork 0
/
optimization_task.py
86 lines (67 loc) · 2.29 KB
/
optimization_task.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
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
from abc import ABC, abstractmethod
import numpy as np
class OptimizationTask(ABC):
"""
Abstract base class for optimization tasks.
This class defines the interface for optimization tasks, including methods
for calculating the Jacobian, residuals, and handling parameters.
"""
def __init__(self):
"""
Initialize an instance of OptimizationTask.
This method serves as a placeholder for any common initialization logic
required by subclasses.
Parameters:
None
"""
pass
@abstractmethod
def jacobian(self) -> np.ndarray:
"""
Abstract method to calculate the Jacobian matrix for the optimization
task.
Subclasses must implement this method to provide the Jacobian matrix
specific to their optimization problem.
Returns:
np.ndarray: The Jacobian matrix.
"""
pass
@abstractmethod
def residuals(self, parameters: np.ndarray) -> np.ndarray:
"""
Abstract method to calculate residuals for the optimization task.
Subclasses must implement this method to provide residuals specific to
their optimization problem.
Parameters:
parameters (np.ndarray): Current parameters for the optimization
task.
Returns:
np.ndarray: Residuals for each data point.
"""
pass
@property
@abstractmethod
def parameters(self) -> np.ndarray:
"""
Abstract property to get the current parameters for the optimization
task.
Subclasses must implement this property to provide access to the
current parameters.
Returns:
np.ndarray: Current parameters.
"""
pass
@parameters.setter
@abstractmethod
def parameters(self, parameters: np.ndarray):
"""
Abstract property to set the current parameters for the optimization
task.
Subclasses must implement this property to allow setting new
parameters.
Parameters:
parameters (np.ndarray): New parameters for the optimization task.
Returns:
None
"""
pass