-
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
Feature Construction Moments #438
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
|
||
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 |
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 🐶
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 |
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
|
||
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 |
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 🐶
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( |
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 🐶
E302 expected 2 blank lines, found 1
[ 0.02, -0. ], | ||
[ 0.03, 0.01]]) | ||
""" | ||
mean = np.mean(data.data_matrix, axis=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.
This doesn't work for FDataBasis
.
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.
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), |
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.
You can apply the function directly to the FDataGrid
and use its integrate
method afterwards.
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.
Then the function should be a Callable[[FDataGrid], FDataGrid] so a FDataGrid is returned and the integrate method could be applied later
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.
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] |
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.
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`. |
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.
Where is the n
in this formula? What is p
?
if isinstance(data, FDataGrid): | ||
return function(data).integrate() / domain_range | ||
|
||
return nquad_vec( |
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.
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], |
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.
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, |
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 🐶
WPS430 Found nested function: integrand
if isinstance(data, FDataGrid): | ||
return function(data).integrate() / lebesgue_measure | ||
|
||
def integrand(*args: NDArrayFloat): |
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 🐶
WPS430 Found nested function: integrand
No description provided.