File size: 552 Bytes
2dce10c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | from __future__ import annotations
import numpy as np
from .config import SIGMA_EPS
def linear_interpolate(row: np.ndarray) -> np.ndarray:
row = np.asarray(row, dtype=np.float64).copy()
nan = ~np.isfinite(row)
if not nan.any(): return row
if nan.all(): return np.zeros_like(row)
idx = np.arange(row.shape[0])
row[nan] = np.interp(idx[nan], idx[~nan], row[~nan])
return row
def revin(x, mu, sigma, reverse=False):
s = np.where(sigma < SIGMA_EPS, 1.0, sigma)
return x*s+mu if reverse else (x-mu)/s
|