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

Feature Construction Moments #438

Merged
merged 13 commits into from
Jun 14, 2022
Merged

Conversation

alvaro-castillo
Copy link
Contributor

No description provided.

@alvaro-castillo alvaro-castillo self-assigned this Apr 6, 2022
@alvaro-castillo alvaro-castillo requested a review from vnmabus April 6, 2022 21:34
@codecov
Copy link

codecov bot commented Apr 6, 2022

Codecov Report

Merging #438 (e83e411) into develop (b3e2cb7) will increase coverage by 0.04%.
The diff coverage is 100.00%.

@@             Coverage Diff             @@
##           develop     #438      +/-   ##
===========================================
+ Coverage    80.45%   80.49%   +0.04%     
===========================================
  Files           95       95              
  Lines         7417     7433      +16     
===========================================
+ Hits          5967     5983      +16     
  Misses        1450     1450              
Impacted Files Coverage Δ
...kfda/exploratory/stats/_functional_transformers.py 92.30% <100.00%> (+2.56%) ⬆️
skfda/representation/grid.py 84.82% <100.00%> (+0.12%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b3e2cb7...e83e411. Read the comment docs.


import numpy as np

from ..._utils import check_is_univariate
from ...representation import FDataBasis, FDataGrid
from ...representation._typing import NDArrayFloat, NDArrayInt
from ...representation import FDataGrid
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[pep8] reported by reviewdog 🐶
F811 redefinition of unused 'FDataGrid' from line 10


import numpy as np

from ..._utils import check_is_univariate
from ...representation import FDataBasis, FDataGrid
from ...representation._typing import NDArrayFloat, NDArrayInt
from ...representation import FDataGrid
Copy link

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


import numpy as np

from ..._utils import check_is_univariate
from ...representation import FDataBasis, FDataGrid
from ...representation._typing import NDArrayFloat, NDArrayInt
from ...representation import FDataGrid
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[pep8] reported by reviewdog 🐶
WPS440 Found block variables overlap: FDataGrid

@@ -342,3 +343,138 @@ def number_up_crossings(
points_greater & points_smaller_rotated,
axis=2,
).T

def moments_of_norm(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[pep8] reported by reviewdog 🐶
E302 expected 2 blank lines, found 1

[ 0.02, -0. ],
[ 0.03, 0.01]])
"""
mean = np.mean(data.data_matrix, axis=1)
Copy link
Member

@vnmabus vnmabus May 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work for FDataBasis.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, it should be the mean in the integral sense, IMHO, to consider the position of the grid points too.


if isinstance(data, FDataGrid):
return scipy.integrate.simpson(
function(data.data_matrix),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can apply the function directly to the FDataGrid and use its integrate method afterwards.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then the function should be a Callable[[FDataGrid], FDataGrid] so a FDataGrid is returned and the integrate method could be applied later

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can apply a ndarray function over a FDataGrid. Mypy probably won't like it but it will work at runtime.

[ 4.9 ],
[ 4.84]])
"""
domain_range = data.domain_range[0][1] - data.domain_range[0][0]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be extended to general functions?

Calculate the specified unconditional moment of a dataset.

It performs the following map:
:math:`f(X)=\int_a^b f_1(X(t))dt,\dots,f_p(X(t))dt=\int_a^b f^p(X(t))dt`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the n in this formula? What is p?

if isinstance(data, FDataGrid):
return function(data).integrate() / domain_range

return nquad_vec(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is ok. You seem to compute the integral of the function instead of the function applied to the random variable. Please add a test using the same data in both discretized and basis form to check if it works.



def unconditional_expected_value(
data: Union[FDataBasis, FDataGrid],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use FData instead of a Union.

and p observations, how the unconditional expected values are calculated:
.. math::
f_1(x(t))=\frac{1}{\left( b-a\right)}\int_a^b g
\left(x_1(t)\right)dt,\dots,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[pep8] reported by reviewdog 🐶
WPS430 Found nested function: integrand

if isinstance(data, FDataGrid):
return function(data).integrate() / lebesgue_measure

def integrand(*args: NDArrayFloat):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[pep8] reported by reviewdog 🐶
WPS430 Found nested function: integrand

@vnmabus vnmabus merged commit d15b394 into develop Jun 14, 2022
@vnmabus vnmabus deleted the feature/featureConstructionMoments branch June 28, 2022 14:39
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.

2 participants