mean_crossing_rate
timecave.data_characteristics.mean_crossing_rate(ts)
Compute the series' mean-crossing rate.
This function computes the mean-crossing rate of a given time series. The mean-crossing rate is defined as the rate at which the values of a time series change from being below its mean value to above said value. In practice, the mean is subtracted from the time series, and the zero-crossing rate is then computed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ts |
ndarray | Series
|
Univariate time series. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Mean-crossing rate. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
See also
median_crossing_rate: Uses the median instead of the mean.
Notes
The mean-crossing rate is defined as the fraction of times a mean-crossing takes place in the whole time series. A mean-crossing occurs when two adjacent values have different signs with respect to the mean (i.e. the first one is below the mean while the second one is above it, and vice-versa).
where \(n\) is the number of samples in the time series, \(a_i\) are its values, and \(\mu\) represents its mean. For more details, please refer to [1].
References
1
Bohdan Myroniv, Cheng-Wei Wu, Yi Ren, Albert Christian, Ensa Bajo, and Yu-chee Tseng. Analyzing user emotions via physiology signals. Data Science and Pattern Recognition, 2, 12 2017.
Examples:
>>> import numpy as np
>>> from timecave.data_characteristics import mean_crossing_rate
>>> ts = np.array([0, 20, 0, 20, 0]);
>>> mean_crossing_rate(ts)
1.0
>>> ts2 = np.ones(10);
>>> mean_crossing_rate(ts2)
0.0
>>> ts3 = np.array([50, 50, 50, 0, 0]);
>>> mean_crossing_rate(ts3)
0.25
If the time series is neither an array nor a series, an exception is thrown:
>>> mean_crossing_rate([0, 1, 2])
Traceback (most recent call last):
...
TypeError: Time series must be either a Numpy array or a Pandas series.
Source code in timecave/data_characteristics.py
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 | |