def test_minimize_array(): assert _round_eq(2, ds.minimize(lambda x: (x[0] - 2)**2, [0], array=True)) assert _round_eq([2, 1], list( ds.minimize(lambda x: (x[0] - 2)**2 + (x[1] - 1)**2, [0, 0], array=True)))
def test_minimize(): assert _round_eq(2, ds.minimize(lambda x: (x - 2)**2)) assert _round_eq([2, 1], list(ds.minimize(lambda x, y: (x - 2)**2 + (y - 1)**2))) assert _round_eq(2, ds.minimize(lambda x: (x - 2)**2, 1)) assert _round_eq([2, 1], list( ds.minimize(lambda x, y: (x - 2)**2 + (y - 1)**2, [1, 1])))
def test_minimize_smooth(): assert _round_eq(2, ds.minimize(lambda x: (x - 2)**2, smooth=True)) assert _round_eq([2, 1], list( ds.minimize(lambda x, y: (x - 2)**2 + (y - 1)**2, smooth=True))) assert _round_eq(2, ds.minimize(lambda x: (x - 2)**2, 1, smooth=True)) assert _round_eq([2, 1], list( ds.minimize(lambda x, y: (x - 2)**2 + (y - 1)**2, [1, 1], smooth=True)))
def minimize(f, start=None, **vargs): def expanded_f(*args): return f(args) return datascience.minimize(expanded_f, start=start, method="L-BFGS-B", **vargs)
def test_minimize_array(): assert _round_eq(2, ds.minimize(lambda x: (x[0]-2)**2, [0], array=True)) assert _round_eq([2, 1], list(ds.minimize(lambda x: (x[0]-2)**2 + (x[1]-1)**2, [0, 0], array=True)))
def test_minimize_smooth(): assert _round_eq(2, ds.minimize(lambda x: (x-2)**2, smooth=True)) assert _round_eq([2, 1], list(ds.minimize(lambda x, y: (x-2)**2 + (y-1)**2, smooth=True))) assert _round_eq(2, ds.minimize(lambda x: (x-2)**2, 1, smooth=True)) assert _round_eq([2, 1], list(ds.minimize(lambda x, y: (x-2)**2 + (y-1)**2, [1, 1], smooth=True)))
def test_minimize(): assert _round_eq(2, ds.minimize(lambda x: (x-2)**2)) assert _round_eq([2, 1], list(ds.minimize(lambda x, y: (x-2)**2 + (y-1)**2))) assert _round_eq(2, ds.minimize(lambda x: (x-2)**2, 1)) assert _round_eq([2, 1], list(ds.minimize(lambda x, y: (x-2)**2 + (y-1)**2, [1, 1])))