-
Notifications
You must be signed in to change notification settings - Fork 22
supporting variable dt with optimize #152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -252,7 +252,7 @@ def rbfdiff(x, _t, sigma=1, lmbd=0.01): | |
| if len(x) != len(_t): raise ValueError("If `_t` is given as array-like, must have same length as `x`.") | ||
| t = _t | ||
|
|
||
| # The below does the approximate equivalent of this code, but sparsely in O(N sigma), since the rbf falls off rapidly | ||
| # The below does the approximate equivalent of this code, but sparsely in O(N sigma^2), since the rbf falls off rapidly | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Solving a sparse linear system with |
||
| # t_i, t_j = np.meshgrid(t,t) | ||
| # r = t_j - t_i # radius | ||
| # rbf = np.exp(-(r**2) / (2 * sigma**2)) # radial basis function kernel | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| import os, sys, copy, scipy | ||
| import os, sys, copy | ||
| import numpy as np | ||
| from scipy.integrate import cumulative_trapezoid | ||
| from scipy.optimize import minimize | ||
|
|
||
|
|
||
| def hankel_matrix(x, num_delays, pad=False): # fixed delay step of 1 | ||
|
|
@@ -95,16 +97,16 @@ def peakdet(x, delta, t=None): | |
|
|
||
|
|
||
| # Trapazoidal integration, with 0 first value so that the lengths match. See #88. | ||
| def integrate_dxdt_hat(dxdt_hat, dt): | ||
| """Wrapper for scipy.integrate.cumulative_trapezoid to integrate dxdt_hat that ensures | ||
| the integral has the same length | ||
| def integrate_dxdt_hat(dxdt_hat, _t): | ||
| """Wrapper for scipy.integrate.cumulative_trapezoid | ||
|
|
||
| :param np.array[float] dxdt_hat: estimate derivative of timeseries | ||
| :param float dt: time step in seconds | ||
| :param float _t: stepsize if given as a scalar or a vector of sample locations | ||
|
|
||
| :return: **x_hat** (np.array[float]) -- integral of dxdt_hat | ||
| """ | ||
| return np.hstack((0, scipy.integrate.cumulative_trapezoid(dxdt_hat)))*dt | ||
| return cumulative_trapezoid(dxdt_hat, initial=0)*_t if np.isscalar(_t) \ | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Turns out |
||
| else cumulative_trapezoid(dxdt_hat, x=_t, initial=0) | ||
|
|
||
|
|
||
| # Optimization routine to estimate the integration constant. | ||
|
|
@@ -118,7 +120,7 @@ def estimate_integration_constant(x, x_hat): | |
|
|
||
| :return: **integration constant** (float) -- initial condition that best aligns x_hat with x | ||
| """ | ||
| return scipy.optimize.minimize(lambda x0, x, xhat: np.linalg.norm(x - (x_hat+x0)), # fn to minimize in 1st argument | ||
| return minimize(lambda x0, x, xhat: np.linalg.norm(x - (x_hat+x0)), # fn to minimize in 1st argument | ||
| 0, args=(x, x_hat), method='SLSQP').x[0] # result is a vector, even if initial guess is just a scalar | ||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed the name of this thing, so kwarg breaks.