def initial_pool(self): initial_wrapper = _Initialpoolsampling(self.eps0 , self.data, self.model, \ self.distance , self.prior_dict) #print wrapper #print wrapper(1) if self.N_threads == 1: results = [] for i in range(self.N_particles): results.append(initial_wrapper(i)) else: self.pool = Pool(self.N_threads) self.mapfn = self.pool.map results = self.mapfn(initial_wrapper , range(self.N_particles)) self.pool.close() #self.pool.terminate() #self.pool.join() results = np.array(results).T self.theta_t = results[1:self.n_params+1,:] self.w_t = results[self.n_params+1,:] self.rhos = results[self.n_params+2,:] self.sig_t = 2. * utils.covariance(self.theta_t , self.w_t) plot_thetas(self.theta_t, self.w_t, self.prior_dict, 0, basename=self.basename)
def initial_pool(self): initial_wrapper = _Initialpoolsampling(self.eps0 , self.data, self.model, \ self.distance , self.prior_dict) #print wrapper #print wrapper(1) if self.N_threads == 1: results = [] for i in range(self.N_particles): results.append(initial_wrapper(i)) else: self.pool = Pool(self.N_threads) self.mapfn = self.pool.map results = self.mapfn(initial_wrapper , range(self.N_particles)) self.pool.close() #self.pool.terminate() #self.pool.join() results = np.array(results).T self.theta_t = results[1:self.n_params+1,:] self.w_t = results[self.n_params+1,:] / self.N_particles self.rhos = results[self.n_params+2:,:] self.sig_t = 2. * utils.covariance(self.theta_t , self.w_t) plot_thetas(self.theta_t, self.w_t, self.prior_dict, 0, basename=self.basename)
def run_abc(self): """ Run PMC_ABC """ self.initial_pool() t = 1 while t < self.T: self.eps_t = np.percentile(self.rhos, 75) print "iteration= " , t , "threshold= " , self.eps_t importance_wrapper = _Importancepoolsampling(self.eps_t, self.data, self.model, \ self.distance, self.prior_dict, \ self.theta_t, self.w_t, self.sig_t) if self.N_threads == 1 : results = [] for i in range(self.N_particles): results.append(importance_wrapper(i)) else: self.pool = Pool(self.N_threads) self.mapfn = self.pool.map results = self.mapfn(importance_wrapper, range(self.N_particles)) self.pool.close() #self.pool.terminate() #self.pool.join() results = np.array(results).T self.theta_t = results[1:self.n_params+1,:] self.w_t = results[self.n_params+1,:] self.rhos = results[self.n_params+2,:] self.sig_t = 2. * utils.covariance(self.theta_t, self.w_t) plot_thetas(self.theta_t, self.w_t, self.prior_dict, t, basename=self.basename, fig_name="{0}_{1}.png".format(self.basename, str(t))) t += 1
def run_abc(self): """ Run PMC_ABC """ self.initial_pool() t = 1 while t < self.T: self.eps_t = np.percentile(np.atleast_2d(self.rhos), 75, axis=1) print "iteration= " , t , "threshold= " , self.eps_t importance_wrapper = _Importancepoolsampling(self.eps_t, self.data, self.model, \ self.distance, self.prior_dict, \ self.theta_t, self.w_t, self.sig_t) if self.N_threads == 1 : results = [] for i in range(self.N_particles): results.append(importance_wrapper(i)) else: self.pool = Pool(self.N_threads) self.mapfn = self.pool.map results = self.mapfn(importance_wrapper, range(self.N_particles)) self.pool.close() #self.pool.terminate() #self.pool.join() results = np.array(results).T self.theta_t = results[1:self.n_params+1,:] self.w_t = results[self.n_params+1,:] self.rhos = results[self.n_params+2:,:] self.sig_t = 2. * utils.covariance(self.theta_t, self.w_t) plot_thetas(self.theta_t, self.w_t, self.prior_dict, t, basename=self.basename, fig_name="{0}_{1}.png".format(self.basename, str(t))) t += 1