77try : import cvxpy
88except ImportError : pass
99
10- try :
11- import mosek
12- solver = 'MOSEK' # https://www.mosek.com/
13- except ImportError :
14- warn ("MOSEK not installed, falling back to CVXPY's defaults" )
15- solver = None # passing this to solve() allows CVXPY to use whatever it deems best
16-
1710
1811def iterative_velocity (x , dt , params , options = None , num_iterations = None , gamma = None , cg_maxiter = 1000 , scale = 'small' ):
1912 """Use an iterative solver to find the total variation regularized 1st derivative. See
@@ -61,17 +54,16 @@ def iterative_velocity(x, dt, params, options=None, num_iterations=None, gamma=N
6154 return x_hat , dxdt_hat
6255
6356
64- def _total_variation_regularized_derivative (x , dt , order , gamma , solver = solver ):
57+ def _total_variation_regularized_derivative (x , dt , order , gamma , solver = None ):
6558 """Generalized total variation regularized derivatives. Use convex optimization (cvxpy) to solve for a
66- total variation regularized derivative. Default solver is MOSEK: , which is not
67- always available. Fall back to CVXPY's default.
59+ total variation regularized derivative.
6860
6961 :param np.array[float] x: data to differentiate
7062 :param float dt: time step
7163 :param int order: 1, 2, or 3, the derivative to regularize
7264 :param float gamma: regularization parameter
7365 :param str solver: Solver to use. Solver options include: 'MOSEK', 'CVXOPT', 'CLARABEL', 'ECOS'.
74- In testing, 'MOSEK' was the most robust.
66+ In testing, 'MOSEK' was the most robust. If not given, fall back to CVXPY's default .
7567
7668 :return: tuple[np.array, np.array] of\n
7769 - **x_hat** -- estimated (smoothed) x
@@ -116,7 +108,7 @@ def _total_variation_regularized_derivative(x, dt, order, gamma, solver=solver):
116108 return x_hat * std + mean , dxdt_hat * std
117109
118110
119- def velocity (x , dt , params , options = None , gamma = None , solver = solver ):
111+ def velocity (x , dt , params , options = None , gamma = None , solver = None ):
120112 """Use convex optimization (cvxpy) to solve for the velocity total variation regularized derivative.
121113
122114 :param np.array[float] x: data to differentiate
@@ -125,7 +117,7 @@ def velocity(x, dt, params, options=None, gamma=None, solver=solver):
125117 :param dict options: (**deprecated**, prefer :code:`solver`) a dictionary consisting of {'solver': (str)}
126118 :param float gamma: the regularization parameter
127119 :param str solver: the solver CVXPY should use, 'MOSEK', 'CVXOPT', 'CLARABEL', 'ECOS', etc.
128- In testing, 'MOSEK' was the most robust. Default is to use CVXPY's default.
120+ In testing, 'MOSEK' was the most robust. If not given, fall back to CVXPY's default.
129121
130122 :return: tuple[np.array, np.array] of\n
131123 - **x_hat** -- estimated (smoothed) x
@@ -143,7 +135,7 @@ def velocity(x, dt, params, options=None, gamma=None, solver=solver):
143135 return _total_variation_regularized_derivative (x , dt , 1 , gamma , solver = solver )
144136
145137
146- def acceleration (x , dt , params , options = None , gamma = None , solver = solver ):
138+ def acceleration (x , dt , params , options = None , gamma = None , solver = None ):
147139 """Use convex optimization (cvxpy) to solve for the acceleration total variation regularized derivative.
148140
149141 :param np.array[float] x: data to differentiate
@@ -152,7 +144,7 @@ def acceleration(x, dt, params, options=None, gamma=None, solver=solver):
152144 :param dict options: (**deprecated**, prefer :code:`solver`) a dictionary consisting of {'solver': (str)}
153145 :param float gamma: the regularization parameter
154146 :param str solver: the solver CVXPY should use, 'MOSEK', 'CVXOPT', 'CLARABEL', 'ECOS', etc.
155- In testing, 'MOSEK' was the most robust. Default is to use CVXPY's default.
147+ In testing, 'MOSEK' was the most robust. If not given, fall back to CVXPY's default.
156148
157149 :return: tuple[np.array, np.array] of\n
158150 - **x_hat** -- estimated (smoothed) x
@@ -170,7 +162,7 @@ def acceleration(x, dt, params, options=None, gamma=None, solver=solver):
170162 return _total_variation_regularized_derivative (x , dt , 2 , gamma , solver = solver )
171163
172164
173- def jerk (x , dt , params , options = None , gamma = None , solver = solver ):
165+ def jerk (x , dt , params , options = None , gamma = None , solver = None ):
174166 """Use convex optimization (cvxpy) to solve for the jerk total variation regularized derivative.
175167
176168 :param np.array[float] x: data to differentiate
@@ -179,7 +171,7 @@ def jerk(x, dt, params, options=None, gamma=None, solver=solver):
179171 :param dict options: (**deprecated**, prefer :code:`solver`) a dictionary consisting of {'solver': (str)}
180172 :param float gamma: the regularization parameter
181173 :param str solver: the solver CVXPY should use, 'MOSEK', 'CVXOPT', 'CLARABEL', 'ECOS', etc.
182- In testing, 'MOSEK' was the most robust. Default is to use CVXPY's default.
174+ In testing, 'MOSEK' was the most robust. If not given, fall back to CVXPY's default.
183175
184176 :return: tuple[np.array, np.array] of\n
185177 - **x_hat** -- estimated (smoothed) x
@@ -197,7 +189,7 @@ def jerk(x, dt, params, options=None, gamma=None, solver=solver):
197189 return _total_variation_regularized_derivative (x , dt , 3 , gamma , solver = solver )
198190
199191
200- def smooth_acceleration (x , dt , params , options = None , gamma = None , window_size = None , solver = solver ):
192+ def smooth_acceleration (x , dt , params , options = None , gamma = None , window_size = None , solver = None ):
201193 """Use convex optimization (cvxpy) to solve for the acceleration total variation regularized derivative,
202194 and then apply a convolutional gaussian smoother to the resulting derivative to smooth out the peaks.
203195 The end result is similar to the jerk method, but can be more time-efficient.
@@ -209,7 +201,7 @@ def smooth_acceleration(x, dt, params, options=None, gamma=None, window_size=Non
209201 :param float gamma: the regularization parameter
210202 :param int window_size: window size for gaussian kernel
211203 :param str solver: the solver CVXPY should use, 'MOSEK', 'CVXOPT', 'CLARABEL', 'ECOS', etc.
212- In testing, 'MOSEK' was the most robust. Default is to use CVXPY's default.
204+ In testing, 'MOSEK' was the most robust. If not given, fall back to CVXPY's default.
213205
214206 :return: tuple[np.array, np.array] of\n
215207 - **x_hat** -- estimated (smoothed) x
@@ -236,7 +228,7 @@ def smooth_acceleration(x, dt, params, options=None, gamma=None, window_size=Non
236228 return x_hat , dxdt_hat
237229
238230
239- def jerk_sliding (x , dt , params , options = None , gamma = None , solver = solver ):
231+ def jerk_sliding (x , dt , params , options = None , gamma = None , solver = None ):
240232 """Use convex optimization (cvxpy) to solve for the jerk total variation regularized derivative.
241233
242234 :param np.array[float] x: data to differentiate
@@ -245,7 +237,7 @@ def jerk_sliding(x, dt, params, options=None, gamma=None, solver=solver):
245237 :param dict options: (**deprecated**, prefer :code:`solver`) a dictionary consisting of {'solver': (str)}
246238 :param float gamma: the regularization parameter
247239 :param str solver: the solver CVXPY should use, 'MOSEK', 'CVXOPT', 'CLARABEL', 'ECOS', etc.
248- In testing, 'MOSEK' was the most robust. Default is to use CVXPY's default.
240+ In testing, 'MOSEK' was the most robust. If not given, fall back to CVXPY's default.
249241
250242 :return: tuple[np.array, np.array] of\n
251243 - **x_hat** -- estimated (smoothed) x
0 commit comments