code: def _interpolate_adjacent(times, values, name=None):
      """Interpolates linearly between adjacent values.
  
      Suppose `times` are `[t_1, t_2, ..., t_n]` an array of length `n` and
      values are `[f_1, ... f_n]` of length `n`. This function associates
      each of the values to the midpoint of the interval i.e. `f_i` is associated
      to the midpoint of the interval `[t_i, t_{i+1}]`. Then it calculates the
      values at the interval boundaries by linearly interpolating between adjacent
      intervals. The first interval is considered to be `[0, t_1]`. The values at
      the endpoints (i.e. result[0] and result[n]) are computed as follows:
      `result[0] = values[0] - 0.5 * (result[1] - values[0])` and
      `result[n] = values[n-1] - 0.5 * (result[n-1] - values[n-1])`.
      The rationale for these specific values is discussed in Ref. [1].
  
      Args:
        times: A rank 1 `Tensor` of real dtype. The times at which the interpolated
          values are to be computed. The values in the array should be positive and
          monotonically increasing.
        values: A rank 1 `Tensor` of the same dtype and shape as `times`. The values
          assigned to the midpoints of the time intervals.
        name: Python `str` name prefixed to Ops created by this class.
          Default value: None which is mapped to the default name
            'interpolate_adjacent'.
  
      Returns:
        interval_values: The values interpolated from the supplied midpoint values
          as described above. A `Tensor` of the same dtype as `values` but shape
          `[n+1]` where `[n]` is the shape of `values`. The `i`th component of the
          is the value associated to the time point `t_{i+1}` with `t_0 = 0`.
      """
      with tf.compat.v1.name_scope(
          name,
          default_name="interpolate_adjacent",
          values=[times, values],
      ):
          dt1 = diff(times, order=1, exclusive=False)
          dt2 = diff(times, order=2, exclusive=False)[1:]
          weight_right = dt1[:-1] / dt2
          weight_left = dt1[1:] / dt2
          interior_values = (
              weight_right * values[1:] + weight_left * values[:-1]
          )
          value_0 = values[0] - 0.5 * (interior_values[0] - values[0])
          value_n = values[-1] - 0.5 * (
              interior_values[-1] - values[-1]
          )
          return tf.concat(
              [[value_0], interior_values, [value_n]], axis=0
          )
  
file_path: tf-quant-finance/tf_quant_finance/rates/hagan_west/monotone_convex.py
imports: import tensorflow.compat.v2
  from tf_quant_finance import types
  from tf_quant_finance.math import piecewise
  from tf_quant_finance.math.diff_ops import diff
  from tf_quant_finance.rates.analytics import forwards
label_desc: Use image node_id 4 for calling a global function with example usage: _interpolate_adjacent(times, values, name) and returns: tf