Skip to content

Commit

Permalink
change new parameter from boolean to str
Browse files Browse the repository at this point in the history
  • Loading branch information
daurer committed Mar 5, 2024
1 parent 66bfb1f commit f279f00
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions ptypy/engines/ML.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,11 @@ class ML(PositionCorrectionEngine):
lowlim = 0
help = Number of iterations before probe update starts
[all_line_coeffs]
default = False
type = bool
help = Whether to use all nine coefficients in the linesearch instead of three
[poly_line_coeffs]
default = quadratic
type = str
help = How many coefficients to be used in the the linesearch
doc = choose between the 'quadratic' approximation (default) or 'all'
"""

Expand Down Expand Up @@ -292,7 +293,7 @@ def engine_iterate(self, num=1):
# In principle, the way things are now programmed this part
# could be iterated over in a real Newton-Raphson style.
t2 = time.time()
if self.p.all_line_coeffs:
if self.p.poly_line_coeffs == "all":
B = self.ML_model.poly_line_all_coeffs(self.ob_h, self.pr_h)
diffB = np.arange(1,len(B))*B[1:] # coefficients of poly derivative
roots = np.roots(np.flip(diffB.astype(np.double))) # roots only supports double
Expand All @@ -302,10 +303,12 @@ def engine_iterate(self, num=1):
else: # find real root with smallest poly objective
evalp = lambda root: np.polyval(np.flip(B),root)
self.tmin = dt(min(real_roots, key=evalp)) # root with smallest poly objective
else:
elif self.p.poly_line_coeffs == "quadratic":
B = self.ML_model.poly_line_coeffs(self.ob_h, self.pr_h)
# same as above but quicker when poly quadratic
self.tmin = dt(-0.5 * B[1] / B[2])
else:
raise NotImplementedError("poly_line_coeffs should be 'quadratic' or 'all'")

tc += time.time() - t2

Expand Down

0 comments on commit f279f00

Please sign in to comment.