def soft_extremum_min_max(
pred_extrema: pd.Series, alpha: float
) -> tuple[float, float]:
+ if alpha < 0:
+ raise ValueError("alpha must be non-negative")
pred_minima, pred_maxima = QuickAdapterRegressorV3.get_pred_min_max(
pred_extrema
)
return np.nan
if np.isclose(alpha, 0):
return np.mean(np_array)
- scaled_data = alpha * np_array
- max_scaled_data = np.max(scaled_data)
- if np.isinf(max_scaled_data):
- return np_array[np.argmax(scaled_data)]
- shifted_exponentials = np.exp(scaled_data - max_scaled_data)
+ scaled_np_array = alpha * np_array
+ max_scaled_np_array = np.max(scaled_np_array)
+ if np.isinf(max_scaled_np_array):
+ return np_array[np.argmax(scaled_np_array)]
+ shifted_exponentials = np.exp(scaled_np_array - max_scaled_np_array)
numerator = np.sum(np_array * shifted_exponentials)
denominator = np.sum(shifted_exponentials)
if denominator == 0:
self._label_params[pair]["label_natr_ratio"] = label_natr_ratio
def get_label_natr_ratio_percent(self, pair: str, percent: float) -> float:
+ if not isinstance(percent, float) or not (0.0 <= percent <= 1.0):
+ raise ValueError(
+ f"Invalid percent value: {percent}. It should be a float between 0 and 1"
+ )
return self.get_label_natr_ratio(pair) * percent
@staticmethod