@@ -105,6 +105,20 @@ function StatsBase.sample(
105
105
return mcmcsample (rng, model, sampler, parallel, N, nchains; kwargs... )
106
106
end
107
107
108
+ # Utility function to check and warn about common kwargs mistakes
109
+ function _check_initial_params_kwarg (kwargs)
110
+ if haskey (kwargs, :initial_parameters )
111
+ @warn " The `initial_parameters` keyword argument is not recognised; please use `initial_params` instead."
112
+ return true
113
+ end
114
+ return false
115
+ end
116
+
117
+ # Utility function to remove initial_parameters from kwargs after warning
118
+ function _filter_initial_params_kwarg (kwargs)
119
+ return pairs ((; (k => v for (k, v) in pairs (kwargs) if k != = :initial_parameters ). .. ))
120
+ end
121
+
108
122
# Default implementations of regular and parallel sampling.
109
123
function mcmcsample (
110
124
rng:: Random.AbstractRNG ,
@@ -121,6 +135,9 @@ function mcmcsample(
121
135
initial_state= nothing ,
122
136
kwargs... ,
123
137
)
138
+ # Warn if initial_parameters is passed instead of initial_params
139
+ _check_initial_params_kwarg (kwargs)
140
+
124
141
# Check the number of requested samples.
125
142
N > 0 || error (" the number of samples must be ≥ 1" )
126
143
discard_initial >= 0 ||
@@ -405,6 +422,11 @@ function mcmcsample(
405
422
initial_state= nothing ,
406
423
kwargs... ,
407
424
)
425
+ # Warn if initial_parameters is passed instead of initial_params and remove it from kwargs
426
+ if _check_initial_params_kwarg (kwargs)
427
+ kwargs = _filter_initial_params_kwarg (kwargs)
428
+ end
429
+
408
430
# Check if actually multiple threads are used.
409
431
if Threads. nthreads () == 1
410
432
@warn " Only a single thread available: MCMC chains are not sampled in parallel"
@@ -588,6 +610,11 @@ function mcmcsample(
588
610
initial_state= nothing ,
589
611
kwargs... ,
590
612
)
613
+ # Warn if initial_parameters is passed instead of initial_params and remove it from kwargs
614
+ if _check_initial_params_kwarg (kwargs)
615
+ kwargs = _filter_initial_params_kwarg (kwargs)
616
+ end
617
+
591
618
# Check if actually multiple processes are used.
592
619
if Distributed. nworkers () == 1
593
620
@warn " Only a single process available: MCMC chains are not sampled in parallel"
@@ -727,6 +754,11 @@ function mcmcsample(
727
754
initial_state= nothing ,
728
755
kwargs... ,
729
756
)
757
+ # Warn if initial_parameters is passed instead of initial_params and remove it from kwargs
758
+ if _check_initial_params_kwarg (kwargs)
759
+ kwargs = _filter_initial_params_kwarg (kwargs)
760
+ end
761
+
730
762
# Check if the number of chains is larger than the number of samples
731
763
if nchains > N
732
764
@warn " Number of chains ($nchains ) is greater than number of samples per chain ($N )"
0 commit comments