How to use the numdifftools.nd_cstep.MinStepGenerator 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 / numdifftools / nd_cstep.py View on Github external
method = 'complex'
    data = []
    for name in ['exp', 'expm1', 'sin', 'cos', 'square']:
        # function_names[:-3]:
        for order in range(4, 5, 1):
            #  order = 1
            for n in range(1, 16, 1):
                num_steps = n + order - 1 + num_extrap
                if method in ['central', 'complex']:
                    step = 2
                    if (n > 1 or order >= 4) and method == 'complex':
                        step = 4
                    num_steps = (n + order-1) // step + num_extrap

                step_ratio = 1.6  # 4**(1./n)
                epsilon = MinStepGenerator(num_steps=num_steps,
                                           step_ratio=step_ratio,
                                           offset=0, use_exact_steps=True)
                data.append(pd.DataFrame(_example3(x=0.7, fun_name=name,
                                                   epsilon=epsilon,
                                                   method=method,
                                                   scale=None, n=n,
                                                   order=order),
                                         index=np.arange(1)))
    df = pd.concat(data)
    # sprint(df)
    print(df.groupby(['n']).mean())
    print(np.diff(df.groupby(['n']).mean(), axis=0))
    plt.show('hold')
github pbrod / numdifftools / numdifftools / nd_cstep.py View on Github external
'''
    step_nom : vector   default maximum(log1p(abs(x0)), 1)
        Nominal step. (The steps: h_i = step_nom[i] * delta)
    step_max : real scalar  (Default 2.0)
        Maximum allowed excursion from step_nom as a multiple of it.
    step_ratio: real scalar  (Default 2.0)
        Ratio used between sequential steps in the estimation of the derivative
    step_num : integer  (Default 26)
        The minimum step_num for making richardson extrapolation work is
            7 + np.ceil(self.n/2.) + self.order + self.richardson_terms
    delta : vector default step_max*step_ratio**(-arange(step_num))
        Defines the steps sizes used in derivation: h_i = step_nom[i] * delta
'''


class MaxStepGenerator(MinStepGenerator):
    '''
    Generates a sequence of steps

    where
        steps = base_step * step_ratio ** (-np.arange(num_steps) + offset)
        base_step = step_max * step_nom

    Parameters
    ----------
    max_step : float, array-like, optional default 2
       Defines the maximum step
    step_ratio : real scalar, optional, default 2
        Ratio between sequential steps generated.
        Note: Ratio > 1
    num_steps : scalar integer, optional, default  n + order - 1 + num_extrap
        defines number of steps generated. It should be larger than
github pbrod / numdifftools / numdifftools / nd_cstep.py View on Github external
def _make_generator(self, step):
        if hasattr(step, '__call__'):
            return step
        if step is None and self.method not in ['complex']:
            return MaxStepGenerator(step_ratio=None, num_extrap=7)
        return MinStepGenerator(base_step=step, step_ratio=None, num_extrap=0)