Skip to content

Commit

Permalink
add subclass for quantile regression.
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshwani-broadcom committed Jan 4, 2024
1 parent 74db49a commit 7f2779c
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions lppls/lppls_q.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from lppls.lppls import LPPLS
import numpy as np


class QLPPLS(LPPLS):
def __init__(self, observations, q=0.5):
super().__init__(observations)
self.q = q

def func_restricted(self, x, *args):
"""
Finds the least absolute differences adjusted for the q-dependent loss function.
Args:
x(np.ndarray): 1-D array with shape (n,).
args: Tuple of the fixed parameters needed to completely specify the function.
Returns:
(float)
"""

tc = x[0]
m = x[1]
w = x[2]
observations = args[0]

rM = self.matrix_equation(observations, tc, m, w)
a, b, c1, c2 = rM[:, 0].tolist()

delta = [self.lppls(t, tc, m, w, a, b, c1, c2) for t in observations[0, :]]
delta = np.subtract(delta, observations[1, :])

# Use the L1 norm (sum of absolute differences) instead of the L2 norm
# Apply the q-dependent loss function using the given quantile
loss = np.sum([-(1 - self.q) * e if e < 0 else self.q * e for e in np.abs(delta)])

return loss

0 comments on commit 7f2779c

Please sign in to comment.