Skip to content

Commit

Permalink
add SA tutorial, minor dixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MangaBoba committed Dec 19, 2023
1 parent 7a85bf0 commit a11645a
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ celerybeat.pid
# Environments
.env
.venv
.venv*
env/
venv/
ENV/
Expand Down
10 changes: 5 additions & 5 deletions cases/synthetic/circle/single_objective.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,19 @@ def __init__(self, domain: Domain, estimator: Estimator = None) -> None:

def _evaluate(self, ind: Structure) -> float:

num = 3
num_polys = len(ind.polygons)
loss = 0
for poly in ind.polygons:
area = self.domain.geometry.get_square(poly)
length = self.domain.geometry.get_length(poly)
if area == 0:
ratio = None
ratio = float('inf')
else:
ratio = 1 - 4 * np.pi * area / length ** 2

loss += ratio

loss = loss + 20 * abs(num_polys - num)
if num_polys > 1:
loss += 20 * abs(num_polys - 1)
return loss


Expand Down Expand Up @@ -61,7 +60,7 @@ def _evaluate(self, ind: Structure) -> float:

tuner_cfg = TunerParams(
tuner_type='optuna',
n_steps_tune=10,
n_steps_tune=25,
hyperopt_dist='uniform',
verbose=True,
timeout_minutes=60,
Expand Down Expand Up @@ -101,6 +100,7 @@ def _evaluate(self, ind: Structure) -> float:
'not_too_close_points',
],
extra=5,
estimation_n_jobs=-1,
n_jobs=-1,
log_dir='logs',
run_name='run_name',
Expand Down
1 change: 1 addition & 0 deletions docs/source/tutorials/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ Tutorials

optimisation
tuning
sa
39 changes: 39 additions & 0 deletions docs/source/tutorials/sa.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Sensitivity analysis
====================

SA
--

Use SA to run local search near an optimized structure.


.. code-block:: python
from gefest.core.configs.optimization_params import OptimizationParams
from gefest.core.geometry.datastructs.structure import Structure
from gefest.tools.tuners.sa import SensitivityAnalysis, report_viz
from matplotlib import pyplot as plt
structure: list[Structure] | Structure = ...
opt_params: OptimizationParams = ...
sa = SensitivityAnalysis([optimized_struct], opt_params)
res = sa.analysis()
# plot analysis history
report_viz(res)
# plot initial and best structure
sv = StructVizualizer()
sv.plot_structure(res[1][0])
sv.plot_structure(res[1][1])
plt.show(block=True)
# animated history of structures during SA
gm = GIFMaker()
for st in tqdm(res[1]):
gm.create_frame(st, {'sa': st.fitness})
gm.make_gif('sa individuals', 500)

0 comments on commit a11645a

Please sign in to comment.