(x, value_at_1, sigmoid)
Returns 1 when `x` == 0, between 0 and 1 otherwise.

  Args:
    x: A scalar or numpy array.
    value_at_1: A float between 0 and 1 specifying the output when `x` == 1.
    sigmoid: String, choice of sigmoid type.

  Returns:
    A numpy array with values between 0.0 and 1.0.

  Raises:
    ValueError: If not 0 < `value_at_1` < 1, except for `linear`, `cosine` and
      `quadratic` sigmoids which allow `value_at_1` == 0.
    ValueError: If `sigmoid` is of an unknown type.
Returns 1 when `x` == 0, between 0 and 1 otherwise.
Returns 1 when x == 0 between 0 and 1 otherwise .
def _sigmoids(x, value_at_1, sigmoid):
  """Returns 1 when `x` == 0, between 0 and 1 otherwise.

  Args:
    x: A scalar or numpy array.
    value_at_1: A float between 0 and 1 specifying the output when `x` == 1.
    sigmoid: String, choice of sigmoid type.

  Returns:
    A numpy array with values between 0.0 and 1.0.

  Raises:
    ValueError: If not 0 < `value_at_1` < 1, except for `linear`, `cosine` and
      `quadratic` sigmoids which allow `value_at_1` == 0.
    ValueError: If `sigmoid` is of an unknown type.
  """
  if sigmoid in ('cosine', 'linear', 'quadratic'):
    if not 0 <= value_at_1 < 1:
      raise ValueError('`value_at_1` must be nonnegative and smaller than 1, '
                       'got {}.'.format(value_at_1))
  else:
    if not 0 < value_at_1 < 1:
      raise ValueError('`value_at_1` must be strictly between 0 and 1, '
                       'got {}.'.format(value_at_1))

  if sigmoid == 'gaussian':
    scale = np.sqrt(-2 * np.log(value_at_1))
    return np.exp(-0.5 * (x*scale)**2)

  elif sigmoid == 'hyperbolic':
    scale = np.arccosh(1/value_at_1)
    return 1 / np.cosh(x*scale)

  elif sigmoid == 'long_tail':
    scale = np.sqrt(1/value_at_1 - 1)
    return 1 / ((x*scale)**2 + 1)

  elif sigmoid == 'reciprocal':
    scale = 1/value_at_1 - 1
    return 1 / (abs(x)*scale + 1)

  elif sigmoid == 'cosine':
    scale = np.arccos(2*value_at_1 - 1) / np.pi
    scaled_x = x*scale
    with warnings.catch_warnings():
      warnings.filterwarnings(
          action='ignore', message='invalid value encountered in cos')
      cos_pi_scaled_x = np.cos(np.pi*scaled_x)
    return np.where(abs(scaled_x) < 1, (1 + cos_pi_scaled_x)/2, 0.0)

  elif sigmoid == 'linear':
    scale = 1-value_at_1
    scaled_x = x*scale
    return np.where(abs(scaled_x) < 1, 1 - scaled_x, 0.0)

  elif sigmoid == 'quadratic':
    scale = np.sqrt(1-value_at_1)
    scaled_x = x*scale
    return np.where(abs(scaled_x) < 1, 1 - scaled_x**2, 0.0)

  elif sigmoid == 'tanh_squared':
    scale = np.arctanh(np.sqrt(1-value_at_1))
    return 1 - np.tanh(x*scale)**2

  else:
    raise ValueError('Unknown sigmoid type {!r}.'.format(sigmoid))
def _sigmoids ( x , value_at_1 , sigmoid ) : if sigmoid in ( 'cosine' , 'linear' , 'quadratic' ) : if not 0 <= value_at_1 < 1 : raise ValueError ( '`value_at_1` must be nonnegative and smaller than 1, ' 'got {}.' . format ( value_at_1 ) ) else : if not 0 < value_at_1 < 1 : raise ValueError ( '`value_at_1` must be strictly between 0 and 1, ' 'got {}.' . format ( value_at_1 ) ) if sigmoid == 'gaussian' : scale = np . sqrt ( - 2 * np . log ( value_at_1 ) ) return np . exp ( - 0.5 * ( x * scale ) ** 2 ) elif sigmoid == 'hyperbolic' : scale = np . arccosh ( 1 / value_at_1 ) return 1 / np . cosh ( x * scale ) elif sigmoid == 'long_tail' : scale = np . sqrt ( 1 / value_at_1 - 1 ) return 1 / ( ( x * scale ) ** 2 + 1 ) elif sigmoid == 'reciprocal' : scale = 1 / value_at_1 - 1 return 1 / ( abs ( x ) * scale + 1 ) elif sigmoid == 'cosine' : scale = np . arccos ( 2 * value_at_1 - 1 ) / np . pi scaled_x = x * scale with warnings . catch_warnings ( ) : warnings . filterwarnings ( action = 'ignore' , message = 'invalid value encountered in cos' ) cos_pi_scaled_x = np . cos ( np . pi * scaled_x ) return np . where ( abs ( scaled_x ) < 1 , ( 1 + cos_pi_scaled_x ) / 2 , 0.0 ) elif sigmoid == 'linear' : scale = 1 - value_at_1 scaled_x = x * scale return np . where ( abs ( scaled_x ) < 1 , 1 - scaled_x , 0.0 ) elif sigmoid == 'quadratic' : scale = np . sqrt ( 1 - value_at_1 ) scaled_x = x * scale return np . where ( abs ( scaled_x ) < 1 , 1 - scaled_x ** 2 , 0.0 ) elif sigmoid == 'tanh_squared' : scale = np . arctanh ( np . sqrt ( 1 - value_at_1 ) ) return 1 - np . tanh ( x * scale ) ** 2 else : raise ValueError ( 'Unknown sigmoid type {!r}.' . format ( sigmoid ) )