GAA-UAM / scikit-fda

Functional Data Analysis Python package
https://fda.readthedocs.io
BSD 3-Clause "New" or "Revised" License
309 stars 58 forks source link

Add standard deviation as a function #566

Closed pcuestas closed 1 year ago

pcuestas commented 1 year ago

Added std as a function using single dispatch in the skfda.exploratory.stats module.

The function takes two arguments: a FData object and a ddof (Delta Degrees Of Freedom) integer. By default, ddof=1. Rationale behind this decision has been that these functions (stats.cov, stats.var, stats.std) are meant to be used for statistical (exploratory) purposes, and not for Maximum Likelihood algorithms. The default is different from numpy.std (which uses ddof=1). pandas.DataFrame.std and scipy.stats.variation use ddof=1.

The approach taken to calculate the std of a FDataBasis object is the more direct one that we discussed which does not use the covariance object. Instead, a matrix multiplication is performed to calculate the pointwise variance on an arbitrary point of the domain:

https://github.com/GAA-UAM/scikit-fda/blob/6eada7287e7e1a6098553714cc9a6a06d7b34eef/skfda/exploratory/stats/_stats.py#L153-L156

Tests included to cover the general $\mathbb{R}^p \to \mathbb{R}^q$ case for both FDataGrid and FDataBasis objects.

Closes https://github.com/GAA-UAM/scikit-fda/issues/541.

codecov[bot] commented 1 year ago

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (4fe909c) 86.03% compared to head (3115a6d) 86.10%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## develop #566 +/- ## =========================================== + Coverage 86.03% 86.10% +0.06% =========================================== Files 148 149 +1 Lines 11719 11789 +70 =========================================== + Hits 10083 10151 +68 - Misses 1636 1638 +2 ``` | [Files](https://app.codecov.io/gh/GAA-UAM/scikit-fda/pull/566?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GAA-UAM) | Coverage Δ | | |---|---|---| | [skfda/tests/test\_stats\_std.py](https://app.codecov.io/gh/GAA-UAM/scikit-fda/pull/566?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GAA-UAM#diff-c2tmZGEvdGVzdHMvdGVzdF9zdGF0c19zdGQucHk=) | `100.00% <100.00%> (ø)` | | | [skfda/exploratory/stats/\_stats.py](https://app.codecov.io/gh/GAA-UAM/scikit-fda/pull/566?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GAA-UAM#diff-c2tmZGEvZXhwbG9yYXRvcnkvc3RhdHMvX3N0YXRzLnB5) | `87.17% <94.44%> (+1.93%)` | :arrow_up: | | [skfda/\_utils/\_utils.py](https://app.codecov.io/gh/GAA-UAM/scikit-fda/pull/566?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GAA-UAM#diff-c2tmZGEvX3V0aWxzL191dGlscy5weQ==) | `82.29% <80.00%> (+0.22%)` | :arrow_up: |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.