Skip to content
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

Merged
merged 13 commits into from
Oct 10, 2023
Merged

Conversation

ElenaPetrunina
Copy link
Contributor

Close #132

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

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

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

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

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,)

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,)

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

skfda/misc/hat_matrix.py Show resolved Hide resolved
skfda/misc/hat_matrix.py Show resolved Hide resolved
skfda/misc/hat_matrix.py Show resolved Hide resolved
skfda/misc/hat_matrix.py Show resolved Hide resolved
skfda/misc/hat_matrix.py Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Mar 30, 2022

Codecov Report

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

Comparison is base (cc486a3) 86.08% compared to head (e6ce505) 86.03%.
Report is 1 commits behind head on develop.

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     
Files Coverage Δ
skfda/exploratory/stats/_stats.py 85.00% <100.00%> (-1.37%) ⬇️
skfda/preprocessing/smoothing/_kernel_smoothers.py 95.83% <100.00%> (+0.59%) ⬆️
skfda/preprocessing/smoothing/_linear.py 95.12% <100.00%> (+0.52%) ⬆️
skfda/tests/test_metrics.py 97.87% <100.00%> (ø)
skfda/tests/test_smoothing.py 100.00% <100.00%> (ø)
skfda/misc/hat_matrix.py 86.36% <77.77%> (-2.86%) ⬇️
skfda/misc/metrics/_lp_norms.py 77.35% <54.54%> (-8.65%) ⬇️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ElenaPetrunina ElenaPetrunina marked this pull request as draft March 30, 2022 14:22
@@ -186,7 +186,7 @@ def _hat_matrix_function_not_normalized(
) -> NDArrayFloat:

bandwidth = (
np.percentile(np.abs(delta_x), 15)
np.percentile(delta_x, 15)

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

@@ -311,10 +311,26 @@ def __call__( # noqa: D102
) -> NDArrayFloat | FData:

bandwidth = (
np.percentile(np.abs(delta_x), 15)
np.percentile(delta_x, 15)

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

if self.bandwidth is None
else self.bandwidth
)

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

@@ -325,45 +341,42 @@ def __call__( # noqa: D102
and isinstance(X, FDataBasis)
):
raise ValueError("Only FDataBasis is supported for now.")

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

Copy link

@github-actions github-actions bot left a 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,

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,

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],

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]

skfda/misc/hat_matrix.py Show resolved Hide resolved
skfda/misc/hat_matrix.py Show resolved Hide resolved
skfda/misc/hat_matrix.py Show resolved Hide resolved
skfda/misc/hat_matrix.py Show resolved Hide resolved
skfda/misc/hat_matrix.py Show resolved Hide resolved
skfda/misc/hat_matrix.py Show resolved Hide resolved
skfda/misc/hat_matrix.py Show resolved Hide resolved
skfda/misc/hat_matrix.py Show resolved Hide resolved
skfda/misc/hat_matrix.py Show resolved Hide resolved
skfda/misc/hat_matrix.py Show resolved Hide resolved
skfda/misc/hat_matrix.py Show resolved Hide resolved
skfda/misc/hat_matrix.py Show resolved Hide resolved
@@ -114,10 +116,12 @@
*,
weights: Optional[NDArrayFloat] = None,
output_points: Optional[GridPointsLike] = None,
metric: Metric[Vector] = l2_distance,

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,

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,

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,

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))

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))

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

@vnmabus vnmabus marked this pull request as ready for review October 10, 2023 11:00
@vnmabus vnmabus merged commit fac57c8 into develop Oct 10, 2023
13 of 16 checks passed
@vnmabus vnmabus deleted the feature/several_dim_kernel_smoothing branch October 10, 2023 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Smoothing in several dimensions
2 participants