Ejemplo n.º 1
0
 def run(self) -> SensitivityResult:
     """
     Run fits and comparisons for all perturbations, returning
     a list of results.
     """
     results = list()
     for result in Process.run_jobs(self._make_jobs(),
                                    number_of_cores=self.number_of_cores):
         results.append(result)
     return SensitivityResult(results)
Ejemplo n.º 2
0
    def fit_parallel(self, model, analysis, grid_priors):
        """
        Perform the grid search in parallel, with all the optimisation for each grid square being performed on a
        different process.

        Parameters
        ----------
        analysis
            An analysis
        grid_priors
            Priors describing the position in the grid

        Returns
        -------
        result: GridSearchResult
            The result of the grid search
        """

        grid_priors = list(set(grid_priors))
        results = []
        lists = self.make_lists(grid_priors)
        physical_lists = self.make_physical_lists(grid_priors)

        results_list = [["index"] +
                        list(map(model.name_for_prior, grid_priors)) +
                        ["likelihood_merit"]]

        jobs = list()

        for index, values in enumerate(lists):
            jobs.append(
                self.job_for_analysis_grid_priors_and_values(
                    analysis=copy.deepcopy(analysis),
                    model=model,
                    grid_priors=grid_priors,
                    values=values,
                    index=index,
                ))

        for result in Process.run_jobs(jobs, self.number_of_cores):
            results.append(result)
            results = sorted(results)
            results_list.append(result.result_list_row)
            self.write_results(results_list)

        return GridSearchResult([result.result for result in results], lists,
                                physical_lists)
Ejemplo n.º 3
0
    def run(self) -> SensitivityResult:
        """
        Run fits and comparisons for all perturbations, returning
        a list of results.
        """
        self.logger.info("Running")

        headers = [
            "index", *self._headers, "log_likelihood_base",
            "log_likelihood_perturbed", "log_likelihood_difference"
        ]
        physical_values = list(self._physical_values)

        results = list()
        for result in Process.run_jobs(self._make_jobs(),
                                       number_of_cores=self.number_of_cores):
            if isinstance(result, Exception):
                raise result

            results.append(result)
            results = sorted(results)

            os.makedirs(self.search.paths.output_path, exist_ok=True)
            with open(self.results_path, "w+") as f:
                writer = csv.writer(f)
                writer.writerow(headers)
                for result_ in results:
                    values = physical_values[result_.number]
                    writer.writerow(
                        padding(item) for item in [
                            result_.number,
                            *values,
                            result_.log_likelihood_base,
                            result_.log_likelihood_perturbed,
                            result_.log_likelihood_difference,
                        ])

        return SensitivityResult(results)