-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Smoothing in several dimensions #436
Conversation
skfda/misc/hat_matrix.py
Outdated
inner_product_matrix = X_train.basis.inner_product_matrix() | ||
|
||
# Calculate new coefficients taking into account cross-products | ||
# if the basis is orthonormal, C would not change | ||
C = C @ inner_product_matrix # noqa: WPS350 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[pep8] reported by reviewdog 🐶
W293 blank line contains whitespace
@@ -9,9 +9,10 @@ | |||
|
|||
import numpy as np | |||
|
|||
from ..._utils._utils import _to_grid_points | |||
from ..._utils._utils import _to_grid_points, _cartesian_product |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[pep8] reported by reviewdog 🐶
I001 isort found an import in the wrong position
from ...misc.hat_matrix import HatMatrix, NadarayaWatsonHatMatrix | ||
from ...representation._typing import GridPointsLike, NDArrayFloat | ||
from ...misc.metrics import PairwiseMetric, l2_distance, Metric |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[pep8] reported by reviewdog 🐶
I001 isort found an import in the wrong position
from ...misc.hat_matrix import HatMatrix, NadarayaWatsonHatMatrix | ||
from ...representation._typing import GridPointsLike, NDArrayFloat | ||
from ...misc.metrics import PairwiseMetric, l2_distance, Metric | ||
from ...representation._typing import GridPointsLike, NDArrayFloat, Vector |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[pep8] reported by reviewdog 🐶
I005 isort found an unexpected missing import
|
||
hat_matrix = np.reshape( | ||
self.hat_matrix_, | ||
(*dims,) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[pep8] reported by reviewdog 🐶
WPS356 Found an unnecessary iterable unpacking
|
||
hat_matrix = np.reshape( | ||
self.hat_matrix_, | ||
(*dims,) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[pep8] reported by reviewdog 🐶
C812 missing trailing comma
….com/GAA-UAM/scikit-fda into feature/several_dim_kernel_smoothing
….com/GAA-UAM/scikit-fda into feature/several_dim_kernel_smoothing
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## develop #436 +/- ##
===========================================
- Coverage 86.08% 86.03% -0.05%
===========================================
Files 148 148
Lines 11694 11719 +25
===========================================
+ Hits 10067 10083 +16
- Misses 1627 1636 +9
☔ View full report in Codecov by Sentry. |
skfda/misc/hat_matrix.py
Outdated
@@ -186,7 +186,7 @@ def _hat_matrix_function_not_normalized( | |||
) -> NDArrayFloat: | |||
|
|||
bandwidth = ( | |||
np.percentile(np.abs(delta_x), 15) | |||
np.percentile(delta_x, 15) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[pep8] reported by reviewdog 🐶
WPS432 Found magic number: 15
skfda/misc/hat_matrix.py
Outdated
@@ -311,10 +311,26 @@ def __call__( # noqa: D102 | |||
) -> NDArrayFloat | FData: | |||
|
|||
bandwidth = ( | |||
np.percentile(np.abs(delta_x), 15) | |||
np.percentile(delta_x, 15) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[pep8] reported by reviewdog 🐶
WPS432 Found magic number: 15
skfda/misc/hat_matrix.py
Outdated
if self.bandwidth is None | ||
else self.bandwidth | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[pep8] reported by reviewdog 🐶
W293 blank line contains whitespace
skfda/misc/hat_matrix.py
Outdated
@@ -325,45 +341,42 @@ def __call__( # noqa: D102 | |||
and isinstance(X, FDataBasis) | |||
): | |||
raise ValueError("Only FDataBasis is supported for now.") | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[pep8] reported by reviewdog 🐶
W293 blank line contains whitespace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit
mypy
skfda/misc/hat_matrix.py|323 col 17| Item "None" of "FData | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | int | float | complex | _NestedSequence[bool | int | float | complex | str | bytes] | Sequence[_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]] | None" has no attribute "flatten" [union-attr]
skfda/misc/hat_matrix.py|326 col 20| Value of type variable "Input" of "call" of "HatMatrix" cannot be "object" [type-var]
skfda/misc/hat_matrix.py|326 col 20| Not all union combinations were tried because there are too many unions [misc]
skfda/misc/hat_matrix.py|330 col 25| Argument "y_train" to "call" of "HatMatrix" has incompatible type "ndarray[Any, dtype[floating[Any]]] | FData | None"; expected "None" [arg-type]
skfda/misc/hat_matrix.py|352 col 18| Incompatible types in assignment (expression has type "FData | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | int | float | complex | _NestedSequence[bool | int | float | complex | str | bytes] | Sequence[_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]] | None", variable has type "ndarray[Any, dtype[floating[Any]]]") [assignment]
skfda/misc/hat_matrix.py|353 col 18| Incompatible types in assignment (expression has type "FData | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes] | Sequence[_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]] | None", variable has type "ndarray[Any, dtype[floating[Any]]]") [assignment]
skfda/misc/hat_matrix.py|356 col 39| Item "_SupportsArray[dtype[Any]]" of "FData | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | int | float | complex | _NestedSequence[bool | int | float | complex | str | bytes] | Sequence[_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]] | None" has no attribute "shape" [union-attr]
skfda/misc/hat_matrix.py|356 col 39| Item "_NestedSequence[_SupportsArray[dtype[Any]]]" of "FData | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | int | float | complex | _NestedSequence[bool | int | float | complex | str | bytes] | Sequence[_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]] | None" has no attribute "shape" [union-attr]
skfda/misc/hat_matrix.py|356 col 39| Item "int" of "FData | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | int | float | complex | _NestedSequence[bool | int | float | complex | str | bytes] | Sequence[_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]] | None" has no attribute "shape" [union-attr]
skfda/misc/hat_matrix.py|356 col 39| Item "float" of "FData | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | int | float | complex | _NestedSequence[bool | int | float | complex | str | bytes] | Sequence[_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]] | None" has no attribute "shape" [union-attr]
skfda/misc/hat_matrix.py|356 col 39| Item "complex" of "FData | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | int | float | complex | _NestedSequence[bool | int | float | complex | str | bytes] | Sequence[_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]] | None" has no attribute "shape" [union-attr]
skfda/misc/hat_matrix.py|356 col 39| Item "_NestedSequence[bool | int | float | complex | str | bytes]" of "FData | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | int | float | complex | _NestedSequence[bool | int | float | complex | str | bytes] | Sequence[_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]] | None" has no attribute "shape" [union-attr]
skfda/misc/hat_matrix.py|356 col 39| Item "Sequence[_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]]" of "FData | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | int | float | complex | _NestedSequence[bool | int | float | complex | str | bytes] | Sequence[_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]] | None" has no attribute "shape" [union-attr]
skfda/misc/hat_matrix.py|356 col 39| Item "None" of "FData | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | int | float | complex | _NestedSequence[bool | int | float | complex | str | bytes] | Sequence[_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]] | None" has no attribute "shape" [union-attr]
skfda/misc/hat_matrix.py|378 col 23| Argument "bandwidth" to "_solve_least_squares" of "LocalLinearRegressionHatMatrix" has incompatible type "object"; expected "float" [arg-type]
) | ||
|
||
data_matrix = np.einsum( | ||
hat_matrix, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [mypy] reported by reviewdog 🐶
Argument 1 to "einsum" has incompatible type "ndarray[Any, dtype[floating[Any]]]"; expected "str | SupportsArray[dtype[bool | integer[Any]]] | _NestedSequence[SupportsArray[dtype[bool | integer[Any]]]] | bool | int | _NestedSequence[bool | int]" [arg-type]
data_matrix = np.einsum( | ||
hat_matrix, | ||
[Ellipsis, *range(1, len(self.output_points_) + 1)], | ||
X.data_matrix, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [mypy] reported by reviewdog 🐶
Argument 3 to "einsum" has incompatible type "ndarray[Any, dtype[floating[Any]]]"; expected "SupportsArray[dtype[bool]] | _NestedSequence[SupportsArray[dtype[bool]]] | bool | _NestedSequence[bool]" [arg-type]
[Ellipsis, *range(1, len(self.output_points_) + 1)], | ||
X.data_matrix, | ||
[0, *range(1, len(self.output_points_) + 2)], | ||
[0, Ellipsis, len(self.output_points_) + 1], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [mypy] reported by reviewdog 🐶
Argument 5 to "einsum" has incompatible type "list[object]"; expected "SupportsArray[dtype[bool]] | _NestedSequence[SupportsArray[dtype[bool]]] | bool | _NestedSequence[bool]" [arg-type]
@@ -114,10 +116,12 @@ | |||
*, | |||
weights: Optional[NDArrayFloat] = None, | |||
output_points: Optional[GridPointsLike] = None, | |||
metric: Metric[Vector] = l2_distance, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 [mypy] reported by reviewdog 🐶
Expected:
@@ -114,10 +116,12 @@ | |||
*, | |||
weights: Optional[NDArrayFloat] = None, | |||
output_points: Optional[GridPointsLike] = None, | |||
metric: Metric[Vector] = l2_distance, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 [mypy] reported by reviewdog 🐶
def call(self, Vector, Vector, /) -> ndarray[Any, dtype[floating[Any]]]
@@ -114,10 +116,12 @@ | |||
*, | |||
weights: Optional[NDArrayFloat] = None, | |||
output_points: Optional[GridPointsLike] = None, | |||
metric: Metric[Vector] = l2_distance, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 [mypy] reported by reviewdog 🐶
Got:
@@ -114,10 +116,12 @@ | |||
*, | |||
weights: Optional[NDArrayFloat] = None, | |||
output_points: Optional[GridPointsLike] = None, | |||
metric: Metric[Vector] = l2_distance, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 [mypy] reported by reviewdog 🐶
def [T in (ndarray[Any, dtype[floating[Any]]], FData)] call(self, elem1: T, elem2: T) -> ndarray[Any, dtype[floating[Any]]]
fd = skfda.FDataGrid(X) | ||
|
||
ks = KernelSmoother( | ||
kernel_estimator=KNeighborsHatMatrix(n_neighbors=1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[pep8] reported by reviewdog 🐶
WPS319 Found bracket in wrong position
np.testing.assert_allclose(fd_trans.data_matrix, fd.data_matrix) | ||
|
||
ks = KernelSmoother( | ||
kernel_estimator=KNeighborsHatMatrix(n_neighbors=3)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[pep8] reported by reviewdog 🐶
WPS319 Found bracket in wrong position
Close #132