Make pdf_transfer_1d more readable
This commit is contained in:
parent
51360171c4
commit
a7cdd22619
1 changed files with 18 additions and 7 deletions
|
|
@ -1,13 +1,24 @@
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
def pdf_transfer_1d(pX: np.ndarray, pY: np.ndarray) -> np.ndarray:
|
EPSILON = np.finfo(float).eps
|
||||||
PX = np.cumsum(pX + np.finfo(float).eps)
|
|
||||||
PX /= PX[-1]
|
|
||||||
|
|
||||||
PY = np.cumsum(pY + np.finfo(float).eps)
|
|
||||||
PY /= PY[-1]
|
|
||||||
|
|
||||||
f = np.interp(PX, PY, np.arange(len(pX)))
|
def pdf_transfer_1d(
|
||||||
|
source_y: np.ndarray, target_y: np.ndarray, target_x: np.ndarray = None
|
||||||
|
) -> np.ndarray:
|
||||||
|
"""
|
||||||
|
return the best source_x-es
|
||||||
|
"""
|
||||||
|
cumulative_source = np.cumsum(source_y).astype(np.float64)
|
||||||
|
cumulative_source /= cumulative_source[-1]
|
||||||
|
|
||||||
return f
|
cumulative_target = np.cumsum(target_y).astype(np.float64)
|
||||||
|
cumulative_target /= cumulative_target[-1]
|
||||||
|
|
||||||
|
cumulative_transfered = np.interp(
|
||||||
|
cumulative_source,
|
||||||
|
cumulative_target,
|
||||||
|
np.arange(len(cumulative_source)) if target_x is None else target_x,
|
||||||
|
)
|
||||||
|
return cumulative_transfered
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue