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

Add StateVectors type and modify array handling #204

Merged
merged 2 commits into from
May 11, 2020
Merged

Conversation

sdhiscocks
Copy link
Member

This includes a number of changes to how Matrix type is implemented which will allow greater customisation if required. In particular, a new StateVectors type has been created which handles the case where calculations of averages (and in turn covariance) were incorrect when using Angle types.

Angle types now include a average method, which returns a circular mean. This removes an issue when calculating means near the point of angle wrapping.

These changes were primarily done for bug identified when calculating mean of particles, and such some minor changes to Particle and Particle type have been made.

Some functions have also been updated, as these are a set of state vectors, so can take advantage of the new type. This includes updating the Mixture Tracker

The array changes have changed minimum requirement for NumPy to 1.17, or 1.16 with NUMPY_EXPERIMENTAL_ARRAY_FUNCTION environment variable set to 1.

Copy link
Collaborator

@DaveKirkland DaveKirkland left a comment

Choose a reason for hiding this comment

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

When I run the pytest, I get 2 XFAIL messages:
======================== short test summary info====================
XFAIL types\tests\test_angle.py::TestAngle::test_average[elevation]
reason: Can't handle average when wrapping over ±pi
XFAIL types\tests\test_angle.py::TestAngle::test_average[latitude]
reason: Can't handle average when wrapping over ±pi
============ 384 passed, 1 skipped, 2 xfailed in 5.84s =======================

Is this the expected behaviour?

stonesoup/functions.py Show resolved Hide resolved
stonesoup/functions.py Show resolved Hide resolved
stonesoup/functions.py Show resolved Hide resolved
@sdhiscocks
Copy link
Member Author

When I run the pytest, I get 2 XFAIL messages:
======================== short test summary info====================
XFAIL types\tests\test_angle.py::TestAngle::test_average[elevation]
reason: Can't handle average when wrapping over ±pi
XFAIL types\tests\test_angle.py::TestAngle::test_average[latitude]
reason: Can't handle average when wrapping over ±pi
============ 384 passed, 1 skipped, 2 xfailed in 5.84s =======================

Is this the expected behaviour?

Yes. It's not possible to average elevation wrapping on it's own. The code also doesn't handle when in combination with bearing, which is something that we may want to look at.

Interestingly I don't see a summary of xfailed tests. May be different versions of pytest.

@DaveKirkland
Copy link
Collaborator

Yes. It's not possible to average elevation wrapping on it's own. The code also doesn't handle when in combination with bearing, which is something that we may want to look at.

Interestingly I don't see a summary of xfailed tests. May be different versions of pytest.

When I saw that it failed via exception, I ran "pytest -rx" which provides more details. There is also a flag to state why some tests are skipped e.g. If optional package are not installed.

Perhaps elevation needs it's own method - it behaves a little differently than angle.

Copy link
Collaborator

@DaveKirkland DaveKirkland left a comment

Choose a reason for hiding this comment

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

Look good to me.

@sdhiscocks
Copy link
Member Author

Yes. It's not possible to average elevation wrapping on it's own. The code also doesn't handle when in combination with bearing, which is something that we may want to look at.
Interestingly I don't see a summary of xfailed tests. May be different versions of pytest.

When I saw that it failed via exception, I ran "pytest -rx" which provides more details. There is also a flag to state why some tests are skipped e.g. If optional package are not installed.

Perhaps elevation needs it's own method - it behaves a little differently than angle.

I've raised #214 to cover the elevation/bearing issue.

Copy link
Collaborator

@sglvladi sglvladi left a comment

Choose a reason for hiding this comment

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

Looks good and neat 👍 Minor comments added

stonesoup/types/array.py Outdated Show resolved Hide resolved

@property
def ndim(self):
return self.particles[0].ndim

@property
def mean(self):
Copy link
Collaborator

@sglvladi sglvladi May 6, 2020

Choose a reason for hiding this comment

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

Would it be worth adding the @lru_cache() decorator here? I found that this (or more specifically @cached_property as I am working on Python 3.8) sped up my computations nearly 10x when using the ParticlePredictor/Updater with hypothesisers, where the same mean needs to be re-computed many times. Might be better done in a different PR, but thought I'd mention it, seeing as changes are introduced.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agree it would be good to do this. I've always worried that caching could be difficult with mutable list, with mutable particles with mutable state vector. A lot of places for it to go wrong.

I think @jmbarr's proposal in #160 to use just an array for particles (e.g. StateVectors in #204) would make these easier, as you could change the arrays writable flag.

@@ -176,9 +180,8 @@ def state_vector(self):

@property
def covar(self):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same comment as for mean

This includes a number of changes to how Matrix type is implemented
which will allow greater customisation if required. In particular, a new
StateVectors type has been created which handles the case where
calculations of averages (and in turn covariance) were incorrect when
using Angle types.

Angle types now include a average method, which returns a circular mean.
This removes an issue when calculating means near the point of angle
wrapping.

These changes were primarily done for bug identified when calculating
mean of particles, and such some minor changes to PartcileState and
Particle type have been made.

Some functions have also been updated, as these are a set of state
vectors, so can take advantage of the new type. This includes updating
the Mixture Tracker

The array changes have changed minimum requirement for NumPy to 1.17, or
1.16 with NUMPY_EXPERIMENTAL_ARRAY_FUNCTION environment variable set to
1.
@sdhiscocks
Copy link
Member Author

I've rebased to fix conflict and fix some issues from #187 (mainly arrays were used before instead of StateVector type in Particle so some tests failed once it was forced to use StateVector due to indexes)

@sdhiscocks sdhiscocks merged commit 55d0f70 into master May 11, 2020
@sdhiscocks sdhiscocks deleted the state_vectors branch June 12, 2020 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants