How to use ultranest - 5 common examples

To help you get started, we’ve selected a few ultranest examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github JohannesBuchner / BXA / bxa / xspec / solver.py View on Github external
l = -0.5 * Fit.statistic
			#print("like = %.1f" % l)
			if not numpy.isfinite(l):
				return -1e100
			return l
		
		# run multinest
		if Fit.statMethod.lower() not in BXASolver.allowed_stats:
			raise RuntimeError('ERROR: not using cash (Poisson likelihood) for Poisson data! set Fit.statMethod to cash before analysing (currently: %s)!' % Fit.statMethod)
		
		n_dims = len(self.paramnames)
		resume = kwargs.pop('resume', False)
		Lepsilon = kwargs.pop('Lepsilon', 0.1)

		with XSilence():
			self.results = solve(log_likelihood, self.prior_function, n_dims, 
				paramnames=self.paramnames,
				outputfiles_basename=self.outputfiles_basename, 
				resume=resume, Lepsilon=Lepsilon,
				n_live_points=n_live_points, evidence_tolerance=evidence_tolerance, 
				seed=-1, max_iter=0, wrapped_params=wrapped_params, **kwargs
			)
			self.posterior = self.results['samples']
			chainfilename = '%schain.fits' % self.outputfiles_basename
			store_chain(chainfilename, self.transformations, self.posterior)
			xspec.AllChains.clear()
			xspec.AllChains += chainfilename
		
			# set current parameters to best fit
			self.set_best_fit()
		
		return self.results
github JohannesBuchner / BXA / bxa / sherpa / solver.py View on Github external
#print "%.1f" % l
				return l
			except Exception as e:
				print('Exception in log_likelihood function: ', e)
				for i, p in enumerate(self.parameters):
					print('    Parameter %10s: %f --> %f [%f..%f]' % (p.fullname, p.val, cube[i], p.min, p.max))
				#import sys
				#sys.exit(-127)
				raise Exception("Model evaluation problem") from e
			return -1e300
		
		n_dims = len(self.parameters)
		resume = kwargs.pop('resume', False)
		Lepsilon = kwargs.pop('Lepsilon', 0.1)

		self.results = solve(log_likelihood, prior_transform, n_dims,
			paramnames=self.paramnames,
			outputfiles_basename=self.outputfiles_basename,
			resume=resume, Lepsilon=Lepsilon,
			n_live_points=n_live_points, evidence_tolerance=evidence_tolerance,
			seed=-1, max_iter=0, wrapped_params=wrapped_params, **kwargs
		)
		self.set_best_fit()
		return self.results
github threeML / threeML / threeML / bayesian / ultranest_sampler.py View on Github external
# We need to check if the MCMC
        # chains will have a place on
        # the disk to write and if not,
        # create one

        chain_name = self._kwargs.pop("chain_name")

        if threeML_config["parallel"]["use-parallel"]:

            raise RuntimeError(
                "If you want to run ultranest in parallell you need to use an ad-hoc method"
            )

        else:

            sampler = ultranest.ReactiveNestedSampler(
                param_names,
                loglike,
                transform=ultranest_prior,
                log_dir=chain_name,
                vectorized=False,
                resume=self._resume,
                wrapped_params=self._wrapped_params,
            )

            sampler.run(show_status=loud, **self._kwargs)

        process_fit = False

        if using_mpi:

            # if we are running in parallel and this is not the
github JohannesBuchner / BXA / bxa / xspec / solver.py View on Github external
ndata_columns = 6 if Plot.background else 4
			ncomponents = content.shape[1] - ndata_columns
			if data[0] is None:
				data[0] = content[:,0:ndata_columns]
			model_contributions = []
			for component in range(ncomponents):
				y = content[:, ndata_columns + component]
				kwargs = dict(drawstyle='steps', alpha=0.1, color='k')
				kwargs.update(plot_args[component])
				
				label = component_names[component]
				# we only label the first time we enter here
				# otherwise we get lots of entries in the legend
				component_names[component] = ''
				if component >= len(bands):
					bands.append(PredictionBand(xmid,
						shadeargs=dict(color=kwargs['color']),
						lineargs=dict(color=kwargs['color'])))
				if label != 'ignore':
					#plt.plot(xmid, y, label=label, **kwargs)
					bands[component].add(y)
				
				model_contributions.append(y)
			models.append(model_contributions)
github JohannesBuchner / BXA / bxa / xspec / solver.py View on Github external
def plot_unconvolved_components(content):
			xmid = content[:,0]
			ncomponents = content.shape[1] - 2
			for component in range(ncomponents):
				y = content[:, 2 + component]
				kwargs = dict(drawstyle='steps', alpha=0.1, color='k')
				kwargs.update(plot_args[component])
				
				label = component_names[component]
				# we only label the first time we enter here
				# otherwise we get lots of entries in the legend
				component_names[component] = ''
				if component >= len(bands):
					bands.append(PredictionBand(xmid,
						shadeargs=dict(color=kwargs['color']),
						lineargs=dict(color=kwargs['color'])))
				if label != 'ignore':
					#plt.plot(xmid, y, label=label, **kwargs)
					bands[component].add(y)

ultranest

Fit and compare complex models reliably and rapidly. Advanced Nested Sampling.

GPL-3.0
Latest version published 14 days ago

Package Health Score

76 / 100
Full package analysis

Similar packages