|
| 1 | +""""Functions for computing Jacobian matrices to be used during fitting.""" |
| 2 | + |
| 3 | +import numpy as np |
| 4 | + |
| 5 | +################################################################################################### |
| 6 | +################################################################################################### |
| 7 | + |
| 8 | +## Periodic fit functions |
| 9 | + |
| 10 | +def jacobian_gauss(xs, *params): |
| 11 | + """Create the Jacobian matrix for the Guassian function.""" |
| 12 | + |
| 13 | + jacobians = [] |
| 14 | + for a, b, c in zip(*[iter(params)] * 3): |
| 15 | + |
| 16 | + sub = b * np.exp((-(((-a + xs)**2) / (2 * c**2)))) |
| 17 | + |
| 18 | + jacobian = np.hstack([ |
| 19 | + (sub * (-a + xs) / c**2).reshape(-1, 1), |
| 20 | + np.exp(-(-a + xs)**2 / (2 * c**2)).reshape(-1, 1), |
| 21 | + (sub * (-a + xs)**2 / c**3).reshape(-1, 1), |
| 22 | + ]) |
| 23 | + jacobians.append(jacobian) |
| 24 | + |
| 25 | + return np.hstack(jacobians) |
| 26 | + |
| 27 | + |
| 28 | +## Aperiodic fit functions |
| 29 | + |
| 30 | +def jacobian_expo(xs, *params): |
| 31 | + """Create the Jacobian matrix for the exponential function.""" |
| 32 | + |
| 33 | + a, b, c = params |
| 34 | + jacobian = np.hstack([ |
| 35 | + np.ones([len(xs), 1]), |
| 36 | + - (1 / (b + xs**c)).reshape(-1, 1), |
| 37 | + -((xs**c * np.log10(xs)) / (b + xs**c)).reshape(-1, 1), |
| 38 | + ]) |
| 39 | + |
| 40 | + return jacobian |
| 41 | + |
| 42 | + |
| 43 | +def jacobian_expo_nk(xs, *params): |
| 44 | + """Create the Jacobian matrix for the exponential no-knee function.""" |
| 45 | + |
| 46 | + jacobian = np.hstack([ |
| 47 | + np.ones([len(xs), 1]), |
| 48 | + (-np.log10(xs) / np.log10(10)).reshape(-1, 1), |
| 49 | + ]) |
| 50 | + |
| 51 | + return jacobian |
0 commit comments