Skip to content

Commit

Permalink
Set correction=0 by default
Browse files Browse the repository at this point in the history
(and explicitly set the correction value where it was not set,
to avoid changing the previous behavior of the modules)
  • Loading branch information
pcuestas committed Oct 12, 2023
1 parent 7b0c0b7 commit 93fdf3d
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 24 deletions.
8 changes: 4 additions & 4 deletions skfda/exploratory/stats/_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ def mean(
return (X * weight).sum()


def var(X: FData, correction: int = 1) -> FDataGrid:
def var(X: FData, correction: int = 0) -> FDataGrid:
"""
Compute the variance of a set of samples in a FData object.
Args:
X: Object containing all the set of samples whose variance is desired.
correction: degrees of freedom adjustment. The divisor used in the
calculation is `N - correction`, where `N` represents the number of
elements. Default: `1`.
elements. Default: `0`.
Returns:
Variance of all the samples in the original object, as a
Expand All @@ -78,7 +78,7 @@ def gmean(X: FDataGrid) -> FDataGrid:

def cov(
X: FData,
correction: int = 1,
correction: int = 0,
) -> Callable[[NDArrayFloat, NDArrayFloat], NDArrayFloat]:
"""
Compute the covariance.
Expand All @@ -90,7 +90,7 @@ def cov(
X: Object containing different samples of a functional variable.
correction: degrees of freedom adjustment. The divisor used in the
calculation is `N - correction`, where `N` represents the number of
elements. Default: `1`.
elements. Default: `0`.
Returns:
Expand Down
2 changes: 2 additions & 0 deletions skfda/inference/anova/_anova_oneway.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ def _anova_bootstrap(
cov_est = concatenate(fd_grouped).cov(
grid_points,
grid_points,
correction=1,
)
k_est = [cov_est] * len(fd_grouped)
else:
Expand All @@ -228,6 +229,7 @@ def _anova_bootstrap(
fdg.cov(
grid_points,
grid_points,
correction=1,
)
for fdg in fd_grouped
]
Expand Down
2 changes: 2 additions & 0 deletions skfda/inference/hotelling/_hotelling.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,12 @@ def hotelling_t2(
k1 = fd1.cov(
fd1.grid_points[0],
fd1.grid_points[0],
correction=1,
)
k2 = fd2.cov(
fd2.grid_points[0],
fd2.grid_points[0],
correction=1,
)

m = m.reshape((-1, 1)) # Reshaping the mean for a proper matrix product
Expand Down
4 changes: 2 additions & 2 deletions skfda/misc/covariances.py
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ class EmpiricalGrid(Empirical):
cov_fdata: FDataGrid
correction: int

def __init__(self, data: FDataGrid, correction: int = 1) -> None:
def __init__(self, data: FDataGrid, correction: int = 0) -> None:
super().__init__(data=data)

self.correction = correction
Expand Down Expand Up @@ -853,7 +853,7 @@ class EmpiricalBasis(Empirical):
coeff_matrix: NDArrayFloat
correction: int

def __init__(self, data: FDataBasis, correction: int = 1) -> None:
def __init__(self, data: FDataBasis, correction: int = 0) -> None:
super().__init__(data=data)

self.correction = correction
Expand Down
8 changes: 4 additions & 4 deletions skfda/representation/_functional_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,15 +826,15 @@ def cov( # noqa: WPS451
s_points: NDArrayFloat,
t_points: NDArrayFloat,
/,
correction: int = 1,
correction: int = 0,
) -> NDArrayFloat:
pass

@overload
def cov( # noqa: WPS451
self: T,
/,
correction: int = 1,
correction: int = 0,
) -> Callable[[NDArrayFloat, NDArrayFloat], NDArrayFloat]:
pass

Expand All @@ -844,7 +844,7 @@ def cov( # noqa: WPS320, WPS451
s_points: Optional[NDArrayFloat] = None,
t_points: Optional[NDArrayFloat] = None,
/,
correction: int = 1,
correction: int = 0,
) -> Union[
Callable[[NDArrayFloat, NDArrayFloat], NDArrayFloat],
NDArrayFloat,
Expand All @@ -866,7 +866,7 @@ def cov( # noqa: WPS320, WPS451
t_points: Points where the covariance function is evaluated.
correction: degrees of freedom adjustment. The divisor used in the
calculation is `N - correction`, where `N` represents the
number of elements. Default: `1`.
number of elements. Default: `0`.
Returns:
Covariance function.
Expand Down
12 changes: 6 additions & 6 deletions skfda/representation/basis/_fdatabasis.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ def sum( # noqa: WPS125
def var(
self: T,
eval_points: Optional[NDArrayFloat] = None,
correction: int = 1,
correction: int = 0,
) -> T:
"""Compute the variance of the functional data object.
Expand All @@ -462,7 +462,7 @@ def var(
between 501 and 10 times the number of basis.
correction: degrees of freedom adjustment. The divisor used in the
calculation is `N - correction`, where `N` represents the
number of elements. Default: `1`.
number of elements. Default: `0`.
Returns:
Variance of the original object.
Expand All @@ -478,15 +478,15 @@ def cov( # noqa: WPS451
s_points: NDArrayFloat,
t_points: NDArrayFloat,
/,
correction: int = 1,
correction: int = 0,
) -> NDArrayFloat:
pass

@overload
def cov( # noqa: WPS451
self: T,
/,
correction: int = 1,
correction: int = 0,
) -> Callable[[NDArrayFloat, NDArrayFloat], NDArrayFloat]:
pass

Expand All @@ -495,7 +495,7 @@ def cov( # noqa: WPS320, WPS451
s_points: Optional[NDArrayFloat] = None,
t_points: Optional[NDArrayFloat] = None,
/,
correction: int = 1,
correction: int = 0,
) -> Union[
Callable[[NDArrayFloat, NDArrayFloat], NDArrayFloat],
NDArrayFloat,
Expand All @@ -519,7 +519,7 @@ def cov( # noqa: WPS320, WPS451
t_points: Points where the covariance function is evaluated.
correction: degrees of freedom adjustment. The divisor used in the
calculation is `N - correction`, where `N` represents the
number of elements. Default: `1`.
number of elements. Default: `0`.
Returns:
Covariance function.
Expand Down
16 changes: 8 additions & 8 deletions skfda/representation/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,13 +582,13 @@ def sum( # noqa: WPS125
sample_names=(None,),
)

def var(self: T, correction: int = 1) -> T:
def var(self: T, correction: int = 0) -> T:
"""Compute the variance of a set of samples in a FDataGrid object.
Args:
correction: "Delta Degrees of Freedom": the divisor used in the
calculation is `N - correction`, where `N` represents the number of
elements. By default `correction` is 1.
correction: degrees of freedom adjustment. The divisor used in the
calculation is `N - correction`, where `N` represents the
number of elements. Default: `0`.
Returns:
A FDataGrid object with just one sample representing the
Expand All @@ -610,15 +610,15 @@ def cov( # noqa: WPS451
s_points: NDArrayFloat,
t_points: NDArrayFloat,
/,
correction: int = 1,
correction: int = 0,
) -> NDArrayFloat:
pass

@overload
def cov( # noqa: WPS451
self: T,
/,
correction: int = 1,
correction: int = 0,
) -> Callable[[NDArrayFloat, NDArrayFloat], NDArrayFloat]:
pass

Expand All @@ -627,7 +627,7 @@ def cov( # noqa: WPS320, WPS451
s_points: Optional[NDArrayFloat] = None,
t_points: Optional[NDArrayFloat] = None,
/,
correction: int = 1,
correction: int = 0,
) -> Union[
Callable[[NDArrayFloat, NDArrayFloat], NDArrayFloat],
NDArrayFloat,
Expand All @@ -645,7 +645,7 @@ def cov( # noqa: WPS320, WPS451
t_points: Grid points where the covariance function is evaluated.
correction: degrees of freedom adjustment. The divisor used in the
calculation is `N - correction`, where `N` represents the
number of elements. Default: `1`.
number of elements. Default: `0`.
Returns:
Covariance function.
Expand Down

0 comments on commit 93fdf3d

Please sign in to comment.