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

fix: entity splitting bug in NCMAPSS #63

Merged
merged 1 commit into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions rul_datasets/reader/ncmapss.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,9 @@ def _window_by_cycle(

@staticmethod
def _get_end_idx(identifiers):
_, split_idx = np.unique(identifiers, return_counts=True)
split_idx = np.cumsum(split_idx)
_, split_idx = np.unique(identifiers, return_index=True)
split_idx = np.sort(split_idx)
split_idx = np.concatenate([split_idx[1:], [len(identifiers)]])

return split_idx

Expand Down
19 changes: 17 additions & 2 deletions tests/reader/test_ncmapss.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ def test_max_rul(max_rul, prepared_ncmapss):


@pytest.mark.needs_data
def test__split_by_unit(prepared_ncmapss):
reader = NCmapssReader(1)
@pytest.mark.parametrize("fd", range(1, 8))
def test__split_by_unit(fd, prepared_ncmapss):
reader = NCmapssReader(fd)
features, targets, auxiliary = reader._load_raw_data()
features, targets, auxiliary = reader._split_by_unit(features, targets, auxiliary)

Expand All @@ -113,6 +114,20 @@ def test__split_by_unit(prepared_ncmapss):
assert np.unique(auxiliary[i][:, 0]).size == 1 # only one unit id present


@pytest.mark.needs_data
@pytest.mark.parametrize("fd", range(1, 8))
def test__get_end_idx_for_cycles(fd, prepared_ncmapss):
reader = NCmapssReader(fd)
features, targets, auxiliary = reader._load_raw_data()
features, targets, auxiliary = reader._split_by_unit(features, targets, auxiliary)

for aux in auxiliary:
cycle_end_idx = reader._get_end_idx(aux[:, 1])
split_aux = np.split(aux, cycle_end_idx[:-1])
for cycle in split_aux:
assert np.unique(cycle[:, 1]).size == 1 # only one cycle id present


@pytest.mark.needs_data
@pytest.mark.parametrize("window_size", [10, 100])
def test_padding_and_window_size(window_size, prepared_ncmapss):
Expand Down
Loading