@@ -2125,121 +2125,6 @@ def _kld_error(args):
21252125 approx = approx )
21262126
21272127
2128- def old_stopping_function (results ,
2129- args = None ,
2130- rstate = None ,
2131- M = None ,
2132- return_vals = False ):
2133- """
2134- The old stopping function utilized by :class:`DynamicSampler`.
2135- Zipped parameters are passed to the function via :data:`args`.
2136- Assigns the run a stopping value based on a weighted average of the
2137- stopping values for the posterior and evidence::
2138- stop = pfrac * stop_post + (1.- pfrac) * stop_evid
2139- The evidence stopping value is based on the estimated evidence error
2140- (i.e. standard deviation) relative to a given threshold::
2141- stop_evid = evid_std / evid_thresh
2142- The posterior stopping value is based on the fractional error (i.e.
2143- standard deviation / mean) in the Kullback-Leibler (KL) divergence
2144- relative to a given threshold::
2145- stop_post = (kld_std / kld_mean) / post_thresh
2146- Estimates of the mean and standard deviation are computed using `n_mc`
2147- realizations of the input using a provided `'error'` keyword (either
2148- `'jitter'` or `'resample'`).
2149- Returns the boolean `stop <= 1`. If `True`, the :class:`DynamicSampler`
2150- will stop adding new samples to our results.
2151- Parameters
2152- ----------
2153- results : :class:`Results` instance
2154- :class:`Results` instance.
2155- args : dictionary of keyword arguments, optional
2156- Arguments used to set the stopping values. Default values are
2157- `pfrac = 1.0`, `evid_thresh = 0.1`, `post_thresh = 0.02`,
2158- `n_mc = 128`, `error = 'jitter'`, and `approx = True`.
2159- rstate : `~numpy.random.Generator`, optional
2160- `~numpy.random.Generator` instance.
2161- M : `map` function, optional
2162- An alias to a `map`-like function. This allows users to pass
2163- functions from pools (e.g., `pool.map`) to compute realizations in
2164- parallel. By default the standard `map` function is used.
2165- return_vals : bool, optional
2166- Whether to return the stopping value (and its components). Default
2167- is `False`.
2168- Returns
2169- -------
2170- stop_flag : bool
2171- Boolean flag indicating whether we have passed the desired stopping
2172- criteria.
2173- stop_vals : tuple of shape (3,), optional
2174- The individual stopping values `(stop_post, stop_evid, stop)` used
2175- to determine the stopping criteria.
2176- """
2177-
2178- with warnings .catch_warnings ():
2179- warnings .filterwarnings ("once" )
2180- warnings .warn (
2181- "This an old stopping function that will "
2182- "be removed in future releases" , DeprecationWarning )
2183- # Initialize values.
2184- if args is None :
2185- args = {}
2186- if M is None :
2187- M = map
2188-
2189- # Initialize hyperparameters.
2190- pfrac = args .get ('pfrac' , 1.0 )
2191- if not 0. <= pfrac <= 1. :
2192- raise ValueError (
2193- f"The provided `pfrac` { pfrac } is not between 0. and 1." )
2194- evid_thresh = args .get ('evid_thresh' , 0.1 )
2195- if pfrac < 1. and evid_thresh < 0. :
2196- raise ValueError (
2197- f"The provided `evid_thresh` { evid_thresh } is not non-negative "
2198- f"even though `pfrac` is { pfrac } ." )
2199- post_thresh = args .get ('post_thresh' , 0.02 )
2200- if pfrac > 0. and post_thresh < 0. :
2201- raise ValueError (
2202- f"The provided `post_thresh` { post_thresh } is not non-negative "
2203- f"even though `pfrac` is { pfrac } ." )
2204- n_mc = args .get ('n_mc' , 128 )
2205- if n_mc <= 1 :
2206- raise ValueError (f"The number of realizations { n_mc } must be greater "
2207- "than 1." )
2208- if n_mc < 20 :
2209- warnings .warn ("Using a small number of realizations might result in "
2210- "excessively noisy stopping value estimates." )
2211- error = args .get ('error' , 'jitter' )
2212- if error not in {'jitter' , 'resample' }:
2213- raise ValueError (f"The chosen `'error'` option { error } is not valid." )
2214- approx = args .get ('approx' , True )
2215-
2216- # Compute realizations of ln(evidence) and the KL divergence.
2217- rlist = [results for i in range (n_mc )]
2218- error_list = [error for i in range (n_mc )]
2219- approx_list = [approx for i in range (n_mc )]
2220- seeds = get_seed_sequence (rstate , n_mc )
2221- args = zip (rlist , error_list , approx_list , seeds )
2222- outputs = list (M (_kld_error , args ))
2223- kld_arr , lnz_arr = np .array ([(kld [- 1 ], res .logz [- 1 ])
2224- for kld , res in outputs ]).T
2225-
2226- # Evidence stopping value.
2227- lnz_std = np .std (lnz_arr )
2228- stop_evid = lnz_std / evid_thresh
2229-
2230- # Posterior stopping value.
2231- kld_mean , kld_std = np .mean (kld_arr ), np .std (kld_arr )
2232- stop_post = (kld_std / kld_mean ) / post_thresh
2233-
2234- # Effective stopping value.
2235- stop = pfrac * stop_post + (1. - pfrac ) * stop_evid
2236-
2237- if return_vals :
2238- return stop <= 1. , (stop_post , stop_evid , stop )
2239- else :
2240- return stop <= 1.
2241-
2242-
22432128def restore_sampler (fname , pool = None ):
22442129 """
22452130 Restore the dynamic sampler from a file.
@@ -2293,7 +2178,7 @@ def restore_sampler(fname, pool=None):
22932178 samplers = [sampler ]
22942179
22952180 for cursamp in samplers :
2296- cursamp .M = mapper
2181+ cursamp .mapper = mapper
22972182 cursamp .pool = pool
22982183 cursamp .loglikelihood .pool = pool
22992184 return sampler
0 commit comments