Stone-Soup icon indicating copy to clipboard operation
Stone-Soup copied to clipboard

Track metadata should handle removal of states

Open sdhiscocks opened this issue 6 years ago • 1 comments

Reference #121

sdhiscocks avatar Aug 27 '19 09:08 sdhiscocks

I think we should proceed with caution on this one, because it can turn out to be really inefficient. One way I can think of to update the metadata, following a state removal, is to first clear the metadata, and then reconstruct the dict by considering all states, but the one to be removed, incrementally. An example way of doing this would be the following:

def __delitem__(self, index):
    # Update metadata
    # 1) Reset the metadata
    self._metadata = dict({})
    # 2) Reconstruct the metadata, without considering the state to be removed
    for i in range(len(self)):
        if i == index:
            continue
        self._update_metadata_from_state(self, self.states[i])
    return super().__delitem__(index)

Obviously, the above can end up being very costly.

Therefore, unless we can find an efficient alternative, we may want to consider the following questions:

  • Why do we actually need to remove states? Can we come up with some use-cases?
  • Assuming there are use-cases, do we also want to allow for the removal of states from the middle of list? If so, what would be an example use-case?
  • Assuming we decide that we only allow removal from the ends, should we allow both ends? Use-case?
  • If the only use-case is to limit the history length, then should we actually update the metadata once a state is removed? It might be more sensible to just keep the metadata.

sglvladi avatar Apr 04 '20 07:04 sglvladi