Skip to content

implement Sofomore.active(kernel) method #4

Open

Description

@nikohansen

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?

Activity

  1. nikohansen commented on Oct 27, 2021

    @nikohansen
    ContributorAuthor

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

  2. nikohansen commented on Oct 27, 2021

    @nikohansen
    ContributorAuthor

    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']
  3. cheikhToure commented on Oct 28, 2021

    @cheikhToure
    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 !=.

  4. cheikhToure commented on Oct 28, 2021

    @cheikhToure
    Collaborator

    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.

  5. nikohansen commented on Oct 29, 2021

    @nikohansen
    ContributorAuthor

    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.

  6. self-assigned this
    on Jul 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestquestionFurther information is requested

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions