Skip to content

Commit

Permalink
Improvements (#103)
Browse files Browse the repository at this point in the history
* add regularizer term to matrix equation, vectorize lppls class method and take abs of dt.

* bump version
  • Loading branch information
Joshwani authored Feb 15, 2024
1 parent 2c48a26 commit ec15640
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions lppls/lppls.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def __init__(self, observations):
@staticmethod
@njit
def lppls(t, tc, m, w, a, b, c1, c2):
return a + np.power(tc - t, m) * (b + ((c1 * np.cos(w * np.log(tc - t))) + (c2 * np.sin(w * np.log(tc - t)))))
dt = np.abs(tc - t) + 1e-8
return a + np.power(dt, m) * (b + ((c1 * np.cos(w * np.log(dt))) + (c2 * np.sin(w * np.log(dt)))))

def func_restricted(self, x, *args):
"""
Expand All @@ -49,7 +50,7 @@ def func_restricted(self, x, *args):
# print('type', type(res))
# print('func_restricted', res)

delta = [self.lppls(t, tc, m, w, a, b, c1, c2) for t in observations[0, :]]
delta = self.lppls(observations[0, :], tc, m, w, a, b, c1, c2)
delta = np.subtract(delta, observations[1, :])
delta = np.power(delta, 2)
return np.sum(delta)
Expand All @@ -64,8 +65,7 @@ def matrix_equation(observations, tc, m, w):
P = observations[1]
N = len(T)

# @TODO make taking tc - t or |tc - t| configurable
dT = np.abs(tc - T)
dT = np.abs(tc - T) + 1e-8
phase = np.log(dT)

fi = np.power(dT, m)
Expand Down Expand Up @@ -99,6 +99,8 @@ def matrix_equation(observations, tc, m, w):
[np.sum(yihi)]
])

matrix_1 += 1e-8 * np.eye(matrix_1.shape[0])

return np.linalg.solve(matrix_1, matrix_2)

def fit(self, max_searches, minimizer='Nelder-Mead', obs=None):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
long_description = fh.read()

setuptools.setup(name='lppls',
version='0.6.12',
version='0.6.13',
description='A Python module for fitting the LPPLS model to data.',
packages=['lppls'],
author='Josh Nielsen',
Expand Down

0 comments on commit ec15640

Please sign in to comment.