Skip to content

Commit

Permalink
Merge branch 'asymptote_transform' of https://github.com/cvxgrp/spcqe
Browse files Browse the repository at this point in the history
…into asymptote_transform

merging new changes
  • Loading branch information
pluflou committed Jan 10, 2025
2 parents 8130ed4 + 7de7f95 commit 1c5d549
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 105 deletions.
191 changes: 125 additions & 66 deletions notebooks/Aramis/extrapolation_demo.ipynb

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/spcqe/extrapolate_asymptotic.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from scipy.interpolate import interp1d

dist = sps.norm()
XSOLAR = 0
XSOLAR = -0.1
YSOLAR = dist.ppf(0.99999)

def get_asymptote_parameters_out(x0, _y0, x1, _y1, yasympt):
Expand Down Expand Up @@ -182,14 +182,13 @@ def plot_tails(ax, sig, quantiles, fit_quantiles, transf, method, key, index, ex
elif method == 'linear':
extrap_ys = linear_interp(extrap_values)
sig_values = np.linspace(sig_m, sig_M, 1000)
ax.scatter(fit_quantiles[index], dist.ppf(quantiles), color='C3', marker='+', s=40, label='quantiles setpoints')
if h_per_day is not None:
idxs_days = np.arange(-n_days, n_days+1, 1) * h_per_day + index
idxs_days = np.array([i for i in idxs_days if i != index])
idxs_hours = np.arange(-n_hours, n_hours+1, 1) + index
idxs_hours = np.array([i for i in idxs_hours if i != index])
ax.scatter(sig[idxs_days], transf[idxs_days], color='green', s=20, label='nearby days')
ax.scatter(sig[idxs_hours], transf[idxs_hours], color='orange', s=20, label='nearby hours')
ax.scatter(sig[idxs_days], transf[idxs_days], color='green', s=30, label='nearby days')
ax.scatter(sig[idxs_hours], transf[idxs_hours], color='orange', s=30, label='nearby hours')
ax.axvline(sig[index], color='C3', linestyle='--', label='value to transform')
ax.plot(sig_values, linear_interp(sig_values), label='linear transform')
ax.plot(
Expand All @@ -199,6 +198,7 @@ def plot_tails(ax, sig, quantiles, fit_quantiles, transf, method, key, index, ex
color='black',
label='extrapolation transform'
)
ax.scatter(fit_quantiles[index], dist.ppf(quantiles), color='C3', marker='+', s=150, label='quantiles setpoints')
ax.scatter(sig[index], transf[index], color='black', marker='x', label='transformed value')
ax.set_title(f'Transfer function from dilated signal to normal distribution - {key} tail')
ax.legend()
Expand Down
37 changes: 2 additions & 35 deletions src/spcqe/quantiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,40 +352,6 @@ def inverse_fit_extrapolate(self, X, Z, new_quantiles):

return Z

# TODO: not used anymore. Should be removed ?
# def x_expand(self, xi, tix):
# """
#
# """
# xin = np.atleast_1d(xi)
# h1 = np.ones_like(xin)
# h2 = xin
# h3up = [np.clip(xin - kn, 0, np.inf) for kn in self.fit_quantiles[tix][1:-1]]
# basis = np.r_[[h1, h2] + h3up].T
# return basis

# TODO: not used anymore. Should be removed ?
# def score(self, X, y=None):
# data = np.asarray(X)
# if len(data) != self.length and y is None:
# raise ValueError(
# "If not transforming the original fit data set, a time index must be passed as y"
# )
# # get correct basis matrix and quantile estimates for time period of prediction
# if y is not None:
# new_quantiles = self.predict(y)
# else:
# new_quantiles = self.fit_quantiles
# data = data[:, np.newaxis]
# q = self.quantiles[np.newaxis, :]
# score = np.sum(
# np.trapz(
# 0.5 * np.abs(data - new_quantiles) + (q - 0.5) * (data - new_quantiles),
# x=self.quantiles,
# )
# )
# return score

def extend_basis(self, t):
"""
Extend the basis matrix to a new time index.
Expand All @@ -398,11 +364,12 @@ def extend_basis(self, t):
self.num_harmonics,
t,
self.periods,
standing_wave=self.standing_wave,
trend=self.trend,
max_cross_k=self.max_cross_k,
custom_basis=self.custom_basis,
)
return new_basis
# TODO: check if this is the correct way to extend the basis
else:
raise NotImplementedError(
"Extending the basis to time before the training data not currently supported"
Expand Down

0 comments on commit 1c5d549

Please sign in to comment.