Neighborhood

Neighborhood objets are Addons defining what a neighborhood is for a Variables via Variable Addon, or a Search space via Search space Addon.

from zellij.core import *
from zellij.core import MockModel
from zellij.utils.converters import *

lf = Loss()(MockModel())
sp = MixedSearchspace(ArrayVar(
                        IntVar("a",-5,5, neighborhood=IntMinmax(2)),
                        FloatVar("b",-5,5, neighborhood=FloatInterval(1.5)),
                        CatVar("b",['f1','f2','f3'], neighborhood=CatInterval()),
                        neighborhood=ArrayInterval()),
                        lf,
                        neighborhood=Intervals())
point = sp.random_point(1)
print(point)
neighbors = sp.to_continuous.convert([[-5,-5],[0,0],point,[5,5]])
print(float_points)
int_points = sp.to_continuous.reverse(float_points)
print(int_points)

Intervals

Intervals Neighborhood are based on drawing a random value between x \pm neighborhood.

class Intervals(search_space=None, neighborhood=None)[source]

Bases: zellij.core.addons.Neighborhood

Search space Addon, used to determine the neighbor of a given point. All Variables of the Search space must have the neighbor addon implemented.

Parameters
neighborhood
property neighborhood
property target
class ArrayInterval(variable=None, neighborhood=None)[source]

Bases: zellij.core.addons.VarNeighborhood

Search space Addon, used to determine the neighbor of an ArrayVar. neighbor kwarg must be implemented for all Variables of the ArrayVar.

Parameters
  • variable (ArrayVar, default=None) – Targeted Variables.

  • neighborhood (list, default=None) – Not yet implemented

neighborhood
property neighborhood
property target
class FloatInterval(neighborhood, variable=None)[source]

Bases: zellij.core.addons.VarNeighborhood

Variable Addon, used to determine the neighbor of a FloatVar. Draw a random point in x \pm neighborhood.

Parameters
  • variable (FloatVar, default=None) – Targeted Variables.

  • neighborhood (float, default=None) – x \pm neighborhood

neighborhood
property neighborhood
property target
class IntInterval(neighborhood, variable=None)[source]

Bases: zellij.core.addons.VarNeighborhood

Variable Addon, used to determine the neighbor of an IntVar. Draw a random point in x \pm neighborhood.

Parameters
  • variable (IntVar, default=None) – Targeted Variables.

  • neighborhood (int, default=None) – x \pm neighborhood

neighborhood
property neighborhood
property target
class CatInterval(variable=None, neighborhood=None)[source]

Bases: zellij.core.addons.VarNeighborhood

Variable Addon, used to determine the neighbor of a CatVar. Draw a random feature in CatVar.

Parameters
  • variable (FlaotVar, default=None) – Targeted Variables.

  • neighborhood (int, default=None) – Undefined, for CatVar it draws a random feature.

neighborhood
property neighborhood
property target
class ConstantInterval(variable=None, neighborhood=None)[source]

Bases: zellij.core.addons.VarNeighborhood

Variable Addon, used to determine the neighbor of a Constant. Do nothing. Return the constant.

Parameters
  • variable (Constant, default=None) – Targeted Variables.

  • neighborhood (int, default=None) – Not implemented.

neighborhood
property neighborhood
property target