Ejemplo n.º 1
0
    def set_minimizer(self, minimizer):
        """
        Set the minimizer to be used, among those available.

        :param minimizer: the name of the new minimizer or an instance of a LocalMinimization or a GlobalMinimization
        class. Using the latter two classes allows for more choices and a better control of the details of the
        minimization, like the choice of algorithms (if supported by the used minimizer)
        :return: (none)
        """

        if isinstance(minimizer, minimization._Minimization):

            self._minimizer_type = minimizer

        else:

            assert minimizer.upper() in minimization._minimizers, (
                "Minimizer %s is not available on this system. "
                "Available minimizers: %s" %
                (minimizer, ",".join(list(minimization._minimizers.keys()))))

            # The string can only specify a local minimization. This will return an error if that is not the case.
            # In order to setup global optimization the user needs to use the GlobalMinimization factory directly

            self._minimizer_type = minimization.LocalMinimization(minimizer)
Ejemplo n.º 2
0
    def __init__(self,
                 likelihood_model,
                 data_list,
                 verbose=False,
                 record=True):
        """
        Implement a joint likelihood analysis.

        :param likelihood_model: the model for the likelihood analysis
        :param data_list: the list of data sets (plugin instances) to be used in this analysis
        :param verbose: (True or False) print every step in the -log likelihood minimization
        :param record: it records every call to the log likelihood function during minimization. The recorded values
        can be retrieved as a pandas DataFrame using the .fit_trace property
        :return:
        """

        self._analysis_type = "mle"

        # Process optional keyword parameters
        self.verbose = verbose

        self._likelihood_model = likelihood_model  # type: astromodels.core.model.Model

        self._data_list = data_list

        self._assign_model_to_data(self._likelihood_model)

        # This is to keep track of the number of calls to the likelihood
        # function
        self._record = bool(record)
        self._ncalls = 0
        self._record_calls = {}

        # Pre-defined minimizer
        default_minimizer = minimization.LocalMinimization(
            threeML_config["mle"]["default minimizer"])

        if threeML_config["mle"]["default minimizer algorithm"] is not None:

            default_minimizer.set_algorithm(
                threeML_config["mle"]["default minimizer algorithm"])

        self.set_minimizer(default_minimizer)

        # Initial set of free parameters

        self._free_parameters = self._likelihood_model.free_parameters

        # Initially set the value of _current_minimum to None, it will be change by the fit() method

        self._current_minimum = None

        # Null setup for minimizer

        self._minimizer = None

        self._minimizer_callback = None

        self._analysis_results = None