Skip to content

Error in calculating the mean values in the FData object #642

@aleexarias

Description

@aleexarias

Bug description summary

In the FData class, the mean function is calculated with the sum function, which has a skipna option that ignores NaN values. However, for the division it is assumed that all elements are present, which could not be correct in all cases.

Code to reproduce the bug

from skfda.representation.grid import FDataGrid

data_matrix = np.array([
    [1.0, 2.0, 3.0],
    [np.nan, 2.0, 3.0],
    [1.0, 2.0, np.nan],
])

fd = FDataGrid(data_matrix)
mean_fd = fd.mean(skipna=True)

print("Computed mean with skipna=True:")
print(mean_fd.data_matrix)

Expected result

Computed mean with skipna=True:
[ 1.0 2.0 3.0]

Actual result

Computed mean with skipna=True:
[ 0.66 2.0 2.0]

Traceback (if an exception is raised)

No response

Software versions

scikit-fda version: 0.9.2.dev0
OS: Ubuntu 20.04.6 LTS (Focal Fossa)

Additional context

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions