docstr: Set the particle to an intermediate position
  
  This method resets particles that exceed the bounds to an intermediate
  position between the boundary and their earlier position. Namely, it changes
  the coordinate of the out-of-bounds axis to the middle value between the
  previous position and the boundary of the axis.
  The following equation describes this strategy:
  
  .. math::
  
      x_{i, t, d} = \begin{cases}
                          \frac{1}{2} \left (x_{i, t-1, d} + lb_d \right) & \quad \text{if }x_{i, t, d} < lb_d \\
                          \frac{1}{2} \left (x_{i, t-1, d} + ub_d \right) & \quad \text{if }x_{i, t, d} > ub_d \\
                          x_{i, t, d} & \quad \text{otherwise}
                    \end{cases}
docstr_tok: ["Set","the","particle","to","an","intermediate","position","This","method","resets","particles","that","exceed","the","bounds","to","an","intermediate","position","between","the","boundary","and","their","earlier","position",".","Namely",",","it","changes","the","coordinate","of","the","out-of-bounds","axis","to","the","middle","value","between","the","previous","position","and","the","boundary","of","the","axis",".","The","following","equation","describes","this","strategy",":","..","math",":",":","x_","{","i",",","t",",","d","}","=","\\begin","{","cases","}","\\frac","{","1","}","{","2","}","\\left","(","x_","{","i",",","t-1",",","d","}","+","lb_d","\\right",")","&","\\quad","\\text","{","if","}","x_","{","i",",","t",",","d","}","<","lb_d","\\\\","\\frac","{","1","}","{","2","}","\\left","(","x_","{","i",",","t-1",",","d","}","+","ub_d","\\right",")","&","\\quad","\\text","{","if","}","x_","{","i",",","t",",","d","}",">","ub_d","\\\\","x_","{","i",",","t",",","d","}","&","\\quad","\\text","{","otherwise","}","\\end","{","cases","}"]
code: def intermediate(self, position, bounds, **kwargs):
      r"""Set the particle to an intermediate position
  
          This method resets particles that exceed the bounds to an intermediate
          position between the boundary and their earlier position. Namely, it changes
          the coordinate of the out-of-bounds axis to the middle value between the
          previous position and the boundary of the axis.
          The following equation describes this strategy:
  
          .. math::
  
              x_{i, t, d} = \begin{cases}
                                  \frac{1}{2} \left (x_{i, t-1, d} + lb_d \right) & \quad \text{if }x_{i, t, d} < lb_d \\
                                  \frac{1}{2} \left (x_{i, t-1, d} + ub_d \right) & \quad \text{if }x_{i, t, d} > ub_d \\
                                  x_{i, t, d} & \quad \text{otherwise}
                            \end{cases}
  
          """
      if self.memory is None:
          new_pos = position
          self.memory = new_pos
      else:
          lb, ub = bounds
          lower_than_bound, greater_than_bound = self._out_of_bounds(
              position, bounds
          )
          new_pos = position
          new_pos[lower_than_bound] = 0.5 * (
              self.memory[lower_than_bound] + lb[lower_than_bound[1]]
          )
          new_pos[greater_than_bound] = 0.5 * (
              self.memory[greater_than_bound]
              + ub[greater_than_bound[1]]
          )
          self.memory = new_pos
      return new_pos
  
imports: import inspect
  import logging
  import numpy
  import math
  from copy import copy
  from ..utils.reporter import Reporter
label_desc: Use image node_id 7 for calling the BoundaryHandler obj's underlying member method code with example usage: obj.intermediate(position, bounds) and returns: new_pos