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 a RandomState parameter to the clutter model #587

Merged
merged 6 commits into from
Jan 24, 2022

Conversation

ekhunter123
Copy link
Collaborator

Add an optional numpy.random.RandomState parameter to the clutter model. This helps with reproducibility of code and closes #575.

@codecov
Copy link

codecov bot commented Jan 18, 2022

Codecov Report

Merging #587 (5a85ca3) into main (31b5ff2) will increase coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head 5a85ca3 differs from pull request most recent head cbe65f4. Consider uploading reports for the commit cbe65f4 to get more accurate results
Impacted file tree graph

@@           Coverage Diff           @@
##             main     #587   +/-   ##
=======================================
  Coverage   94.34%   94.34%           
=======================================
  Files         154      154           
  Lines        7344     7345    +1     
  Branches     1397     1397           
=======================================
+ Hits         6929     6930    +1     
  Misses        313      313           
  Partials      102      102           
Flag Coverage Δ
integration 68.64% <66.66%> (+<0.01%) ⬆️
unittests 91.69% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
stonesoup/models/clutter/clutter.py 94.44% <100.00%> (+0.15%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 31b5ff2...cbe65f4. Read the comment docs.

@@ -42,6 +42,9 @@ class ClutterModel(Model, ABC):
"The default defines the space for a uniform distribution in 2D. The call "
"`np.array([self.distribution(*arg) for arg in self.dist_params])` "
"must return a numpy array of length equal to the number of dimensions.")
random_state: Optional[np.random.RandomState] = Property(
default=np.random.RandomState(1),
Copy link
Member

Choose a reason for hiding this comment

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

The issue with having this as a default, is run to run you'll get the same results, and I think it'd be better that by default the global random state is used. Also, this default will be shared by all instances, which may have unexpected issues.

Something like in Gaussian Model may be better:

seed: Optional[int] = Property(default=None, doc="Seed for random number generation")
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.random_state = np.random.RandomState(self.seed) if self.seed is not None else None

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's a very good point, I hadn't thought of that. I've made this change like you suggested. However, I did keep the seed as either an integer seed or a numpy random state (or default None). I thought this way the user can use the same random state for the poisson random variable and the distribution attribute. For example:

rs = numpy.random.RandomState(seed=1)  
clutter_model = ClutterModel(  
     distribution=rs.uniform,  
     seed=rs,  
     ...  
)

Does that seem ok?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sorry, I don't quite understand why this change made the tests fail. It seems to be failing Test 39, installing dependencies.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I don't quite understand why this change made the tests fail. It seems to be failing Test 39, installing dependencies.

CircleCI seems to be having issues lately with the dependency cache getting corrupted. Seems I can't reset the cache on PRs from forks. Will have to look into a solution, but just ignore failures for now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok, thank you!

ekhunter123 and others added 4 commits January 21, 2022 13:03
Fix a small bug in the random seed so that it uses the global random state as default.
Fix small bug so that the clutter model uses global random state as default.
@sdhiscocks sdhiscocks merged commit a8760f9 into dstl:main Jan 24, 2022
@ekhunter123 ekhunter123 deleted the clutter_seed branch January 24, 2022 15:47
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.

Radar cluttertest doesn't consider no clutter
3 participants