Skip to content

Commit 57d928e

Browse files
adding the z_score_scaler
1 parent 18e4182 commit 57d928e

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

docs/utils.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,41 @@ from damavand.damavand.utils import zoomed_fft_freq_axis
8484

8585
# Generating a frequency axis for zoomed frequency spectrum, covering from 0 Hz to 2500 Hz using 2500 points
8686
zoomed_freq_axis = zoomed_fft_freq_axis(0, 2500, 2500)
87+
```
88+
89+
## `z_score_scaler(signals, axis=1, return_df=True, eps=1e-8)`
90+
91+
### Z-score standardization of time-series signals
92+
93+
##### Arguments:
94+
- **signals**: A `pandas.DataFrame` or `numpy.ndarray` including signals in its rows.
95+
- **axis**: An `int` (`0` or `1`) specifying the normalization direction.
96+
- `axis=1` (default): each signal is independently standardized over time (row-wise).
97+
- `axis=0`: each time step is standardized across signals (column-wise).
98+
- **return_df**: A `bool` indicating whether to return a `pandas.DataFrame` when the input is a DataFrame.
99+
- **eps**: A small `float` added to the standard deviation to avoid division by zero.
100+
101+
##### Return Values:
102+
- A scaled `pandas.DataFrame` or `numpy.ndarray` (matching the input type by default), where each signal has zero mean and unit variance according to the selected axis.
103+
104+
##### Descriptions:
105+
This function applies **Z-score standardization** (also known as standardization or Z-score normalization) to time-series signals.
106+
Each signal (or time step) is centered by subtracting its mean and scaled by its standard deviation, improving numerical stability and convergence behavior during model training.
107+
108+
##### Usage example:
109+
110+
```Python
111+
# Importings
112+
import pandas as pd
113+
import numpy as np
114+
from damavand.damavand.augmentations import z_score_scaler
115+
116+
# Example signals (rows = signals, columns = time steps)
117+
signals = pd.DataFrame(np.random.randn(5, 1000))
118+
119+
# Apply row-wise Z-score standardization (each signal independently)
120+
signals_scaled = z_score_scaler(signals, axis=1)
121+
122+
# Convert output to NumPy array
123+
signals_scaled_np = z_score_scaler(signals, axis=1, return_df=False)
87124
```

0 commit comments

Comments
 (0)