class_docstr: Holds the param-space coordinates (X) and target values (Y)
  Allows for constant-time appends while ensuring no duplicates are added
  
  Example
  -------
  >>> def target_func(p1, p2):
  >>>     return p1 + p2
  >>> pbounds = {'p1': (0, 1), 'p2': (1, 100)}
  >>> space = TargetSpace(target_func, pbounds, random_state=0)
  >>> x = np.array([4 , 5])
  >>> y = target_func(x)
  >>> space.register(x, y)
  >>> assert self.max()['target'] == 9
  >>> assert self.max()['params'] == {'p1': 1.0, 'p2': 2.0}
class_docstr_tok: ["Holds","the","param-space","coordinates","(","X",")","and","target","values","(","Y",")","Allows","for","constant-time","appends","while","ensuring","no","duplicates","are","added","Example","--","--","--","-",">",">",">","def","target_func","(","p1",",","p2",")",":",">",">",">","return","p1","+","p2",">",">",">","pbounds","=","{","'p1","'",":","(","0",",","1",")",",","'p2","'",":","(","1",",","100",")","}",">",">",">","space","=","TargetSpace","(","target_func",",","pbounds",",","random_state=0",")",">",">",">","x","=","np.array","(","[","4",",","5","]",")",">",">",">","y","=","target_func","(","x",")",">",">",">","space.register","(","x",",","y",")",">",">",">","assert","self.max","(",")","[","'target","'","]","==","9",">",">",">","assert","self.max","(",")","[","'params","'","]","==","{","'p1","'",":","1.0",",","'p2","'",":","2.0","}"]
docstr: Append a point and its target value to the known data.
  
  Parameters
  ----------
  x : ndarray
      a single point, with len(x) == self.dim
  
  y : float
      target function value
  
  Raises
  ------
  KeyError:
      if the point is not unique
  
  Notes
  -----
  runs in amortized constant time
  
  Example
  -------
  >>> target_func = lambda p1, p2: p1 + p2
  >>> pbounds = {'p1': (0, 1), 'p2': (1, 100)}
  >>> space = TargetSpace(target_func, pbounds)
  >>> len(space)
  0
  >>> x = np.array([0, 0])
  >>> y = 1
  >>> space.register(x, y)
  >>> len(space)
  1
docstr_tok: ["Append","a","point","and","its","target","value","to","the","known","data",".","Parameters","--","--","--","--","--","x",":","ndarray","a","single","point",",","with","len","(","x",")","==","self.dim","y",":","float","target","function","value","Raises","--","--","--","KeyError",":","if","the","point","is","not","unique","Notes","--","--","-","runs","in","amortized","constant","time","Example","--","--","--","-",">",">",">","target_func","=","lambda","p1",",","p2",":","p1","+","p2",">",">",">","pbounds","=","{","'p1","'",":","(","0",",","1",")",",","'p2","'",":","(","1",",","100",")","}",">",">",">","space","=","TargetSpace","(","target_func",",","pbounds",")",">",">",">","len","(","space",")","0",">",">",">","x","=","np.array","(","[","0",",","0","]",")",">",">",">","y","=","1",">",">",">","space.register","(","x",",","y",")",">",">",">","len","(","space",")","1"]
code: def register(self, params, target, constraint_value=None):
      """
      Append a point and its target value to the known data.
  
      Parameters
      ----------
      x : ndarray
          a single point, with len(x) == self.dim
  
      y : float
          target function value
  
      Raises
      ------
      KeyError:
          if the point is not unique
  
      Notes
      -----
      runs in amortized constant time
  
      Example
      -------
      >>> target_func = lambda p1, p2: p1 + p2
      >>> pbounds = {'p1': (0, 1), 'p2': (1, 100)}
      >>> space = TargetSpace(target_func, pbounds)
      >>> len(space)
      0
      >>> x = np.array([0, 0])
      >>> y = 1
      >>> space.register(x, y)
      >>> len(space)
      1
      """
      x = self._as_array(params)
      if x in self:
          if self._allow_duplicate_points:
              self.n_duplicate_points = self.n_duplicate_points + 1
              print(
                  f"{Colours.RED}Data point {x} is not unique. {self.n_duplicate_points} duplicates registered."
                  f" Continuing ...{Colours.END}"
              )
          else:
              raise NotUniqueError(
                  f'Data point {x} is not unique. You can set "allow_duplicate_points=True" to '
                  f"avoid this error"
              )
  
      # if x is not within the bounds of the parameter space, warn the user
      if self._bounds is not None:
          if not np.all(
              (self._bounds[:, 0] <= x) & (x <= self._bounds[:, 1])
          ):
              warn(
                  f"\nData point {x} is outside the bounds of the parameter space. ",
                  stacklevel=2,
              )
  
      self._params = np.concatenate([self._params, x.reshape(1, -1)])
      self._target = np.concatenate([self._target, [target]])
  
      if self._constraint is None:
          # Insert data into unique dictionary
          self._cache[_hashable(x.ravel())] = target
      else:
          if constraint_value is None:
              msg = (
                  "When registering a point to a constrained TargetSpace"
                  + " a constraint value needs to be present."
              )
              raise ValueError(msg)
          # Insert data into unique dictionary
          self._cache[_hashable(x.ravel())] = (target, constraint_value)
          self._constraint_values = np.concatenate(
              [self._constraint_values, [constraint_value]]
          )
  
imports: import numpy
  from warnings import warn
  from .util import ensure_rng, NotUniqueError
  from .util import Colours
label_desc: Use image node_id 16 for calling the TargetSpace obj's underlying member method code with example usage: obj.register(params, target, constraint_value) without return types