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 toTrue
, 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
isTrue
, 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.
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)
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.
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: 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: 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
- name (
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: -
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:
-