Commit 200ab07e by Martin Reinecke

### cleanups

parent 40aae561
 ... @@ -21,7 +21,6 @@ from functools import reduce ... @@ -21,7 +21,6 @@ from functools import reduce class FieldArray(FieldType): class FieldArray(FieldType): def __init__(self, shape): def __init__(self, shape): super(FieldArray, self).__init__() super(FieldArray, self).__init__() try: try: ... ...
 ... @@ -20,10 +20,5 @@ from ..domain_object import DomainObject ... @@ -20,10 +20,5 @@ from ..domain_object import DomainObject class FieldType(DomainObject): class FieldType(DomainObject): def weight(self, x, power=1, axes=None, inplace=False): def weight(self, x, power=1, axes=None, inplace=False): if inplace: return x if inplace else x.copy() result = x else: result = x.copy() return result
 ... @@ -205,9 +205,8 @@ class LineSearchStrongWolfe(LineSearch): ... @@ -205,9 +205,8 @@ class LineSearchStrongWolfe(LineSearch): The new Energy object on the new position. The new Energy object on the new position. """ """ # define the cubic and quadratic interpolant checks cubic_delta = 0.2 # cubic interpolant checks cubic_delta = 0.2 # cubic quad_delta = 0.1 # quadratic interpolant checks quad_delta = 0.1 # quadratic alpha_recent = None alpha_recent = None phi_recent = None phi_recent = None ... @@ -270,33 +269,22 @@ class LineSearchStrongWolfe(LineSearch): ... @@ -270,33 +269,22 @@ class LineSearchStrongWolfe(LineSearch): """Estimating the minimum with cubic interpolation. """Estimating the minimum with cubic interpolation. Finds the minimizer for a cubic polynomial that goes through the Finds the minimizer for a cubic polynomial that goes through the points ( a,f(a) ), ( b,f(b) ), and ( c,f(c) ) with derivative at point points (a,a), (b,fb), and (c,fc) with derivative at point a of fpa. a of fpa. f(x) = A *(x-a)^3 + B*(x-a)^2 + C*(x-a) + D If no minimizer can be found return None If no minimizer can be found return None Parameters Parameters ---------- ---------- a : float a, fa, fpa : float Selected point. abscissa, function value and derivative at first point fa : float b, fb : float Value of polynomial at point a. abscissa and function value at second point fpa : Field c, fc : float Derivative at point a. abscissa and function value at third point b : float Selected point. fb : float Value of polynomial at point b. c : float Selected point. fc : float Value of polynomial at point c. Returns Returns ------- ------- xmin : float xmin : float Position of the approximated minimum. Position of the approximated minimum. """ """ with np.errstate(divide='raise', over='raise', invalid='raise'): with np.errstate(divide='raise', over='raise', invalid='raise'): ... @@ -326,35 +314,25 @@ class LineSearchStrongWolfe(LineSearch): ... @@ -326,35 +314,25 @@ class LineSearchStrongWolfe(LineSearch): """Estimating the minimum with quadratic interpolation. """Estimating the minimum with quadratic interpolation. Finds the minimizer for a quadratic polynomial that goes through Finds the minimizer for a quadratic polynomial that goes through the points ( a,f(a) ), ( b,f(b) ) with derivative at point a of fpa. the points (a,fa), (b,fb) with derivative at point a of fpa. f(x) = B*(x-a)^2 + C*(x-a) + D Parameters Parameters ---------- ---------- a : float a, fa, fpa : float Selected point. abscissa, function value and derivative at first point fa : float b, fb : float Value of polynomial at point a. abscissa and function value at second point fpa : Field Derivative at point a. b : float Selected point. fb : float Value of polynomial at point b. Returns Returns ------- ------- xmin : float xmin : float Position of the approximated minimum. Position of the approximated minimum. """ """ # f(x) = B*(x-a)^2 + C*(x-a) + D with np.errstate(divide='raise', over='raise', invalid='raise'): with np.errstate(divide='raise', over='raise', invalid='raise'): try: try: D = fa C = fpa db = b - a * 1.0 db = b - a * 1.0 B = (fb - D - C * db) / (db * db) B = (fb - fa - fpa * db) / (db * db) xmin = a - C / (2.0 * B) xmin = a - fpa / (2.0 * B) except ArithmeticError: except ArithmeticError: return None return None if not np.isfinite(xmin): if not np.isfinite(xmin): ... ...
 ... @@ -94,7 +94,7 @@ class Test_Functionality(unittest.TestCase): ... @@ -94,7 +94,7 @@ class Test_Functionality(unittest.TestCase): outer = np.outer(fp1.val, fp2.val) outer = np.outer(fp1.val, fp2.val) fp = Field((p1, p2), val=outer) fp = Field((p1, p2), val=outer) samples = 2000 samples = 500 ps1 = 0. ps1 = 0. ps2 = 0. ps2 = 0. for ii in range(samples): for ii in range(samples): ... ...
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!