event-budget-prediction / inv_transform.py
ov-pinka's picture
Upload 5 files
3fedfaa verified
raw
history blame
389 Bytes
import numpy as np
def inv_yeojohnson(y, lmbda):
if lmbda == 0:
# Lambda = 0
return np.where(y >= 0, np.exp(y) - 1, 1 - np.exp(-y))
else:
# Lambda != 0
pos_part = np.where(y >= 0, (y * lmbda + 1) ** (1 / lmbda) - 1, 0)
neg_part = np.where(y < 0, 1 - (-(2 - lmbda) * y + 1) ** (1 / (2 - lmbda)), 0)
return pos_part + neg_part