Statistical Features

For activity recognition based on learning algorithms like support vector machine (SVM), decision tree, random forest, multi-layer perceptron. [Krishnan2014] investigated various sliding window approaches to generate such statistical features.

Window Duration

class pyActLearn.CASAS.stat_features.WindowDuration(normalized=False)[source]

Bases: pyActLearn.CASAS.stat_features.FeatureTemplate

Length of the window.

Any sliding window should have a duration of less than half a day. If it is, it is probable that there some missing sensor events, so the statistical features calculated for such a window is invalid.

Parameters:normalized (bool) – If true, the hour is normalized between 0 to 1.
get_feature_value(data_list, cur_index, window_size, sensor_info, sensor_name=None)[source]

Get the duration of the window in seconds. Invalid if the duration is greater than half a day.

Note

Please refer to get_feature_value() for information about parameters.

Last Sensor

class pyActLearn.CASAS.stat_features.LastSensor(per_sensor=False)[source]

Bases: pyActLearn.CASAS.stat_features.FeatureTemplate

Sensor ID of the last sensor event.rst of the window.

For algorithms like decision trees and hidden markov model, sensor ID can be directly used as features. However, in other algorithms such as multi-layer perceptron, or support vector machine, the sensor ID needs to be binary coded.

Parameters:per_sensor (bool) – True if the sensor ID needs to be binary coded.
get_feature_value(data_list, cur_index, window_size, sensor_info, sensor_name=None)[source]

Get the sensor which fired the last event.rst in the sliding window.

If it is configured as per-sensor feature, it returns 1 if the sensor specified triggers the last event.rst in the window. Otherwise returns 0. If it is configured as a non-per-sensor feature, it returns the index of the index corresponding to the dominant sensor name that triggered the last event.rst.

Note

Please refer to get_feature_value() for information about parameters.

Hour of the Event

class pyActLearn.CASAS.stat_features.EventHour(normalized=False)[source]

Bases: pyActLearn.CASAS.stat_features.FeatureTemplate

Hour of last event.rst.

It returns the hour of last sensor event.rst in the sliding window. If normalized is set to True, the hour is divided by 24, so that the value is bounded between 0 to 1.

Parameters:normalized (bool) – If true, the hour is normalized between 0 to 1.
get_feature_value(data_list, cur_index, window_size, sensor_info, sensor_name=None)[source]

Get the hour when the last sensor event.rst in the window occurred

Note

Please refer to get_feature_value() for information about parameters.

Seconds of the Event

class pyActLearn.CASAS.stat_features.EventSeconds(normalized=False)[source]

Bases: pyActLearn.CASAS.stat_features.FeatureTemplate

Seconds of last event.rst.

The time of the hour (in seconds) of the last sensor event.rst in the window. If normalized is True, the seconds is divided by 3600.

Parameters:normalized (bool) – If true, the hour is normalized between 0 to 1.
get_feature_value(data_list, cur_index, window_size, sensor_info, sensor_name=None)[source]

Get the time within an hour when the last sensor event.rst in the window occurred (in seconds)

Note

Please refer to get_feature_value() for information about parameters.

Sensor Count

class pyActLearn.CASAS.stat_features.SensorCount(normalized=False)[source]

Bases: pyActLearn.CASAS.stat_features.FeatureTemplate

Counts the occurrence of each sensor within the sliding window.

The count of occurrence of each sensor is normalized to the length (total number of events) of the window if the normalized is set to True.

Parameters:normalized (bool) – If true, the count of each sensor is normalized between 0 to 1.
get_feature_value(data_list, cur_index, window_size, sensor_info, sensor_name=None)[source]

Counts the number of occurrence of the sensor specified in current window.

Sensor Elapse Time

class pyActLearn.CASAS.stat_features.SensorElapseTime(normalized=False)[source]

Bases: pyActLearn.CASAS.stat_features.FeatureTemplate

The time elapsed since last firing (in seconds)

get_feature_value(data_list, cur_index, window_size, sensor_info, sensor_name=None)[source]

Get elapse time of specified sensor in seconds

Dominant Sensor

class pyActLearn.CASAS.stat_features.DominantSensor(per_sensor=False)[source]

Bases: pyActLearn.CASAS.stat_features.FeatureTemplate

Dominant Sensor of current window.

The sensor that fires the most amount of sensor event.rst in the current window.

Parameters:per_sensor (bool) – True if the sensor ID needs to be binary coded.
get_feature_value(data_list, cur_index, window_size, sensor_info, sensor_name=None)[source]

If per_sensor is True, returns 1 with corresponding sensor Id. otherwise, return the index of last sensor in the window

Feature Template

class pyActLearn.CASAS.stat_features.FeatureTemplate(name, description, enabled=True, normalized=True, per_sensor=False, routine=None)[source]

Bases: object

Statistical Feature Template

Parameters:
  • name (str) – Feature name.
  • description (str) – Feature description.
  • per_sensor (bool) – If the feature is calculated for each sensor.
  • enabled (bool) – If the feature is enabled.
  • routine (FeatureRoutineTemplate) – Routine structure.
  • normalized (bool) – If the value of feature needs to be normalized.
Variables:
  • name (str) – Feature name.
  • description (str) – Feature description.
  • index (int) – Feature index.
  • normalized (bool) – If the value of feature needs to be normalized.
  • per_sensor (bool) – If the feature is calculated for each sensor.
  • enabled (bool) – If the feature is enabled.
  • routine (FeatureRoutineTemplate) – Routine structure.
  • _is_value_valid (bool) – If the value calculated is valid
get_feature_value(data_list, cur_index, window_size, sensor_info, sensor_name=None)[source]

Abstract method to get feature value

Parameters:
  • data_list (list) – List of sensor data.
  • cur_index (int) – Index of current data record.
  • window_size (int) – Sliding window size.
  • sensor_info (dict) – Dictionary containing sensor index information.
  • sensor_name (str) – Sensor Name.
Returns:

feature value

Return type:

double

is_value_valid

Statistical feature value valid check

Due to errors and failures of sensors, the statistical feature calculated may go out of bound. This abstract method is used to check if the value calculated is valid. If not, it will not be inserted into feature vectors.

Returns:True if the result is valid.
Return type:bool

Feature Update Routine Template

class pyActLearn.CASAS.stat_features.FeatureRoutineTemplate(name, description, enabled=True)[source]

Bases: object

Feature Routine Class

A routine that calculate statistical features every time the window slides.

Variables:
  • name (str) – Feature routine name.
  • description (str) – Feature routine description.
  • enabled (str) – Feature routine enable flag.
clear()[source]

Clear Internal Data Structures if recalculation is needed

update(data_list, cur_index, window_size, sensor_info)[source]

Abstract update method

For some features, we will update some statistical data every time we move forward a data record, instead of going back through the whole window and try to find the answer. This function will be called every time we advance in data record.

Parameters:
  • data_list (list) – List of sensor data.
  • cur_index (int) – Index of current data record.
  • window_size (int) – Sliding window size.
  • sensor_info (dict) – Dictionary containing sensor index information.