Hi,
thank you both for the useful replies. I could remove some of the multi-modality by changing parameters, but not all of it.
When I use pm.sample_smc() I get the error copied below.
My model is built fully in PyTensor and runs normal with NUTS. The likelihood function is generated via pm.Normal(mu=…, observed=…).
Any ideas what could be the issue?
---------------------------------------------------------------------------
RemoteTraceback Traceback (most recent call last)
RemoteTraceback:
"""
Traceback (most recent call last):
File "C:\Anaconda3\envs\pymc5_env\Lib\multiprocessing\pool.py", line 125, in worker
result = (True, func(*args, **kwds))
^^^^^^^^^^^^^^^^^^^
File "C:\Anaconda3\envs\pymc5_env\Lib\multiprocessing\pool.py", line 51, in starmapstar
return list(itertools.starmap(args[0], args[1]))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Anaconda3\envs\pymc5_env\Lib\site-packages\pymc\smc\sampling.py", line 419, in _apply_args_and_kwargs
return fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^
File "C:\Anaconda3\envs\pymc5_env\Lib\site-packages\pymc\smc\sampling.py", line 350, in _sample_smc_int
smc.update_beta_and_weights()
File "C:\Anaconda3\envs\pymc5_env\Lib\site-packages\pymc\smc\kernels.py", line 274, in update_beta_and_weights
ESS = int(np.exp(-logsumexp(log_weights * 2)))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: cannot convert float NaN to integer
"""
The above exception was the direct cause of the following exception:
ValueError Traceback (most recent call last)
Cell In[16], line 7
3 if __name__ == '__main__':
5 a = np.where((np.array(df['Time'])>(tmin)) & (np.array(df['Time'])<(tmax)))
----> 7 trace = glm_mcmc_inference_diffusion_backup3(df, np.max(a), Fluence, Surface, Thickness, Absorption_coeff)
Cell In[8], line 59, in glm_mcmc_inference_diffusion_backup3(Data_fit, i, Fluence, Surface, Thickness, Absorption_coeff)
55 print(np.where(Y_obs_late.eval()==np.nan))
57 #### Draw Samples from the Posterior Distribution
58 #step_method = pm.NUTS(early_max_treedepth=4, max_treedepth = 5)
---> 59 trace = pm.sample_smc(progressbar=False)#pm.sample(step=step_method, chains=1, draws=100, tune=1000)#step=TRPL_nuts, tune = 50, draws = no_of_samples, chains=3, discard_tuned_samples=True)
62 return trace
File C:\Anaconda3\envs\pymc5_env\Lib\site-packages\pymc\smc\sampling.py:213, in sample_smc(draws, kernel, start, model, random_seed, chains, cores, compute_convergence_checks, return_inferencedata, idata_kwargs, progressbar, **kernel_kwargs)
210 t1 = time.time()
212 if cores > 1:
--> 213 results = run_chains_parallel(
214 chains, progressbar, _sample_smc_int, params, random_seed, kernel_kwargs, cores
215 )
216 else:
217 results = run_chains_sequential(
218 chains, progressbar, _sample_smc_int, params, random_seed, kernel_kwargs
219 )
File C:\Anaconda3\envs\pymc5_env\Lib\site-packages\pymc\smc\sampling.py:388, in run_chains_parallel(chains, progressbar, to_run, params, random_seed, kernel_kwargs, cores)
386 params = tuple(cloudpickle.dumps(p) for p in params)
387 kernel_kwargs = {key: cloudpickle.dumps(value) for key, value in kernel_kwargs.items()}
--> 388 results = _starmap_with_kwargs(
389 pool,
390 to_run,
391 [(*params, random_seed[chain], chain, pbars[chain]) for chain in range(chains)],
392 repeat(kernel_kwargs),
393 )
394 results = tuple(cloudpickle.loads(r) for r in results)
395 pool.close()
File C:\Anaconda3\envs\pymc5_env\Lib\site-packages\pymc\smc\sampling.py:415, in _starmap_with_kwargs(pool, fn, args_iter, kwargs_iter)
411 def _starmap_with_kwargs(pool, fn, args_iter, kwargs_iter):
412 # Helper function to allow kwargs with Pool.starmap
413 # Copied from https://stackoverflow.com/a/53173433/13311693
414 args_for_starmap = zip(repeat(fn), args_iter, kwargs_iter)
--> 415 return pool.starmap(_apply_args_and_kwargs, args_for_starmap)
File C:\Anaconda3\envs\pymc5_env\Lib\multiprocessing\pool.py:375, in Pool.starmap(self, func, iterable, chunksize)
369 def starmap(self, func, iterable, chunksize=None):
370 '''
371 Like `map()` method but the elements of the `iterable` are expected to
372 be iterables as well and will be unpacked as arguments. Hence
373 `func` and (a, b) becomes func(a, b).
374 '''
--> 375 return self._map_async(func, iterable, starmapstar, chunksize).get()
File C:\Anaconda3\envs\pymc5_env\Lib\multiprocessing\pool.py:774, in ApplyResult.get(self, timeout)
772 return self._value
773 else:
--> 774 raise self._value
ValueError: cannot convert float NaN to integer