I am currently trying to use CPnest to calculate some evidences for given a data set (Bayesian statistics) Upon my first running of the code, I received the error
RuntimeError:
Attempt to start a new process before the current process
has finished its bootstrapping phase.
This probably means that you are on Windows and you have
forgotten to use the proper idiom in the main module:
if __name__ == '__main__':
freeze_support()
...
The "freeze_support()" line can be omitted if the program
is not going to be frozen to produce a Windows executable.
I looked up the soltuion to this and tried implementing it into my code and no longer got the error, here is my code I am trying to use (the original code that got the error is just the code below without the if __name__ == '__main__':
:
import cpnest
from cpnest.model import Model
class ModelClass(Model):
def __init__(self, times=time1, counts = data10): #time1 and data10 are just simple arrays
self.counts = counts
self.times = times
self.names = ['l0']
self.bounds=[[0,10]]
def log_likelihood(self,params):
model = model1(self.counts, params['l0'])
return np.sum(np.log(model)) - 5*np.log(2*np.pi)
if __name__ == '__main__':
my_model=ModelClass()
nest = cpnest.CPNest(my_model)
nest.run()
However, when running this code, I receive a new error for each process-process?
Traceback (most recent call last):
File "C:\Users\Rp199\anaconda3\lib\multiprocessing\process.py", line 315, in _bootstrap
self.run()
File "C:\Users\Rp199\anaconda3\lib\multiprocessing\process.py", line 108, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\Rp199\anaconda3\lib\site-packages\cpnest\sampler.py", line 173, in produce_sample
self._produce_sample()
File "C:\Users\Rp199\anaconda3\lib\site-packages\cpnest\sampler.py", line 185, in _produce_sample
self.reset()
File "C:\Users\Rp199\anaconda3\lib\site-packages\cpnest\sampler.py", line 113, in reset
for n in tqdm(range(self.poolsize), desc='SMPLR {} init draw'.format(self.thread_id),
AttributeError: 'MetropolisHastingsSampler' object has no attribute 'thread_id'
I am not sure on how to interpret this error and I don't know if it's because I used if __name__ == '__main__':
incorrectly or some other issue that I can't see.
Thanks