@@ -105,6 +105,20 @@ function StatsBase.sample(
105105 return mcmcsample (rng, model, sampler, parallel, N, nchains; kwargs... )
106106end
107107
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+
108122# Default implementations of regular and parallel sampling.
109123function mcmcsample (
110124 rng:: Random.AbstractRNG ,
@@ -121,6 +135,9 @@ function mcmcsample(
121135 initial_state= nothing ,
122136 kwargs... ,
123137)
138+ # Warn if initial_parameters is passed instead of initial_params
139+ _check_initial_params_kwarg (kwargs)
140+
124141 # Check the number of requested samples.
125142 N > 0 || error (" the number of samples must be ≥ 1" )
126143 discard_initial >= 0 ||
@@ -405,6 +422,11 @@ function mcmcsample(
405422 initial_state= nothing ,
406423 kwargs... ,
407424)
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+
408430 # Check if actually multiple threads are used.
409431 if Threads. nthreads () == 1
410432 @warn " Only a single thread available: MCMC chains are not sampled in parallel"
@@ -588,6 +610,11 @@ function mcmcsample(
588610 initial_state= nothing ,
589611 kwargs... ,
590612)
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+
591618 # Check if actually multiple processes are used.
592619 if Distributed. nworkers () == 1
593620 @warn " Only a single process available: MCMC chains are not sampled in parallel"
@@ -727,6 +754,11 @@ function mcmcsample(
727754 initial_state= nothing ,
728755 kwargs... ,
729756)
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+
730762 # Check if the number of chains is larger than the number of samples
731763 if nchains > N
732764 @warn " Number of chains ($nchains ) is greater than number of samples per chain ($N )"
0 commit comments