Add a python equivalent to MATLABs smoothdata and use in Bayes plots#208
Add a python equivalent to MATLABs smoothdata and use in Bayes plots#208MikeSullivan7 wants to merge 1 commit into
Conversation
StephenNneji
left a comment
There was a problem hiding this comment.
Thanks for this fix, it works as advertised. Please see comments below
| raise ValueError("Bayes plots are only available for the results of Bayesian analysis (NS or DREAM)") | ||
|
|
||
|
|
||
| def moving_avg(data: np.ndarray, window_size: int = 8) -> list[float]: |
There was a problem hiding this comment.
I think the function can be called moving_average as its not too long and slightly improves readability
| i = 0 | ||
| moving_averages = [] | ||
|
|
||
| while i < len(data): |
There was a problem hiding this comment.
This seems like it can be replaced by a for loop for i in range(len(data)) which I tend to prefer over a while loop but also means you can get rid of the index initialization and increment
``
| sd_y = np.std(parameter_chain) | ||
|
|
||
| if smooth: | ||
| if sigma is None: |
There was a problem hiding this comment.
please update docstring to reflect switch to moving average, remove sigma. I also think we should expose the window size parameter since we don't know if 8 will work for all cases
There was a problem hiding this comment.
Exposing the window size means the moving average function will need a check for valid window sizes and a unit test will be helpful
This PR fixes the issue with the Bayes plots smoothing not functioning correctly for background parameters. The issue comes from the use of
scipy.ndimage.gaussian_filter1dinstead of a moving average smoothing as is used in MATLAB:smoothdata(N, 'movmean').This PR fixes the issue by implimenting a python version of
smoothdataand the function has been benchmarked against results from MATLAB.smoothdataautomatically calculates the averaging window to use but there is no real explanation on how this is calculated. This has been set to 8 as default as this is the value used by MATLAB for RAT data most commonly.Benchmark for noisy data:

Example of new smoothing for Substrate Roughness example:

Old smoothing:

New smoothing:
