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

implement Sofomore.active(kernel) method #4

Open
nikohansen opened this issue Oct 27, 2021 · 5 comments
Open

implement Sofomore.active(kernel) method #4

nikohansen opened this issue Oct 27, 2021 · 5 comments
Assignees
Labels
enhancement New feature or request question Further information is requested

Comments

@nikohansen
Copy link
Contributor

The Sofomore.activate method should be implemented, in order to be able to refine a kernel.

  • we probably want to call, maybe optionally, kernel._stopdict.clear() during activation
  • @cheikhToure I don't understand the tentative code (see above link)
         new_list = [callback for callback in self.kernels[ikernel].opts['termination_callback']\
                 if callback(kernel) == 'kernel turned off']
         kernel.opts['termination_callback'] = new_list
    Was the == mean to read != such that the turned off termination is removed?
@nikohansen nikohansen added enhancement New feature or request question Further information is requested labels Oct 27, 2021
@nikohansen
Copy link
Contributor Author

nikohansen commented Oct 27, 2021

Another question: why don't we activate the kernel unconditionally?

@nikohansen
Copy link
Contributor Author

nikohansen commented Oct 27, 2021

Tentative code:

    def activate(self, kernel, reset_termination=True, reset_stagnation=False):
        if reset_termination:
            kernel._stopdict.clear()
        if reset_stagnation:
            kernel.fit.histbest.clear()  # reset opts['tolstagnation']
            kernel.fit.histmedian.clear()  # ditto
        ikernel = self.kernels.index(kernel)  # kernel must be in self.kernels
        if ikernel in self._active_indices:
            return
        self._active_indices += [ikernel]
        # remove "turned off" status
        if kernel.opts['termination_callback']:
            kernel.opts['termination_callback'] = [c for c in kernel.opts['termination_callback']
                                                   if c(kernel) != 'kernel turned off']

@cheikhToure
Copy link
Collaborator

The Sofomore.activate method should be implemented, in order to be able to refine a kernel.

  • we probably want to call, maybe optionally, kernel._stopdict.clear() during activation

  • @cheikhToure I don't understand the tentative code (see above link)

         new_list = [callback for callback in self.kernels[ikernel].opts['termination_callback']\
                 if callback(kernel) == 'kernel turned off']
         kernel.opts['termination_callback'] = new_list

    Was the == mean to read != such that the turned off termination is removed?

Yes it was meant to read !=.

@cheikhToure
Copy link
Collaborator

cheikhToure commented Oct 28, 2021

Another question: why don't we activate the kernel unconditionally?

The tentative code was meant to activate a kernel that we inactivated beforehand, mainly for budget allocation.

When we do:

import cma
es = cma.CMAEvolutionStrategy(10 * [1], 0.2)
es.optimize(cma.ff.sphere)

The optimization is done in ~ 2000 function evaluations with a tolfun stopping criterion.
If we then do

es.optimize(lambda x: cma.ff.sphere(x - 1))

The step-size of es increases for 1000 more function evaluations before decreasing for another 2000 function evaluations and we hit a tolstagnation criterion.

The idea was to avoid this adaptive phase that costs 1000 function evaluations when activating a kernel that we did not turn off on purpose (mainly for budget allocation) during the optimization of a changing fitness.

@nikohansen
Copy link
Contributor Author

nikohansen commented Oct 29, 2021

Maybe we want a method that checks for deactivation status, like

    def inactivated(self, kernel):
        """return `True` if kernel was deactivated with `Sofomore.inactivate`, else `False`
        """
        try:
            for c in kernel.opts['termination_callback']:
                if c(kernel) == 'kernel turned off':
                    return True
        except TypeError: # termination callback options were not iterable
            pass
        return False
# or:
    def inactivated(self, kernel):
        s = kernel.stop(check=False)
        for k in s:
            if k == 'callback' and 'kernel turned off' in s[k]:
                return True
        return False

which would allow to write

    moes.activate(kernel) if moes.inactivated(kernel) else None

to activate the kernel only when it was inactivated before.

@nikohansen nikohansen self-assigned this Jul 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants