How to use the numdifftools.step_generators.default_scale function in numdifftools

To help you get started, we’ve selected a few numdifftools examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pbrod / numdifftools / src / numdifftools / _find_default_scale.py View on Github external
def _print_summary(method, order, x_values, scales):
    print(scales)
    header = 'method="{}", order={}, x_values={}:'.format(method, order, str(x_values))
    print(header)
    for n in scales:
        print('n={}, mean scale={:.2f}, median scale={:.2f}'.format(n,
                                                                    np.mean(scales[n]),
                                                                    np.median(scales[n])))

    print('Default scale with ' + header)
    for n in scales:
        print('n={}, scale={:.2f}'.format(n, default_scale(method, n, order)))
github pbrod / numdifftools / src / numdifftools / _find_default_scale.py View on Github external
n, method, order = fd.n, fd.method, fd.order

    if dfun is None:
        return dict(n=n, order=order, method=method, fun=name,
                    error=np.nan, scale=np.nan, x=np.nan)

    relativ_errors = _compute_relative_errors(x, dfun, fd, scales)

    if not np.isfinite(relativ_errors).any():
        return dict(n=n, order=order, method=method, fun=name,
                    error=np.nan, scale=np.nan)
    if show_plot:
        txt = ['', "1'st", "2'nd", "3'rd", "4'th", "5'th", "6'th",
               "7th"] + ["%d'th" % i for i in range(8, 25)]
        title = "The %s derivative using %s, order=%d" % (txt[n], method, order)
        scale0 = default_scale(method, n, order)
        plot_error(scales, relativ_errors, scale0, title, label=name)

    i = np.nanargmin(relativ_errors)
    error = float('{:.3g}'.format(relativ_errors[i]))
    return dict(n=n, order=order, method=method, fun=name,
                error=error, scale=scales[i], x=x)