-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wrote standalone tester for optimizer
- Loading branch information
1 parent
7285efe
commit 85df3b0
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from optimizer import Optimizer | ||
import numpy as np | ||
|
||
|
||
# Function to test the optimizer with | ||
def function(x): | ||
# Matyas function | ||
return 0.26 * (x[0] ** 2 + x[1] ** 2) - 0.48 * x[0] * x[1] | ||
|
||
|
||
# Initialize optimizer | ||
points = np.array([[1, 2]]) # Initial point | ||
optimization_params = {'u1': 1e-4, | ||
'u2': 0.5, | ||
'sigma': 1.5, | ||
'alpha': 1.0, | ||
'tau': 1e-3} | ||
optimizer = Optimizer(points[0], optimization_params) | ||
|
||
|
||
while not optimizer.optimization_terminated(): | ||
# Print status | ||
print(optimizer.get_optimiztion_status()) | ||
|
||
# Calculate error for current points | ||
error = [] | ||
for point in points: | ||
error.append(function(point)) | ||
error = np.array(error) | ||
|
||
# Pass points to optimizer | ||
points = optimizer.get_next_parameter_set(error) | ||
|
||
|
||
print('Optimization terminated with status: {}'.format(optimizer.get_optimiztion_status())) | ||
|