22import numpy as np
33from octoprint_gcodeleveling .twoDimFit import twoDpolyEval
44
5-
6- from abc import ABC , abstractmethod
7-
85threshold = 0.005
96
10- class PathWiseMaximizer (ABC ):
7+ class PathWiseMaximizer ():
118
129 def optimize (self , value , first , second ):
1310 pass
@@ -19,67 +16,6 @@ def testPoint(self, value, q):
1916 else :
2017 return (False , False )
2118
22- class Spaceshot (PathWiseMaximizer ):
23- def __init__ (self , shots ):
24- self .shots = shots
25- self .max = None
26- self .maxQ = None
27-
28- def optimize (self , value , first , second ):
29- self .maxQ = None
30- self .max = 0
31- for shot in range (self .shots ):
32- q = shot / self .shots
33- tp , tv = self .testPoint (value , q )
34- if (tp and tv > self .max ):
35- self .maxQ = tp
36- self .max = tv
37- return self .maxQ
38-
39- class Scatershot (PathWiseMaximizer ):
40- def __init__ (self , shots ):
41- self .shots = shots
42- self .max = None
43- self .maxQ = None
44-
45- def optimize (self , value , first , second ):
46- self .maxQ = None
47- self .max = 0
48- for shot in range (self .shots ):
49- q = random .random ()
50- tp , tv = self .testPoint (value , q )
51- if (tp and tv > self .max ):
52- self .maxQ = tp
53- self .max = tv
54- return self .maxQ
55-
56- class SinglePointNewton (PathWiseMaximizer ):
57- def __init__ (self , height = 0.00001 , telos = 0.1 , point = 0.5 ):
58- self .hMin = height
59- self .telos = telos
60- self .point = point
61-
62- def optimize (self , value , first , second ):
63- q = self .point
64-
65- lvl = 1
66- height = 10
67- while (abs (height ) > self .hMin ):
68- slope = second (q )
69- if (slope != 0.0 ):
70- height = first (q )
71- q = - height / slope + q
72- lvl += 1
73- else :
74- break
75-
76- if (q > self .telos and q < 1 - self .telos ):
77- tp , _ = self .testPoint (value , q )
78- if tp :
79- return tp
80- else :
81- return None
82-
8319class SingleGradientAscent (PathWiseMaximizer ):
8420 def __init__ (self , ds = 0.00001 , step = 10.0 , telos = 0.01 , point = 0.5 , lvl = 200 ):
8521 self .sMin = ds
@@ -108,33 +44,6 @@ def optimize(self, value, first, second):
10844 else :
10945 return None
11046
111- class DynastepSingleGradientAscent (PathWiseMaximizer ):
112- def __init__ (self , ds = 0.00001 , step = 10.0 , telos = 0.01 , point = 0.5 , lvl = 500 ):
113- self .sMin = ds
114- self .step = step
115- self .telos = telos
116- self .point = point
117- self .lvl = lvl
118-
119- def optimize (self , value , first , second ):
120- q = self .point
121-
122- lvl = 0
123- slope = 10
124- while (abs (slope ) > self .sMin and q > self .telos and q < 1 - self .telos and lvl < self .lvl ):
125- slope = first (q )
126- q += slope * self .step * math .exp (- lvl )
127- lvl += 1
128-
129- if (q > self .telos and q < 1 - self .telos ):
130- tp , tv = self .testPoint (value , q )
131- if (tp ):
132- return tp
133- else :
134- return None
135- else :
136- return None
137-
13847def der (coeffs ):
13948 xPartial = []
14049 yPartial = []
0 commit comments