You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I started using tsfel. My main goal is custom feature creation. I could not make this work. I want to use both the built-in features AND custom features in addition / jointly.
This resulted in a custom feature json as intended based on the following custom feature custom_features.py file I provide the feature_path to:
import numpy as np
from tsfel.feature_extraction import set_domain
@set_domain("domain", "temporal")
def p2p(signal, fs):
"""Description of your feature.
Parameters
----------
signal:
The time series to calculate the feature of.
param:
Parameters of your feature (optional)
Returns
-------
float
Calculated feature
"""
# Feature implementation
p2p = np.max(signal) - np.min(signal)
return p2p
runs through and then yields all the standard tsfel features, but not my custom p2p feature - I cannot retrieve my custom feature. There is no error message or warning.
2) Downloading the tsfel repository and run it via "pip install --editable ."
I tried this for debugging/to see where things get lost. There were several issues with this approach:
I use the same function calls as described in 1). To install the package, I had to first add package_dir={"":"tsfel"} to the setup.py file. Otherwise it would not install.
Calling tsfel.add_feature_json(features_path, json_path) then surprisingly failed upon the complexity computation compute_complexity call in add_personal_features.py, line 102 . Tracing down the issue in compute_complexity, I can see that my custom feature is accessed and computed with the wave function test signal in calculate_complexity.py. There, compute_complexityis executed and in line 124:
is called. This produces an error in `calc_features.py', line 470 that says "invalid index to scalar variable".
I can confirm that eval_result = locals()[func_total](signal_window, **parameters_total) in line 465 of calc_features.py yields the proper output for my custom feature, a scalar with value "1" (i.e. the peak to peak value for a wave signal with unit amplitude). In line 470 that scalar then is indexed via len(eval_result[ax].shape) and naturally, that scalar value of "1" cannot be indexed. If, instead of just returning the p2p value in my custom feature definition, I return np.array([p2p]), I can circumvent that issue, but it seems unnatural to manipulate the return from my custom feature definition into this. Also, for the built-in features, this does not seem necessary either.
However, from 1) I do have a valid json file that I can use as a workaround for the above error. Still, this behaviour is surprising, at least to me.
Proceeding with debugging, I find that in calc_features.py, lines 405ff. the custom-feature-related files are executed. However, browsing the domain_feats in line 430,
domain_feats = dict_features[_type].keys()
does not show my custom feature "p2p". In order to have it computed in the following feature computation loop, it should be included in domain_feats, if I understand the code correctly. Between lines 405 and 430, there is no code for integrating any custom features into "domain_feats" which I take as that custom features cannot be computed as of today.
Can you confirm this? If so, why is this not apparent from the docs?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I started using tsfel. My main goal is custom feature creation. I could not make this work. I want to use both the built-in features AND custom features in addition / jointly.
I tried:
1) "pip install tsfel"
Creating a custom feature json works with
and creates the desired, non-empty json:
This resulted in a custom feature json as intended based on the following custom feature
custom_features.py
file I provide the feature_path to:Calling tsfel by
runs through and then yields all the standard tsfel features, but not my custom p2p feature - I cannot retrieve my custom feature. There is no error message or warning.
2) Downloading the tsfel repository and run it via "pip install --editable ."
I tried this for debugging/to see where things get lost. There were several issues with this approach:
I use the same function calls as described in 1). To install the package, I had to first add
package_dir={"":"tsfel"}
to the setup.py file. Otherwise it would not install.Calling
tsfel.add_feature_json(features_path, json_path)
then surprisingly failed upon the complexity computationcompute_complexity
call inadd_personal_features.py
, line 102 . Tracing down the issue incompute_complexity
, I can see that my custom feature is accessed and computed with the wave function test signal incalculate_complexity.py
. There,compute_complexity
is executed and in line 124:calc_window_features(one_feat_dict, wave[: int(ti)], fs, features_path=features_path)
is called. This produces an error in `calc_features.py', line 470 that says "invalid index to scalar variable".
I can confirm that
eval_result = locals()[func_total](signal_window, **parameters_total)
in line 465 ofcalc_features.py
yields the proper output for my custom feature, a scalar with value "1" (i.e. the peak to peak value for a wave signal with unit amplitude). In line 470 that scalar then is indexed vialen(eval_result[ax].shape)
and naturally, that scalar value of "1" cannot be indexed. If, instead of just returning the p2p value in my custom feature definition, I returnnp.array([p2p])
, I can circumvent that issue, but it seems unnatural to manipulate the return from my custom feature definition into this. Also, for the built-in features, this does not seem necessary either.However, from 1) I do have a valid json file that I can use as a workaround for the above error. Still, this behaviour is surprising, at least to me.
domain_feats = dict_features[_type].keys()
does not show my custom feature "p2p". In order to have it computed in the following feature computation loop, it should be included in domain_feats, if I understand the code correctly. Between lines 405 and 430, there is no code for integrating any custom features into "domain_feats" which I take as that custom features cannot be computed as of today.
Can you confirm this? If so, why is this not apparent from the docs?
Beta Was this translation helpful? Give feedback.
All reactions