コード例 #1
0
ファイル: ultranest.py プロジェクト: OliverEdy/pycbc
    def from_config(cls, cp, model, output_file=None, **kwds):
        """
        Loads the sampler from the given config file.
        """
        skeys = {}
        opts = {
            'update_interval_iter_fraction': float,
            'update_interval_ncall': int,
            'log_interval': int,
            'show_status': bool,
            'dlogz': float,
            'dKL': float,
            'frac_remain': float,
            'Lepsilon': float,
            'min_ess': int,
            'max_iters': int,
            'max_ncalls': int,
            'log_dir': str,
            'stepsampling': bool,
            'enable_plots': bool,
            'max_num_improvement_loops': int,
            'min_num_live_points': int,
            'cluster_num_live_points:': int
        }
        for opt_name in opts:
            if cp.has_option('sampler', opt_name):
                value = cp.get('sampler', opt_name)
                skeys[opt_name] = opts[opt_name](value)
        inst = cls(model, **skeys)

        do_mpi, _, rank = use_mpi()
        if not do_mpi or (rank == 0):
            setup_output(inst, output_file)
        return inst
コード例 #2
0
    def __init__(self, generator, variable_args=(), record_failures=False,
                 **frozen_params):
        self.generator = generator
        self.variable_args = tuple(variable_args)
        self.frozen_params = frozen_params
        # we'll keep a dictionary of the current parameters for fast
        # generation
        self.current_params = frozen_params.copy()
        # keep a list of functions to call before waveform generation
        self._pregenerate_functions = []

        # If we are under mpi, then failed waveform will be stored by
        # mpi rank to avoid file writing conflicts. We'll check for this
        # upfront
        self.record_failures = (record_failures or
                                ('PYCBC_RECORD_FAILED_WAVEFORMS' in os.environ))
        self.mpi_enabled, _, self.mpi_rank = use_mpi()
コード例 #3
0
ファイル: ultranest.py プロジェクト: OliverEdy/pycbc
    def __init__(self,
                 model,
                 log_dir=None,
                 stepsampling=False,
                 enable_plots=False,
                 **kwargs):
        super(UltranestSampler, self).__init__(model)

        import ultranest
        log_likelihood_call, prior_call = setup_calls(model, copy_prior=True)

        # Check for cyclic boundaries
        periodic = []
        cyclic = self.model.prior_distribution.cyclic
        for param in self.variable_params:
            if param in cyclic:
                logging.info('Param: %s will be cyclic', param)
                periodic.append(True)
            else:
                periodic.append(False)

        self._sampler = ultranest.ReactiveNestedSampler(
            list(self.model.variable_params),
            log_likelihood_call,
            prior_call,
            log_dir=log_dir,
            wrapped_params=periodic,
            resume=True)

        if stepsampling:
            import ultranest.stepsampler
            self._sampler.stepsampler = ultranest.stepsampler.RegionBallSliceSampler(
                nsteps=100,
                adaptive_nsteps='move-distance',
                region_filter=True)

        self.enable_plots = enable_plots
        self.nlive = 0
        self.ndim = len(self.model.variable_params)
        self.result = None
        self.kwargs = kwargs  # Keywords for the run method of ultranest

        do_mpi, _, rank = use_mpi()
        self.main = (not do_mpi) or (rank == 0)