diff --git a/docs/features/add-new-features.md b/docs/features/add-new-features.md index f27a7e3e..d718b474 100644 --- a/docs/features/add-new-features.md +++ b/docs/features/add-new-features.md @@ -147,37 +147,37 @@ The code to extract your behavioral features should be implemented in your provi ```python def rapids_features(sensor_data_files, day_segment, provider, filter_data_by_segment, *args, **kwargs): - acc_data = pd.read_csv(sensor_data_files["sensor_data"]) - requested_features = provider["FEATURES"] - # name of the features this function can compute - base_features_names = ["maxmagnitude", "minmagnitude", "avgmagnitude", "medianmagnitude", "stdmagnitude"] - # the subset of requested features this function can compute - features_to_compute = list(set(requested_features) & set(base_features_names)) + acc_data = pd.read_csv(sensor_data_files["sensor_data"]) + requested_features = provider["FEATURES"] + # name of the features this function can compute + base_features_names = ["maxmagnitude", "minmagnitude", "avgmagnitude", "medianmagnitude", "stdmagnitude"] + # the subset of requested features this function can compute + features_to_compute = list(set(requested_features) & set(base_features_names)) - acc_features = pd.DataFrame(columns=["local_segment"] + ["acc_rapids_" + x for x in features_to_compute]) - if not acc_data.empty: - acc_data = filter_data_by_segment(acc_data, day_segment) - + acc_features = pd.DataFrame(columns=["local_segment"] + ["acc_rapids_" + x for x in features_to_compute]) if not acc_data.empty: - acc_features = pd.DataFrame() - # get magnitude related features: magnitude = sqrt(x^2+y^2+z^2) - magnitude = acc_data.apply(lambda row: np.sqrt(row["double_values_0"] ** 2 + row["double_values_1"] ** 2 + row["double_values_2"] ** 2), axis=1) - acc_data = acc_data.assign(magnitude = magnitude.values) + acc_data = filter_data_by_segment(acc_data, day_segment) - if "maxmagnitude" in features_to_compute: - acc_features["acc_rapids_maxmagnitude"] = acc_data.groupby(["local_segment"])["magnitude"].max() - if "minmagnitude" in features_to_compute: - acc_features["acc_rapids_minmagnitude"] = acc_data.groupby(["local_segment"])["magnitude"].min() - if "avgmagnitude" in features_to_compute: - acc_features["acc_rapids_avgmagnitude"] = acc_data.groupby(["local_segment"])["magnitude"].mean() - if "medianmagnitude" in features_to_compute: - acc_features["acc_rapids_medianmagnitude"] = acc_data.groupby(["local_segment"])["magnitude"].median() - if "stdmagnitude" in features_to_compute: - acc_features["acc_rapids_stdmagnitude"] = acc_data.groupby(["local_segment"])["magnitude"].std() - - acc_features = acc_features.reset_index() + if not acc_data.empty: + acc_features = pd.DataFrame() + # get magnitude related features: magnitude = sqrt(x^2+y^2+z^2) + magnitude = acc_data.apply(lambda row: np.sqrt(row["double_values_0"] ** 2 + row["double_values_1"] ** 2 + row["double_values_2"] ** 2), axis=1) + acc_data = acc_data.assign(magnitude = magnitude.values) + + if "maxmagnitude" in features_to_compute: + acc_features["acc_rapids_maxmagnitude"] = acc_data.groupby(["local_segment"])["magnitude"].max() + if "minmagnitude" in features_to_compute: + acc_features["acc_rapids_minmagnitude"] = acc_data.groupby(["local_segment"])["magnitude"].min() + if "avgmagnitude" in features_to_compute: + acc_features["acc_rapids_avgmagnitude"] = acc_data.groupby(["local_segment"])["magnitude"].mean() + if "medianmagnitude" in features_to_compute: + acc_features["acc_rapids_medianmagnitude"] = acc_data.groupby(["local_segment"])["magnitude"].median() + if "stdmagnitude" in features_to_compute: + acc_features["acc_rapids_stdmagnitude"] = acc_data.groupby(["local_segment"])["magnitude"].std() + + acc_features = acc_features.reset_index() - return acc_features + return acc_features ``` ## New Features for Non-Existing Sensors diff --git a/docs/features/feature-introduction.md b/docs/features/feature-introduction.md index 88ce3c09..5d4b309f 100644 --- a/docs/features/feature-introduction.md +++ b/docs/features/feature-introduction.md @@ -26,10 +26,10 @@ Every phone or Fitbit sensor has a corresponding config section in `config.yaml` # 5) PANDA provider PANDA: - # 5.1) Parameters of RAPIDS provider of PHONE_ACCELEROMETER + # 5.1) Parameters of PANDA provider of PHONE_ACCELEROMETER COMPUTE: False VALID_SENSED_MINUTES: False - # 5.2) Features of RAPIDS provider of PHONE_ACCELEROMETER + # 5.2) Features of PANDA provider of PHONE_ACCELEROMETER FEATURES: exertional_activity_episode: ["sumduration", "maxduration", "minduration", "avgduration", "medianduration", "stdduration"] nonexertional_activity_episode: ["sumduration", "maxduration", "minduration", "avgduration", "medianduration", "stdduration"] @@ -38,15 +38,15 @@ Every phone or Fitbit sensor has a corresponding config section in `config.yaml` ``` ## Sensor Parameters -Each sensor configuration section has a `Parameters` subsection (see `#2` in the example). These are parameters that affect different aspects of how the raw data is download, and processed. The `TABLE` parameter exists for every sensor, but some sensors will have extra para meters like [`[PHONE_LOCATIONS]`](../phone-locations/). We explain these parameters in a table at the top of each sensor documentation page. +Each sensor configuration section has a `Parameters` subsection (see `#2` in the example). These are parameters that affect different aspects of how the raw data is downloaded, and processed. The `TABLE` parameter exists for every sensor, but some sensors will have extra parameters like [`[PHONE_LOCATIONS]`](../phone-locations/). We explain these parameters in a table at the top of each sensor documentation page. ## Sensor Providers -Each sensor configuration section can have zero, one or more behavioral feature **providers** (see `#2` in the example). A provider is a script created by the core RAPIDS team or other researchers that extracts behavioral features for that sensor. For this accelerometer example we have two providers RAPIDS (see `#4`) and PANDA (see `#5`). +Each sensor configuration section can have zero, one or more behavioral feature **providers** (see `#3` in the example). A provider is a script created by the core RAPIDS team or other researchers that extracts behavioral features for that sensor. In this example, accelerometer has two providers: RAPIDS (see `#4`) and PANDA (see `#5`). ### Provider Parameters Each provider has parameters that affect the computation of the behavioral features it offers (see `#4.1` or `#5.1` in the example). These parameters will include at least a `[COMPUTE]` flag that you switch to `True` to extract a provider's behavioral features. -We explain each provider parameter in a table under the `Parameters description` heading on each provider documentation page. +We explain every provider's parameter in a table under the `Parameters description` heading on each provider documentation page. ### Provider Features Each provider offers a set of behavioral features (see `#4.2` or `#5.2` in the example). For some providers these features are grouped in an array (like those for `RAPIDS` provider in `#4.2`) but for others they are grouped in a collection of arrays (like those for `PANDAS` provider in `#5.2`) depending on the meaning and purpose of those features. In either case you can delete the features you are not interested in and they will not be included in the sensor's output feature file.