Skip to content

Commit 23f85da

Browse files
committed
changed naming convention to append _raw when one of zscore is True and other is False in config
1 parent 0d97340 commit 23f85da

3 files changed

Lines changed: 50 additions & 6 deletions

File tree

pyhctsa/Configurations/distribution.yaml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,22 @@ Distribution:
167167
configs:
168168
- zscore: False
169169
hctsa_name: DN_Burstiness
170-
ordered_args:
170+
ordered_args:
171+
172+
Moments:
173+
base_name: Moments
174+
labels:
175+
- distribution
176+
- moment
177+
- shape
178+
dependencies:
179+
- scipy
180+
configs:
181+
- theMom: [3, 4, 5, 6, 7, 8, 9, 10, 11]
182+
zscore: True
183+
- theMom: [3, 4, 5, 6, 7, 8, 9, 10, 11]
184+
zscore: False
185+
hctsa_name: DN_Moments
186+
ordered_args: ["theMom"]
187+
188+

pyhctsa/FeatureCalculator/calculator.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,30 @@ def _build_feature_funcs(self):
5858
ordered_args = feature_config.get("ordered_args", [])
5959
configs = feature_config.get("configs", [{}])
6060
if isinstance(configs, list) and configs and isinstance(configs[0], dict):
61+
# Check if zscore varies
62+
zscore_values = [conf.get("zscore", False) for conf in configs]
63+
zscore_varies = len(set(zscore_values)) > 1
6164
for conf in configs:
6265
zscore = conf.pop("zscore", False) if "zscore" in conf else False
6366
absval = conf.pop("abs", False) if "abs" in conf else False
64-
label = f"{module_key}_{feature_name}"
6567
if conf:
6668
keys, values = zip(*[(k, v if isinstance(v, list) else [v]) for k, v in conf.items()])
6769
for combo in product(*values):
6870
combo_dict = dict(zip(keys, combo))
71+
label = base_name
6972
if ordered_args:
70-
label = base_name + "_" + "_".join(
71-
_format_param_value(combo_dict[arg]) for arg in ordered_args)
73+
label += "_" + "_".join(_format_param_value(combo_dict[arg]) for arg in ordered_args)
7274
else:
73-
label = base_name + "_" + "_".join(f"{k}{v}" for k, v in combo_dict.items())
75+
label += "_" + "_".join(f"{k}{_format_param_value(v)}" for k, v in combo_dict.items())
76+
# Only append "_raw" if zscore varies and zscore is False
77+
if zscore_varies and not zscore:
78+
label += "_raw"
7479
decorated_func = preprocess_decorator(zscore, absval)(op_func)
7580
feature_funcs[label] = partial(decorated_func, **combo_dict)
7681
else:
7782
label = base_name
83+
if zscore_varies and not zscore:
84+
label += "_raw"
7885
decorated_func = preprocess_decorator(zscore, absval)(op_func)
7986
feature_funcs[label] = decorated_func
8087
else:
@@ -113,4 +120,3 @@ def extract(self, data : ArrayLike):
113120
elapsed = time.perf_counter() - start_time
114121
print(f"Feature extraction completed in {elapsed:.3f} seconds.")
115122
return results
116-

pyhctsa/Operations/Distribution.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,3 +435,23 @@ def Burstiness(y: ArrayLike) -> Dict[str, float]:
435435
out = {'B': B, 'B_Kim': B_Kim}
436436

437437
return out
438+
439+
def Moments(y : ArrayLike, theMom : int = 0) -> float:
440+
"""
441+
A moment of the distribution of the input time series.
442+
Normalizes by the standard deviation.
443+
444+
Parameters
445+
----------
446+
y : array-like
447+
Input time series or data vector
448+
theMom: int, optional
449+
The moment to calculate. Default is 0.
450+
451+
Returns
452+
-------
453+
float
454+
The calculated moment.
455+
"""
456+
y = np.asarray(y)
457+
return stats.moment(y, theMom) / np.std(y, ddof=1)

0 commit comments

Comments
 (0)