-
Notifications
You must be signed in to change notification settings - Fork 125
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
Conversation
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.
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. |
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. |
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.
Look good to me.
I've raised #214 to cover the elevation/bearing issue. |
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.
Looks good and neat 👍 Minor comments added
|
||
@property | ||
def ndim(self): | ||
return self.particles[0].ndim | ||
|
||
@property | ||
def mean(self): |
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.
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.
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.
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): |
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.
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.
I've rebased to fix conflict and fix some issues from #187 (mainly arrays were used before instead of |
This includes a number of changes to how
Matrix
type is implemented which will allow greater customisation if required. In particular, a newStateVectors
type has been created which handles the case where calculations of averages (and in turn covariance) were incorrect when usingAngle
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
andParticle
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 to1
.