-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Avik Basu <[email protected]>
- Loading branch information
Showing
4 changed files
with
117 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import os | ||
from collections.abc import Sequence | ||
from typing import Optional | ||
|
||
import numpy as np | ||
import numpy.typing as npt | ||
|
||
from numalogic.transforms import expmov_avg_aggregator | ||
|
||
|
||
EXP_MOV_AVG_BETA = float(os.getenv("EXP_MOV_AVG_BETA", "0.6")) | ||
|
||
|
||
def aggregate_window(y: npt.NDArray[float]) -> npt.NDArray[float]: | ||
"""Aggregate over window/sequence length.""" | ||
return np.apply_along_axis( | ||
func1d=expmov_avg_aggregator, axis=0, arr=y, beta=EXP_MOV_AVG_BETA | ||
).reshape(-1) | ||
|
||
|
||
def aggregate_features( | ||
y: npt.NDArray[float], weights: Optional[Sequence[float]] = None | ||
) -> npt.NDArray[float]: | ||
"""Aggregate over features.""" | ||
if weights: | ||
return np.average(y, weights=weights, axis=1, keepdims=True) | ||
return np.mean(y, axis=1, keepdims=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters