def fun_inverse(fun=None, y=<NUM_LIT:0>, x0=None, args=(), disp=False, method='<STR_LIT>', **kwargs):
fun_inverse.fun = cost_fun.fun = fun if fun is not None else getattr(fun_inverse, '<STR_LIT>', lambda x: x)<EOL>fun_inverse.target = cost_fun.target = y or <NUM_LIT:0><EOL>fun_inverse.verbose = verbose = cost_fun.verbose = kwargs.pop(<EOL>'<STR_LIT>', getattr(cost_fun, '<STR_LIT>', getattr(fun_inverse, '<STR_LIT>', False)))<EOL>fun_inverse.x0 = x0 = x0 if x0 is not None else getattr(fun_inverse, '<STR_LIT>', <NUM_LIT:0>) or <NUM_LIT:0><EOL>if verbose:<EOL><INDENT>print('<STR_LIT>'.format(fun_inverse.x0, fun_inverse.target))<EOL><DEDENT>res = minimize(cost_fun,<EOL>x0=x0,<EOL>args=args,<EOL>options=kwargs.pop('<STR_LIT>', {}),<EOL>method=method,<EOL>**kwargs<EOL>)<EOL>if isinstance(x0, NUMERIC_TYPES):<EOL><INDENT>return res.x[<NUM_LIT:0>]<EOL><DEDENT>return res.x<EOL>
r"""Find the threshold level that accomplishes the desired specificity
    Call indicated function repeatedly to find answer to the inverse function evaluation
    Arguments:
      fun (function): function to be calculate an inverse for
      y (float): desired output of fun
      x0 (float): initial guess at input to fun, the fun arg that will be adjusted
      args (list or tuple): constants arguments to fun which will not be adjusted
      constraints (tuple): dictionary of optimizer constraints (see scipy.optimize.minimize)
      disp (bool): whether to display incremental results during optimization
      method (str): one of the scipy.optimize.minimize methods
      additional kwargs are passed along to the minimize function
    fun_inverse can be used to calculate a trivial square root:
    >>> round(fun_inverse(fun=lambda x: x**2, y=9, x0=0), 6)
    3.0