Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added sanitize optional parameter to minimize() #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion EDAspy/optimization/eda.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,14 @@ def export_settings(self) -> dict:
"parallelize": self.parallelize
}

def minimize(self, cost_function: callable, output_runtime: bool = True, *args, **kwargs) -> EdaResult:
def minimize(self, cost_function: callable, output_runtime: bool = True, sanitize: callable = None, *args, **kwargs) -> EdaResult:
"""
Minimize function to execute the EDA optimization. By default, the optimizer is designed to minimize a cost
function; if maximization is desired, just add a minus sign to your cost function.

:param cost_function: cost function to be optimized and accepts an array as argument.
:param output_runtime: true if information during runtime is desired.
:param sanitize: run before updating model, can be used to adjust the representation of the generation
:return: EdaResult object with results and information.
:rtype: EdaResult
"""
Expand All @@ -166,6 +167,8 @@ def minimize(self, cost_function: callable, output_runtime: bool = True, *args,

for _ in range(self.max_iter - 1):
self._truncation()
if sanitize is not None:
sanitize(self.generation)
self._update_pm()

self._new_generation()
Expand Down