median_crossing_rate
timecave.data_characteristics.median_crossing_rate(ts)
Compute the series' median-crossing rate.
This function computes the median-crossing rate of a given time series. The median-crossing rate is defined as the rate at which the values of a time series change from being below its median value to above said value. In practice, the median 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
|
Median-crossing rate. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
See also
mean_crossing_rate Uses the mean instead of the median.
Notes
The median-crossing rate is similar to the mean-crossing rate, but it uses the median as a reference value. It can be computed from the following formula:
where \(n\) is the number of samples in the time series, \(a_i\) are its values, and \(Med\) represents its median. The formula for the mean-crossing rate can be found in [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 median_crossing_rate
>>> ts = np.array([0, 20, 0, 20, 0]);
>>> median_crossing_rate(ts)
1.0
>>> ts2 = np.ones(10);
>>> median_crossing_rate(ts2)
0.0
>>> ts3 = np.array([50, 50, 50, 0, 0]);
>>> median_crossing_rate(ts3)
0.25
>>> ts4 = np.array([0, 20, 5, 5, 5]);
>>> median_crossing_rate(ts4)
0.5
If the time series is neither an array nor a series, an exception is thrown:
>>> median_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
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 | |