How to use the astromodels.ModelAssertionViolation function in astromodels

To help you get started, we’ve selected a few astromodels 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 threeML / threeML / threeML / classicMLE / joint_likelihood.py View on Github external
# Use the internal representation (see the Parameter class)

            parameter._set_internal_value(trial_values[i])

        # Now profile out nuisance parameters and compute the new value
        # for the likelihood

        summed_log_likelihood = 0

        for dataset in list(self._data_list.values()):

            try:

                this_log_like = dataset.inner_fit()

            except ModelAssertionViolation:

                # This is a zone of the parameter space which is not allowed. Return
                # a big number for the likelihood so that the fit engine will avoid it

                custom_warnings.warn(
                    "Fitting engine in forbidden space: %s" % (trial_values,),
                    custom_exceptions.ForbiddenRegionOfParameterSpace,
                )

                return minimization.FIT_FAILED

            except:

                # Do not intercept other errors

                raise
github threeML / threeML / threeML / bayesian / bayesian_analysis.py View on Github external
def _log_like(self, trial_values):
        """Compute the log-likelihood"""

        # Get the value of the log-likelihood for this parameters

        try:

            # Loop over each dataset and get the likelihood values for each set
            log_like_values = [ dataset.get_log_like() for dataset in self._data_list.values() ]
#            log_like_values = map(lambda dataset: dataset.get_log_like(), self._data_list.values())

        except ModelAssertionViolation:

            # Fit engine or sampler outside of allowed zone

            return -np.inf

        except:

            # We don't want to catch more serious issues

            raise

        # Sum the values of the log-like

        log_like = np.sum(log_like_values)

        if not np.isfinite(log_like):