@@ -763,7 +763,7 @@ def plot_one_hist(
763763 results : ratapi .outputs .BayesResults ,
764764 param : int | str ,
765765 smooth : bool = True ,
766- sigma : float | None = None ,
766+ window_size : int = 8 ,
767767 estimated_density : Literal ["normal" , "lognor" , "kernel" , None ] = None ,
768768 axes : Axes | None = None ,
769769 block : bool = False ,
@@ -783,9 +783,9 @@ def plot_one_hist(
783783 smooth : bool, default True
784784 Whether to apply Gaussian smoothing to the histogram.
785785 Defaults to True.
786- sigma: float or None , default None
787- If given, is used as the sigma-parameter for the Gaussian smoothing .
788- If None, the default (1/3rd of parameter chain standard deviation) is used .
786+ window_size : int , default 8
787+ The width of the smoothing window centered around the element being averaged .
788+ The window moves down the length of the data, computing an average over the elements within each window .
789789 estimated_density : 'normal', 'lognor', 'kernel' or None, default None
790790 If None (default), ignore. Else, add an estimated density
791791 of the given form on top of the histogram by the following estimations:
@@ -826,7 +826,7 @@ def plot_one_hist(
826826 sd_y = np .std (parameter_chain )
827827
828828 if smooth :
829- counts = moving_avg (counts )
829+ counts = moving_average (counts , window_size = window_size )
830830 axes .hist (
831831 bins [:- 1 ],
832832 bins ,
@@ -1233,7 +1233,7 @@ def plot_bayes(project: ratapi.Project, results: ratapi.outputs.BayesResults):
12331233 raise ValueError ("Bayes plots are only available for the results of Bayesian analysis (NS or DREAM)" )
12341234
12351235
1236- def moving_avg (data : np .ndarray , window_size : int = 8 ) -> list [float ]:
1236+ def moving_average (data : np .ndarray , window_size : int = 8 ) -> list [float ]:
12371237 """Calculate the moving average of an array with a given window size.
12381238
12391239 This is a python equivalent to MATLABs smoothdata(A, 'movmean')
@@ -1247,10 +1247,10 @@ def moving_avg(data: np.ndarray, window_size: int = 8) -> list[float]:
12471247 computing an average over the elements within each window.
12481248
12491249 """
1250- i = 0
1250+ assert 0 <= window_size <= len ( data )
12511251 moving_averages = []
12521252
1253- while i < len (data ):
1253+ for i in range ( len (data ) ):
12541254 start_window_ind = floor (float (i - window_size / 2 )) if i - window_size / 2 > 0 else 0
12551255 end_window_ind = floor (float (i + window_size / 2 )) if i + window_size / 2 < len (data ) else len (data )
12561256 window_average = np .sum (data [start_window_ind :end_window_ind ]) / (end_window_ind + 0 - start_window_ind )
0 commit comments