From b72e004e0c108887ccc882f7b2787aeff15dbd81 Mon Sep 17 00:00:00 2001 From: Janos Gabler Date: Sun, 25 Oct 2026 10:28:31 +0100 Subject: [PATCH 1/2] Add likelihood benchmark sets Add four sets of maximum likelihood benchmark problems on simulated data: likelihood_small and likelihood_large (correctly specified, 3-25 and 25-150 params) and likelihood_misspecified_small and likelihood_misspecified_large (tiny to severe misspecification). Each instance has a good and a bad start. All problems minimize the negative log-likelihood and provide closed form jacobians of the contributions; some have bounds. Data are simulated from uniform draws via inverse CDFs, so they are stable across NumPy versions. Reference solutions are stored in solutions.py and created by .tools/create_likelihood_solutions.py. run_benchmark now sums likelihood contributions instead of treating them as least-squares residuals. Co-Authored-By: Claude Opus 5.5 --- .tools/create_likelihood_solutions.py | 331 +++ docs/source/how_to/how_to_benchmarking.ipynb | 2 + .../benchmarking/get_benchmark_problems.py | 59 +- .../benchmarking/likelihood/__init__.py | 0 .../benchmarking/likelihood/models.py | 1927 ++++++++++++++++ .../benchmarking/likelihood/problems.py | 1332 +++++++++++ .../benchmarking/likelihood/sampling.py | 96 + .../benchmarking/likelihood/solutions.py | 2038 +++++++++++++++++ src/optimagic/benchmarking/run_benchmark.py | 22 +- .../benchmarking/likelihood/__init__.py | 0 .../benchmarking/likelihood/test_models.py | 449 ++++ .../benchmarking/likelihood/test_problems.py | 171 ++ .../benchmarking/likelihood/test_sampling.py | 69 + .../test_get_benchmark_problems.py | 64 + .../benchmarking/test_run_benchmark.py | 42 + 15 files changed, 6595 insertions(+), 7 deletions(-) create mode 100644 .tools/create_likelihood_solutions.py create mode 100644 src/optimagic/benchmarking/likelihood/__init__.py create mode 100644 src/optimagic/benchmarking/likelihood/models.py create mode 100644 src/optimagic/benchmarking/likelihood/problems.py create mode 100644 src/optimagic/benchmarking/likelihood/sampling.py create mode 100644 src/optimagic/benchmarking/likelihood/solutions.py create mode 100644 tests/optimagic/benchmarking/likelihood/__init__.py create mode 100644 tests/optimagic/benchmarking/likelihood/test_models.py create mode 100644 tests/optimagic/benchmarking/likelihood/test_problems.py create mode 100644 tests/optimagic/benchmarking/likelihood/test_sampling.py diff --git a/.tools/create_likelihood_solutions.py b/.tools/create_likelihood_solutions.py new file mode 100644 index 000000000..4d4596978 --- /dev/null +++ b/.tools/create_likelihood_solutions.py @@ -0,0 +1,331 @@ +"""Compute the reference solutions of the likelihood benchmark sets. + +Writes ``src/optimagic/benchmarking/likelihood/solutions.py``. Run it after changing a +model or an instance of the likelihood benchmark sets: + + python .tools/create_likelihood_solutions.py [instance_name ...] + +Without arguments, all solutions are recomputed. With instance names, only those are +recomputed and the others are kept. + +Each solution is the best of several local optimizations (L-BFGS-B from the good start, +the bad start, the true params and a few perturbed starts), polished with projected +Newton steps on a numerical Hessian of the analytic gradient. + +""" + +import sys +from concurrent.futures import ProcessPoolExecutor +from typing import Any + +import numpy as np +from numpy.typing import NDArray +from scipy import linalg, optimize + +from optimagic.benchmarking.likelihood.models import SimulatedLikelihood +from optimagic.benchmarking.likelihood.problems import LIKELIHOOD_SETS +from optimagic.config import OPTIMAGIC_ROOT + +OUTPUT_PATH = OPTIMAGIC_ROOT / "benchmarking" / "likelihood" / "solutions.py" + +# a variable is treated as active if it is on its bound and the gradient does not +# point into the feasible set by more than this +ACTIVE_TOLERANCE = 1e-6 + + +def main(names: list[str]) -> None: + instances = { + instance.name: instance + for instances in LIKELIHOOD_SETS.values() + for instance in instances + } + if names: + unknown = set(names) - set(instances) + if unknown: + raise ValueError(f"Unknown instances: {sorted(unknown)}") + from optimagic.benchmarking.likelihood.solutions import LIKELIHOOD_SOLUTIONS + + solutions = dict(LIKELIHOOD_SOLUTIONS) + else: + names = list(instances) + solutions = {} + + with ProcessPoolExecutor() as executor: + results = executor.map(compute_reference_solution, names) + for name, (solution, report) in zip(names, results, strict=True): + solutions[name] = solution + print(f"{name:52s} {report}", flush=True) + + ordered = {name: solutions[name] for name in instances if name in solutions} + OUTPUT_PATH.write_text(_create_module_code(ordered)) + + +def compute_reference_solution(name: str) -> tuple[dict[str, Any], str]: + """Compute the reference solution of one instance. + + Returns: + The solution, with the entries "params", "value", "opg_hessian_ratio" and + "other_local_optima", and a one line report. + + """ + instance = next( + instance + for instances in LIKELIHOOD_SETS.values() + for instance in instances + if instance.name == name + ) + likelihood = instance.build() + lower, upper = _get_bounds(likelihood) + + starts = [likelihood.good_start, likelihood.bad_start] + start_names = ["good", "bad"] + if likelihood.true_params is not None: + starts.append(np.clip(likelihood.true_params, lower, upper)) + start_names.append("true") + rng = np.random.default_rng(0) + n_perturbed = 3 if likelihood.n_params <= 25 else 1 + for _ in range(n_perturbed): + scale = 0.5 * (1 + np.abs(likelihood.good_start)) + perturbed = likelihood.good_start + scale * rng.normal(size=likelihood.n_params) + starts.append(np.clip(perturbed, lower, upper)) + start_names.append("perturbed") + + optima = [] + for start in starts: + x = _minimize_lbfgsb(likelihood, start, lower, upper) + x = _polish(likelihood, x, lower, upper) + optima.append((_value(likelihood, x), x)) + values = np.array([value for value, _ in optima]) + best_value, best_x = min(optima, key=lambda pair: pair[0]) + + free = ~_is_active(likelihood, best_x, lower, upper) + jac = likelihood.jac(best_x)[:, free] + opg = jac.T @ jac + hessian = _numerical_hessian(likelihood, best_x, lower, upper)[np.ix_(free, free)] + ratio = linalg.eigh(opg, hessian, eigvals_only=True) + decrement = _opg_decrement(likelihood, best_x, free) + + is_worse = values > best_value + 1e-6 * (1 + abs(best_value)) + solution = { + "params": best_x, + "value": best_value, + "opg_hessian_ratio": (float(ratio.min()), float(ratio.max())), + "other_local_optima": bool(is_worse.any()), + } + worse_starts = [ + name for name, worse in zip(start_names, is_worse, strict=True) if worse + ] + report = ( + f"value={best_value:.6f} decrement={decrement:.1e} " + f"n_active={np.sum(~free)} ratio=[{ratio.min():.3f}, {ratio.max():.3f}] " + f"worse_local_optima_from={worse_starts}" + ) + return solution, report + + +def _get_bounds( + likelihood: SimulatedLikelihood, +) -> tuple[NDArray[np.float64], NDArray[np.float64]]: + k = likelihood.n_params + lower = likelihood.lower_bounds + upper = likelihood.upper_bounds + lower = np.full(k, -np.inf) if lower is None else lower + upper = np.full(k, np.inf) if upper is None else upper + return lower, upper + + +def _value(likelihood: SimulatedLikelihood, x: NDArray[np.float64]) -> float: + with np.errstate(all="ignore"): + value = float(likelihood.fun(x).sum()) + return value if np.isfinite(value) else np.inf + + +def _gradient( + likelihood: SimulatedLikelihood, x: NDArray[np.float64] +) -> NDArray[np.float64]: + with np.errstate(all="ignore"): + return likelihood.jac(x).sum(axis=0) + + +def _minimize_lbfgsb( + likelihood: SimulatedLikelihood, + start: NDArray[np.float64], + lower: NDArray[np.float64], + upper: NDArray[np.float64], +) -> NDArray[np.float64]: + def fun_and_grad(x: NDArray[np.float64]) -> tuple[float, NDArray[np.float64]]: + value = _value(likelihood, x) + if not np.isfinite(value): + return 1e300, np.zeros_like(x) + return value, _gradient(likelihood, x) + + res = optimize.minimize( + fun_and_grad, + start, + jac=True, + method="L-BFGS-B", + bounds=list(zip(lower, upper, strict=True)), + options={"maxiter": 100_000, "maxfun": 200_000, "ftol": 1e-15, "gtol": 1e-10}, + ) + return res.x + + +def _is_active( + likelihood: SimulatedLikelihood, + x: NDArray[np.float64], + lower: NDArray[np.float64], + upper: NDArray[np.float64], +) -> NDArray[np.bool_]: + gradient = _gradient(likelihood, x) + at_lower = (x <= lower) & (gradient >= -ACTIVE_TOLERANCE) + at_upper = (x >= upper) & (gradient <= ACTIVE_TOLERANCE) + return at_lower | at_upper + + +def _numerical_hessian( + likelihood: SimulatedLikelihood, + x: NDArray[np.float64], + lower: NDArray[np.float64], + upper: NDArray[np.float64], +) -> NDArray[np.float64]: + """Differentiate the analytic gradient; one-sided next to bounds.""" + k = len(x) + hessian = np.empty((k, k)) + for j in range(k): + h = 1e-5 * max(1.0, abs(x[j])) + step = np.zeros(k) + step[j] = h + if x[j] - h < lower[j]: + column = (_gradient(likelihood, x + step) - _gradient(likelihood, x)) / h + elif x[j] + h > upper[j]: + column = (_gradient(likelihood, x) - _gradient(likelihood, x - step)) / h + else: + forward = _gradient(likelihood, x + step) + backward = _gradient(likelihood, x - step) + column = (forward - backward) / (2 * h) + hessian[:, j] = column + return 0.5 * (hessian + hessian.T) + + +def _polish( + likelihood: SimulatedLikelihood, + x: NDArray[np.float64], + lower: NDArray[np.float64], + upper: NDArray[np.float64], +) -> NDArray[np.float64]: + """Polish a local solution, trying to put variables close to a bound on it. + + Close to a bound, the criterion can be so flat that L-BFGS-B stops before reaching + the bound (e.g. the stochastic frontier with wrong skew). Ties in the criterion + value are resolved in favor of the solution on the bound. + + """ + x = _polish_with_newton(likelihood, x, lower, upper) + distance = np.minimum(x - lower, upper - x) + close = (distance > 0) & (distance < 1e-4 * (1 + np.abs(x))) + if close.any(): + snapped = np.where(close & (x - lower < upper - x), lower, x) + snapped = np.where(close & (x - lower >= upper - x), upper, snapped) + snapped = _polish_with_newton(likelihood, snapped, lower, upper, fixed=close) + value = _value(likelihood, x) + is_tie = _value(likelihood, snapped) <= value + 1e-12 * (1 + abs(value)) + if is_tie and _is_active(likelihood, snapped, lower, upper)[close].all(): + x = snapped + return x + + +def _polish_with_newton( + likelihood: SimulatedLikelihood, + x: NDArray[np.float64], + lower: NDArray[np.float64], + upper: NDArray[np.float64], + fixed: NDArray[np.bool_] | None = None, + max_iterations: int = 30, +) -> NDArray[np.float64]: + """Polish a solution with projected Newton steps on the free variables. + + Variables that are active or fixed are not changed. + + Far from the solution, steps are accepted if they decrease the criterion. Close to + the solution, where the decrease is below the precision of the criterion value, + full steps are accepted if they decrease the decrement in the OPG metric. + + """ + fixed = np.zeros(len(x), dtype=bool) if fixed is None else fixed + value = _value(likelihood, x) + for _ in range(max_iterations): + free = ~(_is_active(likelihood, x, lower, upper) | fixed) + gradient = _gradient(likelihood, x)[free] + hessian = _numerical_hessian(likelihood, x, lower, upper)[np.ix_(free, free)] + eigenvalues, eigenvectors = np.linalg.eigh(hessian) + floor = 1e-12 * np.abs(eigenvalues).max() + eigenvalues = np.maximum(np.abs(eigenvalues), floor) + direction = np.zeros_like(x) + direction[free] = -eigenvectors @ ((eigenvectors.T @ gradient) / eigenvalues) + decrement = -gradient @ direction[free] + if decrement < 1e-24: + break + + if decrement < 1e-8: + candidate = np.clip(x + direction, lower, upper) + if _opg_decrement(likelihood, candidate, free) >= _opg_decrement( + likelihood, x, free + ): + break + x, value = candidate, _value(likelihood, candidate) + continue + + step_length = 1.0 + while step_length > 1e-8: + candidate = np.clip(x + step_length * direction, lower, upper) + candidate_value = _value(likelihood, candidate) + if candidate_value <= value: + break + step_length /= 2 + else: + break + x, value = candidate, candidate_value + return x + + +def _opg_decrement( + likelihood: SimulatedLikelihood, x: NDArray[np.float64], free: NDArray[np.bool_] +) -> float: + """Compute g @ inv(J.T @ J) @ g on the free variables.""" + with np.errstate(all="ignore"): + jac = likelihood.jac(x)[:, free] + gradient = jac.sum(axis=0) + return float(gradient @ np.linalg.lstsq(jac, np.ones(len(jac)), rcond=None)[0]) + + +def _create_module_code(solutions: dict[str, dict[str, Any]]) -> str: + lines = [ + '"""Reference solutions of the likelihood benchmark sets.', + "", + "Created by .tools/create_likelihood_solutions.py; do not edit by hand.", + "", + '"""', + "", + "from typing import Any", + "", + "# fmt: off", + "LIKELIHOOD_SOLUTIONS: dict[str, dict[str, Any]] = {", + ] + for name, solution in solutions.items(): + lines.append(f' "{name}": {{') + lines.append(' "params": [') + params = [repr(float(p)) for p in solution["params"]] + for i in range(0, len(params), 3): + lines.append(" " + ", ".join(params[i : i + 3]) + ",") + lines.append(" ],") + lines.append(f' "value": {float(solution["value"])!r},') + low, high = solution["opg_hessian_ratio"] + lines.append(f' "opg_hessian_ratio": ({low:.4g}, {high:.4g}),') + lines.append(f' "other_local_optima": {solution["other_local_optima"]},') + lines.append(" },") + lines += ["}", "# fmt: on", ""] + return "\n".join(lines) + + +if __name__ == "__main__": + main(sys.argv[1:]) diff --git a/docs/source/how_to/how_to_benchmarking.ipynb b/docs/source/how_to/how_to_benchmarking.ipynb index 7838f7c9f..0e5c1c9d4 100644 --- a/docs/source/how_to/how_to_benchmarking.ipynb +++ b/docs/source/how_to/how_to_benchmarking.ipynb @@ -28,6 +28,8 @@ "\n", "optimagic includes the problems of [Moré and Wild (2009)](https://doi.org/10.1137/080724083) as well as [Cartis and Roberts](https://arxiv.org/abs/1710.11005).\n", "\n", + "For maximum likelihood estimation, there are four sets of problems on simulated data: `\"likelihood_small\"` (3 to 25 parameters) and `\"likelihood_large\"` (25 to 150 parameters) contain correctly specified models, `\"likelihood_misspecified_small\"` and `\"likelihood_misspecified_large\"` misspecified ones, from tiny to severe misspecification. Each model is estimated from a good and a bad start. All problems minimize the negative log-likelihood, provide closed form derivatives and, where natural, bounds.\n", + "\n", "Each problem consist of the `inputs` (the criterion function and the start parameters) and the `solution` (the optimal parameters and criterion value) and optionally provides more information.\n", "\n", "Below we load a subset of the Moré and Wild problems and look at one particular Rosenbrock problem that has difficult start parameters." diff --git a/src/optimagic/benchmarking/get_benchmark_problems.py b/src/optimagic/benchmarking/get_benchmark_problems.py index 2986891ed..253a49f73 100644 --- a/src/optimagic/benchmarking/get_benchmark_problems.py +++ b/src/optimagic/benchmarking/get_benchmark_problems.py @@ -5,8 +5,13 @@ from optimagic import mark from optimagic.benchmarking.cartis_roberts import CARTIS_ROBERTS_PROBLEMS +from optimagic.benchmarking.likelihood.problems import ( + LIKELIHOOD_SETS, + get_likelihood_problems, +) from optimagic.benchmarking.more_wild import MORE_WILD_PROBLEMS from optimagic.benchmarking.noise_distributions import NOISE_DISTRIBUTIONS +from optimagic.parameters.bounds import Bounds from optimagic.shared.process_user_function import infer_aggregation_level from optimagic.typing import AggregationLevel from optimagic.utilities import get_rng @@ -27,8 +32,14 @@ def get_benchmark_problems( """Get a dictionary of test problems for a benchmark. Args: - name (str): The name of the set of test problems. Currently "more_wild" - is the only supported one. + name (str): The name of the set of test problems. One of "more_wild", + "cartis_roberts", "example", "estimagic", "likelihood_small", + "likelihood_large", "likelihood_misspecified_small" and + "likelihood_misspecified_large". The likelihood sets contain maximum + likelihood problems on simulated data, framed as minimization of the + negative log-likelihood. Their inputs contain closed form derivatives + (unless noise is added) and, for some problems, bounds. See + optimagic.benchmarking.likelihood.problems for details. additive_noise (bool): Whether to add additive noise to the problem. Default False. additive_noise_options (dict or None): Specifies the amount and distribution @@ -72,8 +83,9 @@ def get_benchmark_problems( dict: Nested dictionary with benchmark problems of the structure: {"name": {"inputs": {...}, "solution": {...}, "info": {...}}} where "inputs" are keyword arguments for ``minimize`` such as the criterion - function and start parameters. "solution" contains the entries "params" and - "value" and "info" might contain information about the test problem. + function, its derivatives, start parameters and bounds. "solution" + contains the entries "params" and "value" and "info" might contain + information about the test problem. """ if exclude is None: @@ -205,6 +217,8 @@ def _get_raw_problems(name): if k in subset_cr: raw_problems[k] = v + elif name in LIKELIHOOD_SETS: + raw_problems = get_likelihood_problems(name) else: raise NotImplementedError() return raw_problems @@ -245,6 +259,30 @@ def _create_problem_inputs( _criterion = problem_type_to_marker[problem_type](_criterion) inputs = {"fun": _criterion, "params": _x} + + # Closed form derivatives would not match the noisy criterion. + is_noisy = additive_options is not None or multiplicative_options is not None + if "jac" in specification and not is_noisy: + _jac = partial( + _internal_jac_template, + jac=specification["jac"], + scaling_factor=scaling_factor, + ) + _gradient = partial( + _internal_gradient_template, + jac=specification["jac"], + scaling_factor=scaling_factor, + ) + inputs["jac"] = [mark.scalar(_gradient), mark.likelihood(_jac)] + + lower = specification.get("lower_bounds") + upper = specification.get("upper_bounds") + if lower is not None or upper is not None: + if scaling_factor is not None: + lower = None if lower is None else lower * scaling_factor + upper = None if upper is None else upper * scaling_factor + inputs["bounds"] = Bounds(lower=lower, upper=upper) + return inputs @@ -291,6 +329,19 @@ def _internal_criterion_template( return noisy_critval +def _internal_jac_template(params, jac, scaling_factor): + if scaling_factor is not None: + params = params / scaling_factor + out = jac(params) + if scaling_factor is not None: + out = out / scaling_factor + return out + + +def _internal_gradient_template(params, jac, scaling_factor): + return _internal_jac_template(params, jac, scaling_factor).sum(axis=0) + + def _get_combined_noise(fval, additive_options, multiplicative_options, rng): size = len(np.atleast_1d(fval)) if multiplicative_options is not None: diff --git a/src/optimagic/benchmarking/likelihood/__init__.py b/src/optimagic/benchmarking/likelihood/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/src/optimagic/benchmarking/likelihood/models.py b/src/optimagic/benchmarking/likelihood/models.py new file mode 100644 index 000000000..d28afe8fb --- /dev/null +++ b/src/optimagic/benchmarking/likelihood/models.py @@ -0,0 +1,1927 @@ +"""Simulated likelihood models for the likelihood benchmark sets. + +Each public function simulates a dataset from a data generating process and returns a +:class:`SimulatedLikelihood` for a (possibly misspecified) model of that data. All +criterion functions return the negative log-likelihood contributions, i.e. the sum of +the contributions is minimized. + +Data are simulated with a seeded random number generator (see ``sampling``), so every +problem is deterministic. Arguments that start with ``dgp_`` change only the data +generating process; when they deviate from their default, the model is misspecified. + +""" + +from dataclasses import dataclass +from functools import partial +from typing import Callable, Literal + +import numpy as np +from numpy.typing import NDArray +from scipy import linalg, signal, special + +from optimagic.benchmarking.likelihood import sampling + +_LOG_SQRT_2PI = 0.5 * np.log(2 * np.pi) + +ParamsFunction = Callable[[NDArray[np.float64]], NDArray[np.float64]] + + +@dataclass(frozen=True) +class SimulatedLikelihood: + fun: ParamsFunction + """Negative log-likelihood contributions; maps params (k,) to an array (n_obs,).""" + + jac: ParamsFunction + """Jacobian of fun; maps params (k,) to an array of shape (n_obs, k).""" + + good_start: NDArray[np.float64] + """Start values a practitioner would choose without knowing the solution.""" + + bad_start: NDArray[np.float64] + """Start values far from the solution with finite criterion and derivatives.""" + + lower_bounds: NDArray[np.float64] | None = None + """Lower bounds on the params or None if the problem is unbounded from below.""" + + upper_bounds: NDArray[np.float64] | None = None + """Upper bounds on the params or None if the problem is unbounded from above.""" + + true_params: NDArray[np.float64] | None = None + """Params of the data generating process; None if the model is misspecified.""" + + unique_solution: bool = True + """False if the solution is only unique up to relabeling (e.g. mixture models).""" + + @property + def n_params(self) -> int: + return len(self.good_start) + + +# ====================================================================================== +# Shared helpers +# ====================================================================================== + + +def _covariates( + rng: np.random.Generator, + n_obs: int, + n_covariates: int, + correlation: float = 0.0, +) -> NDArray[np.float64]: + """Draw standard normal covariates with equal pairwise correlation. + + Returns: + Array of shape (n_obs, n_covariates). + + """ + x = sampling.standard_normal(rng, (n_obs, n_covariates)) + if correlation != 0: + common = sampling.standard_normal(rng, (n_obs, 1)) + x = np.sqrt(1 - correlation) * x + np.sqrt(correlation) * common + return x + + +def _add_intercept(x: NDArray[np.float64]) -> NDArray[np.float64]: + return np.column_stack([np.ones(len(x)), x]) + + +def _slopes(n_slopes: int, strength: float) -> NDArray[np.float64]: + """Create a deterministic slope pattern with alternating signs. + + For uncorrelated standard normal covariates, the linear index has standard + deviation ``strength``. + + """ + j = np.arange(n_slopes) + raw = (-1.0) ** j * (0.5 + 0.5 * ((0.618034 * (j + 1)) % 1.0)) + if n_slopes == 0: + return raw + return strength * raw / np.linalg.norm(raw) + + +def _regressor_scales(n_covariates: int, badly_scaled: bool) -> NDArray[np.float64]: + """Return column scales between 0.01 and 100 if badly_scaled, otherwise ones.""" + if badly_scaled: + return np.logspace(-2, 2, n_covariates) + return np.ones(n_covariates) + + +def _overdispersed_counts( + rng: np.random.Generator, mean: NDArray[np.float64], dispersion: float +) -> NDArray[np.float64]: + """Draw counts with the given mean and variance dispersion * mean. + + A dispersion of one gives Poisson counts, a dispersion above one gamma-mixed + Poisson (negative binomial) counts and a dispersion below one binomial counts. + + """ + if dispersion == 1: + return sampling.poisson(rng, mean) + if dispersion > 1: + excess = dispersion - 1 + rate = sampling.gamma(rng, mean / excess, excess, mean.shape) + return sampling.poisson(rng, rate) + probability = 1 - dispersion + n_trials = np.maximum(np.round(mean / probability), 1) + return sampling.binomial(rng, n_trials, probability) + + +def _logsumexp(a: NDArray[np.float64], axis: int) -> NDArray[np.float64]: + """Compute log(sum(exp(a))) along axis; faster than scipy for finite inputs.""" + a_max = a.max(axis=axis, keepdims=True) + out = np.log(np.exp(a - a_max).sum(axis=axis, keepdims=True)) + a_max + return np.squeeze(out, axis=axis) + + +def _log_normal_pdf(z: NDArray[np.float64]) -> NDArray[np.float64]: + return -0.5 * z**2 - _LOG_SQRT_2PI + + +def _inverse_mills(z: NDArray[np.float64]) -> NDArray[np.float64]: + """Compute phi(z) / Phi(z), accurate also for very negative z.""" + return np.exp(_log_normal_pdf(z) - special.log_ndtr(z)) + + +def _log_normal_interval( + lower: NDArray[np.float64], upper: NDArray[np.float64] +) -> NDArray[np.float64]: + """Compute log(Phi(upper) - Phi(lower)) for lower < upper, accurate in the tails.""" + flip = lower > 0 + lo = np.where(flip, -upper, lower) + hi = np.where(flip, -lower, upper) + log_hi = special.log_ndtr(hi) + log_lo = special.log_ndtr(lo) + with np.errstate(divide="ignore"): + return log_hi + np.log(-np.expm1(log_lo - log_hi)) + + +def _clip( + x: NDArray[np.float64], + lower: NDArray[np.float64] | None, + upper: NDArray[np.float64] | None, +) -> NDArray[np.float64]: + lower = np.full_like(x, -np.inf) if lower is None else lower + upper = np.full_like(x, np.inf) if upper is None else upper + return np.clip(x, lower, upper) + + +def _simulated_likelihood( + *, + fun: ParamsFunction, + jac: ParamsFunction, + good_start: NDArray[np.float64], + bad_start: NDArray[np.float64], + true_params: NDArray[np.float64] | None, + lower_bounds: NDArray[np.float64] | None = None, + upper_bounds: NDArray[np.float64] | None = None, + unique_solution: bool = True, +) -> SimulatedLikelihood: + """Create a SimulatedLikelihood with start values clipped to the bounds.""" + return SimulatedLikelihood( + fun=fun, + jac=jac, + good_start=_clip( + np.asarray(good_start, dtype=float), lower_bounds, upper_bounds + ), + bad_start=_clip(np.asarray(bad_start, dtype=float), lower_bounds, upper_bounds), + lower_bounds=lower_bounds, + upper_bounds=upper_bounds, + true_params=true_params, + unique_solution=unique_solution, + ) + + +# ====================================================================================== +# Binary choice: logit and probit +# ====================================================================================== + + +def binary_choice( + *, + n_obs: int, + n_params: int, + seed: int, + model: Literal["logit", "probit"] = "logit", + strength: float = 1.0, + correlation: float = 0.0, + badly_scaled: bool = False, + n_sign_restricted: int = 0, + dgp_errors: Literal["logistic", "normal"] | None = None, + dgp_misclassification: float = 0.0, + dgp_heteroskedasticity: float = 0.0, +) -> SimulatedLikelihood: + """Simulate a binary logit or probit model with an intercept. + + Args: + n_obs: Number of observations. + n_params: Number of params (intercept plus slopes). + seed: Seed of the random number generator. + model: The estimated model. + strength: Standard deviation of the linear index without intercept. + correlation: Pairwise correlation of the covariates. + badly_scaled: If True, the covariates have scales between 0.01 and 100. + n_sign_restricted: The last n_sign_restricted slopes get a lower bound of + zero. Restrictions on slopes whose true value is negative are binding. + dgp_errors: Distribution of the latent errors. Defaults to the one implied by + model. + dgp_misclassification: Probability that an outcome is flipped. + dgp_heteroskedasticity: Coefficient of the first covariate in the log standard + deviation of the latent errors. + + """ + rng = np.random.default_rng(seed) + n_covariates = n_params - 1 + scales = _regressor_scales(n_covariates, badly_scaled) + x = _add_intercept(_covariates(rng, n_obs, n_covariates, correlation) * scales) + true_params = np.r_[0.3, _slopes(n_covariates, strength) / scales] + + default_errors = "logistic" if model == "logit" else "normal" + errors = default_errors if dgp_errors is None else dgp_errors + if errors == "logistic": + epsilon = sampling.standard_logistic(rng, n_obs) + else: + epsilon = sampling.standard_normal(rng, n_obs) + epsilon = epsilon * np.exp(dgp_heteroskedasticity * x[:, 1] / scales[0]) + y = (x @ true_params + epsilon > 0).astype(float) + if dgp_misclassification > 0: + flip = sampling.uniform(rng, n_obs) < dgp_misclassification + y = np.where(flip, 1 - y, y) + + is_correct = ( + errors == default_errors + and dgp_misclassification == 0 + and dgp_heteroskedasticity == 0 + and n_sign_restricted == 0 + ) + + if n_sign_restricted > 0: + lower = np.full(n_params, -np.inf) + lower[n_params - n_sign_restricted :] = 0.0 + else: + lower = None + + share = y.mean() + if model == "logit": + fun, jac = _logit_fun, _logit_jac + intercept = special.logit(share) + else: + fun, jac = _probit_fun, _probit_jac + intercept = special.ndtri(share) + + return _simulated_likelihood( + fun=partial(fun, x=x, y=y), + jac=partial(jac, x=x, y=y), + good_start=np.r_[intercept, np.zeros(n_covariates)], + bad_start=np.r_[-2.0, -4 * true_params[1:]], + true_params=true_params if is_correct else None, + lower_bounds=lower, + ) + + +def _logit_fun( + params: NDArray[np.float64], *, x: NDArray[np.float64], y: NDArray[np.float64] +) -> NDArray[np.float64]: + return -special.log_expit((2 * y - 1) * (x @ params)) + + +def _logit_jac( + params: NDArray[np.float64], *, x: NDArray[np.float64], y: NDArray[np.float64] +) -> NDArray[np.float64]: + return -(y - special.expit(x @ params))[:, None] * x + + +def _probit_fun( + params: NDArray[np.float64], *, x: NDArray[np.float64], y: NDArray[np.float64] +) -> NDArray[np.float64]: + return -special.log_ndtr((2 * y - 1) * (x @ params)) + + +def _probit_jac( + params: NDArray[np.float64], *, x: NDArray[np.float64], y: NDArray[np.float64] +) -> NDArray[np.float64]: + sign = 2 * y - 1 + return -(sign * _inverse_mills(sign * (x @ params)))[:, None] * x + + +# ====================================================================================== +# Count data: Poisson, fixed effects Poisson, negative binomial, zero inflated Poisson +# ====================================================================================== + + +def poisson_regression( + *, + n_obs: int, + n_params: int, + seed: int, + strength: float = 0.5, + correlation: float = 0.0, + dgp_dispersion: float = 1.0, +) -> SimulatedLikelihood: + """Simulate a Poisson regression with an intercept. + + Args: + n_obs: Number of observations. + n_params: Number of params (intercept plus slopes). + seed: Seed of the random number generator. + strength: Standard deviation of the linear index without intercept. + correlation: Pairwise correlation of the covariates. + dgp_dispersion: Ratio of the variance to the mean of the counts. Values other + than one make the Poisson likelihood a quasi-likelihood. + + """ + rng = np.random.default_rng(seed) + x = _add_intercept(_covariates(rng, n_obs, n_params - 1, correlation)) + true_params = np.r_[1.0, _slopes(n_params - 1, strength)] + y = _overdispersed_counts(rng, np.exp(x @ true_params), dgp_dispersion) + + log_mean = np.log(y.mean()) + return _simulated_likelihood( + fun=partial(_poisson_fun, x=x, y=y), + jac=partial(_poisson_jac, x=x, y=y), + good_start=np.r_[log_mean, np.zeros(n_params - 1)], + bad_start=np.r_[log_mean + 3, -3 * true_params[1:]], + true_params=true_params if dgp_dispersion == 1 else None, + ) + + +def _poisson_fun( + params: NDArray[np.float64], *, x: NDArray[np.float64], y: NDArray[np.float64] +) -> NDArray[np.float64]: + index = x @ params + return np.exp(index) - y * index + special.gammaln(y + 1) + + +def _poisson_jac( + params: NDArray[np.float64], *, x: NDArray[np.float64], y: NDArray[np.float64] +) -> NDArray[np.float64]: + return (np.exp(x @ params) - y)[:, None] * x + + +def fixed_effects_poisson( + *, + n_groups: int, + n_periods: int, + n_slopes: int, + seed: int, + strength: float = 0.5, + dgp_dispersion: float = 1.0, +) -> SimulatedLikelihood: + """Simulate a panel Poisson regression with group fixed effects. + + The params are the slopes followed by one fixed effect per group. The covariates + are correlated with the fixed effects. + + Args: + n_groups: Number of groups. + n_periods: Number of observations per group. + n_slopes: Number of slopes. + seed: Seed of the random number generator. + strength: Standard deviation of the linear index without fixed effects. + dgp_dispersion: Ratio of the variance to the mean of the counts. + + """ + rng = np.random.default_rng(seed) + n_obs = n_groups * n_periods + group = np.repeat(np.arange(n_groups), n_periods) + effects = 1.5 + 0.3 * sampling.standard_normal(rng, n_groups) + x = _covariates(rng, n_obs, n_slopes) + (effects[group] - 1.5)[:, None] + slopes = _slopes(n_slopes, strength) + true_params = np.r_[slopes, effects] + y = _overdispersed_counts(rng, np.exp(x @ slopes + effects[group]), dgp_dispersion) + + return _simulated_likelihood( + fun=partial(_fixed_effects_poisson_fun, x=x, y=y, group=group), + jac=partial(_fixed_effects_poisson_jac, x=x, y=y, group=group), + good_start=np.r_[np.zeros(n_slopes), np.full(n_groups, np.log(y.mean()))], + bad_start=np.r_[-3 * slopes, np.full(n_groups, np.log(y.mean()) - 2)], + true_params=true_params if dgp_dispersion == 1 else None, + ) + + +def _fixed_effects_poisson_fun( + params: NDArray[np.float64], + *, + x: NDArray[np.float64], + y: NDArray[np.float64], + group: NDArray[np.int64], +) -> NDArray[np.float64]: + n_slopes = x.shape[1] + index = x @ params[:n_slopes] + params[n_slopes:][group] + return np.exp(index) - y * index + special.gammaln(y + 1) + + +def _fixed_effects_poisson_jac( + params: NDArray[np.float64], + *, + x: NDArray[np.float64], + y: NDArray[np.float64], + group: NDArray[np.int64], +) -> NDArray[np.float64]: + n_slopes = x.shape[1] + residual = np.exp(x @ params[:n_slopes] + params[n_slopes:][group]) - y + out = np.zeros((len(y), len(params))) + out[:, :n_slopes] = residual[:, None] * x + out[np.arange(len(y)), n_slopes + group] = residual + return out + + +def negative_binomial( + *, + n_obs: int, + n_params: int, + seed: int, + strength: float = 0.5, + dispersion: float = 0.7, +) -> SimulatedLikelihood: + """Simulate a negative binomial (NB2) regression. + + The params are the regression coefficients (with intercept) followed by the log of + the dispersion parameter alpha, where Var(y) = mu + alpha * mu**2. + + Args: + n_obs: Number of observations. + n_params: Number of params. + seed: Seed of the random number generator. + strength: Standard deviation of the linear index without intercept. + dispersion: The true alpha. + + """ + rng = np.random.default_rng(seed) + n_slopes = n_params - 2 + x = _add_intercept(_covariates(rng, n_obs, n_slopes)) + beta = np.r_[1.0, _slopes(n_slopes, strength)] + mean = np.exp(x @ beta) + rate = sampling.gamma(rng, 1 / dispersion, dispersion * mean, n_obs) + y = sampling.poisson(rng, rate) + + log_mean = np.log(y.mean()) + return _simulated_likelihood( + fun=partial(_negative_binomial_fun, x=x, y=y), + jac=partial(_negative_binomial_jac, x=x, y=y), + good_start=np.r_[log_mean, np.zeros(n_slopes), 0.0], + bad_start=np.r_[log_mean + 2, -3 * beta[1:], 3.0], + true_params=np.r_[beta, np.log(dispersion)], + ) + + +def _negative_binomial_fun( + params: NDArray[np.float64], *, x: NDArray[np.float64], y: NDArray[np.float64] +) -> NDArray[np.float64]: + index = x @ params[:-1] + r = np.exp(-params[-1]) + log_r_plus_mean = np.logaddexp(np.log(r), index) + loglike = ( + special.gammaln(y + r) + - special.gammaln(r) + - special.gammaln(y + 1) + + r * (np.log(r) - log_r_plus_mean) + + y * (index - log_r_plus_mean) + ) + return -loglike + + +def _negative_binomial_jac( + params: NDArray[np.float64], *, x: NDArray[np.float64], y: NDArray[np.float64] +) -> NDArray[np.float64]: + mean = np.exp(x @ params[:-1]) + r = np.exp(-params[-1]) + d_index = r * (y - mean) / (r + mean) + d_r = ( + special.digamma(y + r) + - special.digamma(r) + + np.log(r / (r + mean)) + + (mean - y) / (r + mean) + ) + return -np.column_stack([d_index[:, None] * x, -r * d_r]) + + +def zero_inflated_poisson( + *, + n_obs: int, + n_inflation_params: int, + n_count_params: int, + seed: int, + dgp_dispersion: float | None = None, +) -> SimulatedLikelihood: + """Simulate a zero inflated Poisson regression. + + The params are the coefficients of the logit model for structural zeros followed by + the coefficients of the Poisson model. Both include an intercept and share the + leading covariates. + + Args: + n_obs: Number of observations. + n_inflation_params: Number of params of the inflation model. + n_count_params: Number of params of the count model. + seed: Seed of the random number generator. + dgp_dispersion: If not None, the data are negative binomial counts with this + dispersion (variance over mean) and without zero inflation. + + """ + rng = np.random.default_rng(seed) + n_covariates = max(n_inflation_params, n_count_params) - 1 + covariates = _covariates(rng, n_obs, n_covariates) + z = _add_intercept(covariates[:, : n_inflation_params - 1]) + x = _add_intercept(covariates[:, : n_count_params - 1]) + gamma = np.r_[-1.0, _slopes(n_inflation_params - 1, 0.5)] + beta = np.r_[1.0, _slopes(n_count_params - 1, 0.4)[::-1]] + + if dgp_dispersion is None: + counts = sampling.poisson(rng, np.exp(x @ beta)) + structural_zero = sampling.uniform(rng, n_obs) < special.expit(z @ gamma) + y = np.where(structural_zero, 0.0, counts) + else: + y = _overdispersed_counts(rng, np.exp(x @ beta), dgp_dispersion) + + log_mean = np.log(y.mean()) + return _simulated_likelihood( + fun=partial(_zero_inflated_poisson_fun, z=z, x=x, y=y), + jac=partial(_zero_inflated_poisson_jac, z=z, x=x, y=y), + good_start=np.r_[ + np.zeros(n_inflation_params), log_mean, np.zeros(len(beta) - 1) + ], + bad_start=np.r_[3.0, -3 * gamma[1:], log_mean + 2, -3 * beta[1:]], + true_params=np.r_[gamma, beta] if dgp_dispersion is None else None, + ) + + +def _zero_inflated_poisson_loglike( + params: NDArray[np.float64], + z: NDArray[np.float64], + x: NDArray[np.float64], + y: NDArray[np.float64], +) -> tuple[NDArray[np.float64], ...]: + inflation_index = z @ params[: z.shape[1]] + count_index = x @ params[z.shape[1] :] + mean = np.exp(count_index) + log_inflation = special.log_expit(inflation_index) + log_no_inflation = special.log_expit(-inflation_index) + loglike = np.where( + y == 0, + np.logaddexp(log_inflation, log_no_inflation - mean), + log_no_inflation + y * count_index - mean - special.gammaln(y + 1), + ) + return loglike, log_inflation, mean + + +def _zero_inflated_poisson_fun( + params: NDArray[np.float64], + *, + z: NDArray[np.float64], + x: NDArray[np.float64], + y: NDArray[np.float64], +) -> NDArray[np.float64]: + return -_zero_inflated_poisson_loglike(params, z, x, y)[0] + + +def _zero_inflated_poisson_jac( + params: NDArray[np.float64], + *, + z: NDArray[np.float64], + x: NDArray[np.float64], + y: NDArray[np.float64], +) -> NDArray[np.float64]: + loglike, log_inflation, mean = _zero_inflated_poisson_loglike(params, z, x, y) + inflation = np.exp(log_inflation) + is_zero = y == 0 + # posterior probability that a zero is structural + structural = np.zeros_like(y) + structural[is_zero] = np.exp(log_inflation[is_zero] - loglike[is_zero]) + d_inflation = np.where(is_zero, structural - inflation, -inflation) + d_count = np.where(is_zero, -(1 - structural) * mean, y - mean) + return -np.column_stack([d_inflation[:, None] * z, d_count[:, None] * x]) + + +# ====================================================================================== +# Continuous outcomes: linear regression, Tobit, gamma regression, stochastic frontier +# ====================================================================================== + + +def linear_regression( + *, + n_obs: int, + n_mean_params: int, + n_variance_params: int, + seed: int, + correlation: float = 0.0, + dgp_error_df: float | None = None, + dgp_heteroskedasticity: float = 0.0, +) -> SimulatedLikelihood: + """Simulate a normal linear regression with multiplicative heteroskedasticity. + + The params are the mean coefficients beta followed by the variance coefficients + gamma, with log sd(y_i) = z_i @ gamma. Both x and z include an intercept and z uses + the leading covariates of x. + + Args: + n_obs: Number of observations. + n_mean_params: Number of mean params (intercept plus slopes). + n_variance_params: Number of variance params (at most n_mean_params). + seed: Seed of the random number generator. + correlation: Pairwise correlation of the covariates. + dgp_error_df: If not None, the errors are t distributed with this many degrees + of freedom instead of normal. + dgp_heteroskedasticity: Additional coefficient of the first covariate in the + log standard deviation of the errors that the model ignores. + + """ + rng = np.random.default_rng(seed) + x = _add_intercept(_covariates(rng, n_obs, n_mean_params - 1, correlation)) + z = x[:, :n_variance_params] + beta = np.r_[2.0, _slopes(n_mean_params - 1, 1.0)] + gamma = np.r_[0.0, _slopes(n_variance_params - 1, 0.5)[::-1]] + + if dgp_error_df is None: + errors = sampling.standard_normal(rng, n_obs) + else: + errors = sampling.standardized_t(rng, dgp_error_df, n_obs) + log_sd = z @ gamma + dgp_heteroskedasticity * x[:, 1] + y = x @ beta + np.exp(log_sd) * errors + + is_correct = dgp_error_df is None and dgp_heteroskedasticity == 0 + log_sd_y = np.log(y.std()) + return _simulated_likelihood( + fun=partial(_linear_regression_fun, x=x, z=z, y=y), + jac=partial(_linear_regression_jac, x=x, z=z, y=y), + good_start=np.r_[ + y.mean(), np.zeros(n_mean_params - 1), log_sd_y, np.zeros(len(gamma) - 1) + ], + bad_start=np.r_[0.0, -3 * beta[1:], log_sd_y - 3, -3 * gamma[1:]], + true_params=np.r_[beta, gamma] if is_correct else None, + ) + + +def _linear_regression_fun( + params: NDArray[np.float64], + *, + x: NDArray[np.float64], + z: NDArray[np.float64], + y: NDArray[np.float64], +) -> NDArray[np.float64]: + n_mean = x.shape[1] + log_sd = z @ params[n_mean:] + residual = y - x @ params[:n_mean] + return _LOG_SQRT_2PI + log_sd + 0.5 * (residual * np.exp(-log_sd)) ** 2 + + +def _linear_regression_jac( + params: NDArray[np.float64], + *, + x: NDArray[np.float64], + z: NDArray[np.float64], + y: NDArray[np.float64], +) -> NDArray[np.float64]: + n_mean = x.shape[1] + precision = np.exp(-2 * z @ params[n_mean:]) + residual = y - x @ params[:n_mean] + d_mean = -(residual * precision)[:, None] * x + d_variance = (1 - residual**2 * precision)[:, None] * z + return np.column_stack([d_mean, d_variance]) + + +def tobit( + *, + n_obs: int, + n_params: int, + seed: int, + dgp_error_df: float | None = None, + dgp_heteroskedasticity: float = 0.0, +) -> SimulatedLikelihood: + """Simulate a Tobit model, left censored at zero. + + The params are the coefficients (with intercept) followed by the log of the error + standard deviation. + + Args: + n_obs: Number of observations. + n_params: Number of params. + seed: Seed of the random number generator. + dgp_error_df: If not None, the errors are t distributed with this many degrees + of freedom instead of normal. + dgp_heteroskedasticity: Coefficient of the first covariate in the log standard + deviation of the errors that the model ignores. + + """ + rng = np.random.default_rng(seed) + n_slopes = n_params - 2 + x = _add_intercept(_covariates(rng, n_obs, n_slopes)) + beta = np.r_[0.5, _slopes(n_slopes, 1.0)] + sd = 1.5 + if dgp_error_df is None: + errors = sampling.standard_normal(rng, n_obs) + else: + errors = sampling.standardized_t(rng, dgp_error_df, n_obs) + errors = errors * sd * np.exp(dgp_heteroskedasticity * x[:, 1]) + y = np.maximum(x @ beta + errors, 0.0) + + is_correct = dgp_error_df is None and dgp_heteroskedasticity == 0 + log_sd_y = np.log(y.std()) + return _simulated_likelihood( + fun=partial(_tobit_fun, x=x, y=y), + jac=partial(_tobit_jac, x=x, y=y), + good_start=np.r_[y.mean(), np.zeros(n_slopes), log_sd_y], + bad_start=np.r_[-3.0, -3 * beta[1:], log_sd_y - 3], + true_params=np.r_[beta, np.log(sd)] if is_correct else None, + ) + + +def _tobit_fun( + params: NDArray[np.float64], *, x: NDArray[np.float64], y: NDArray[np.float64] +) -> NDArray[np.float64]: + index = x @ params[:-1] + log_sd = params[-1] + standardized = (y - index) * np.exp(-log_sd) + loglike = np.where( + y > 0, + _log_normal_pdf(standardized) - log_sd, + special.log_ndtr(standardized), + ) + return -loglike + + +def _tobit_jac( + params: NDArray[np.float64], *, x: NDArray[np.float64], y: NDArray[np.float64] +) -> NDArray[np.float64]: + index = x @ params[:-1] + sd = np.exp(params[-1]) + standardized = (y - index) / sd + # at censored observations, standardized is -index / sd + mills = _inverse_mills(standardized) + d_index = np.where(y > 0, standardized / sd, -mills / sd) + d_log_sd = np.where(y > 0, standardized**2 - 1, -mills * standardized) + return -np.column_stack([d_index[:, None] * x, d_log_sd]) + + +def gamma_regression( + *, + n_obs: int, + n_params: int, + seed: int, + dgp_lognormal: bool = False, +) -> SimulatedLikelihood: + """Simulate a gamma regression with log link. + + The params are the coefficients of the log mean (with intercept) followed by the + log of the shape parameter. + + Args: + n_obs: Number of observations. + n_params: Number of params. + seed: Seed of the random number generator. + dgp_lognormal: If True, the outcomes are lognormal with the same mean and + variance as the gamma distribution. + + """ + rng = np.random.default_rng(seed) + n_slopes = n_params - 2 + x = _add_intercept(_covariates(rng, n_obs, n_slopes)) + beta = np.r_[1.0, _slopes(n_slopes, 0.5)] + shape = 2.0 + mean = np.exp(x @ beta) + if dgp_lognormal: + sd = np.sqrt(np.log(1 + 1 / shape)) + y = mean * np.exp(sd * sampling.standard_normal(rng, n_obs) - 0.5 * sd**2) + else: + y = sampling.gamma(rng, shape, mean / shape, n_obs) + + log_mean = np.log(y.mean()) + return _simulated_likelihood( + fun=partial(_gamma_regression_fun, x=x, y=y), + jac=partial(_gamma_regression_jac, x=x, y=y), + good_start=np.r_[log_mean, np.zeros(n_slopes), 0.0], + bad_start=np.r_[log_mean - 3, -3 * beta[1:], 4.0], + true_params=None if dgp_lognormal else np.r_[beta, np.log(shape)], + ) + + +def _gamma_regression_fun( + params: NDArray[np.float64], *, x: NDArray[np.float64], y: NDArray[np.float64] +) -> NDArray[np.float64]: + log_shape = params[-1] + shape = np.exp(log_shape) + log_ratio = np.log(y) - x @ params[:-1] + loglike = ( + shape * (log_shape + log_ratio) + - shape * np.exp(log_ratio) + - special.gammaln(shape) + - np.log(y) + ) + return -loglike + + +def _gamma_regression_jac( + params: NDArray[np.float64], *, x: NDArray[np.float64], y: NDArray[np.float64] +) -> NDArray[np.float64]: + log_shape = params[-1] + shape = np.exp(log_shape) + log_ratio = np.log(y) - x @ params[:-1] + ratio = np.exp(log_ratio) + d_index = shape * (ratio - 1) + d_log_shape = shape * (log_shape + log_ratio + 1 - ratio - special.digamma(shape)) + return -np.column_stack([d_index[:, None] * x, d_log_shape]) + + +def stochastic_frontier( + *, + n_obs: int, + n_params: int, + seed: int, + dgp_wrong_skew: bool = False, +) -> SimulatedLikelihood: + """Simulate a normal-half normal stochastic production frontier. + + The params are the frontier coefficients (with intercept), the log standard + deviation of the noise and the standard deviation of the inefficiency term, which + is bounded below by zero. + + Args: + n_obs: Number of observations. + n_params: Number of params. + seed: Seed of the random number generator. + dgp_wrong_skew: If True, the inefficiency term enters with the wrong sign, so + the residuals are skewed to the right and the solution has no inefficiency, + i.e. it lies on the bound. + + """ + rng = np.random.default_rng(seed) + n_slopes = n_params - 3 + x = _add_intercept(_covariates(rng, n_obs, n_slopes)) + beta = np.r_[1.0, _slopes(n_slopes, 0.5)] + sd_noise, sd_inefficiency = 0.5, 1.0 + noise = sd_noise * sampling.standard_normal(rng, n_obs) + inefficiency = sd_inefficiency * np.abs(sampling.standard_normal(rng, n_obs)) + sign = 1.0 if dgp_wrong_skew else -1.0 + y = x @ beta + noise + sign * inefficiency + + lower = np.r_[np.full(n_params - 1, -np.inf), 0.0] + sd_y = y.std() + return _simulated_likelihood( + fun=partial(_stochastic_frontier_fun, x=x, y=y), + jac=partial(_stochastic_frontier_jac, x=x, y=y), + good_start=np.r_[y.mean(), np.zeros(n_slopes), np.log(sd_y), 0.5 * sd_y], + bad_start=np.r_[y.mean() + 5, -3 * beta[1:], np.log(sd_y) - 3, 5 * sd_y], + true_params=( + None if dgp_wrong_skew else np.r_[beta, np.log(sd_noise), sd_inefficiency] + ), + lower_bounds=lower, + ) + + +def _stochastic_frontier_parts( + params: NDArray[np.float64], x: NDArray[np.float64], y: NDArray[np.float64] +) -> tuple[NDArray[np.float64], ...]: + residual = y - x @ params[:-2] + sd_noise = np.exp(params[-2]) + sd_inefficiency = params[-1] + sd = np.sqrt(sd_noise**2 + sd_inefficiency**2) + skew_arg = -residual * sd_inefficiency / (sd_noise * sd) + return residual, sd_noise, sd_inefficiency, sd, skew_arg + + +def _stochastic_frontier_fun( + params: NDArray[np.float64], *, x: NDArray[np.float64], y: NDArray[np.float64] +) -> NDArray[np.float64]: + residual, _, _, sd, skew_arg = _stochastic_frontier_parts(params, x, y) + loglike = ( + np.log(2) + - np.log(sd) + + _log_normal_pdf(residual / sd) + + special.log_ndtr(skew_arg) + ) + return -loglike + + +def _stochastic_frontier_jac( + params: NDArray[np.float64], *, x: NDArray[np.float64], y: NDArray[np.float64] +) -> NDArray[np.float64]: + residual, sd_noise, sd_ineff, sd, skew_arg = _stochastic_frontier_parts( + params, x, y + ) + mills = _inverse_mills(skew_arg) + d_residual = -residual / sd**2 - mills * sd_ineff / (sd_noise * sd) + d_sd = -1 / sd + residual**2 / sd**3 - mills * skew_arg / sd + d_sd_ineff = d_sd * sd_ineff / sd - mills * residual / (sd_noise * sd) + d_sd_noise = d_sd * sd_noise / sd + mills * residual * sd_ineff / (sd_noise**2 * sd) + return -np.column_stack( + [-d_residual[:, None] * x, d_sd_noise * sd_noise, d_sd_ineff] + ) + + +# ====================================================================================== +# Ordered and multinomial choice +# ====================================================================================== + + +def ordered_probit( + *, + n_obs: int, + n_slopes: int, + n_categories: int, + seed: int, + dgp_errors: Literal["normal", "logistic", "gumbel"] = "normal", +) -> SimulatedLikelihood: + """Simulate an ordered probit model. + + The params are the slopes (without intercept) followed by the cutpoints, which are + parametrized as the first cutpoint and the logs of the increments. + + Args: + n_obs: Number of observations. + n_slopes: Number of slopes. + n_categories: Number of outcome categories. + seed: Seed of the random number generator. + dgp_errors: Distribution of the latent errors, standardized to mean zero and + unit variance. + + """ + rng = np.random.default_rng(seed) + x = _covariates(rng, n_obs, n_slopes) + beta = _slopes(n_slopes, 1.0) + if dgp_errors == "normal": + errors = sampling.standard_normal(rng, n_obs) + elif dgp_errors == "logistic": + errors = sampling.standard_logistic(rng, n_obs) * np.sqrt(3) / np.pi + else: + gumbel = sampling.standard_gumbel(rng, n_obs) + errors = (gumbel - np.euler_gamma) * np.sqrt(6) / np.pi + probabilities = np.linspace(0, 1, n_categories + 1)[1:-1] + cutpoints = special.ndtri(probabilities) * np.sqrt(2) + y = np.searchsorted(cutpoints, x @ beta + errors) + + shares = np.cumsum(np.bincount(y, minlength=n_categories))[:-1] / n_obs + good_cutpoints = special.ndtri(shares) + bad_cutpoints = 3.0 + 0.1 * np.arange(n_categories - 1) + return _simulated_likelihood( + fun=partial(_ordered_probit_fun, x=x, y=y), + jac=partial(_ordered_probit_jac, x=x, y=y), + good_start=np.r_[np.zeros(n_slopes), _cutpoints_to_params(good_cutpoints)], + bad_start=np.r_[-3 * beta, _cutpoints_to_params(bad_cutpoints)], + true_params=( + np.r_[beta, _cutpoints_to_params(cutpoints)] + if dgp_errors == "normal" + else None + ), + ) + + +def _cutpoints_to_params(cutpoints: NDArray[np.floating]) -> NDArray[np.float64]: + return np.r_[cutpoints[0], np.log(np.diff(cutpoints))] + + +def _ordered_probit_parts( + params: NDArray[np.float64], x: NDArray[np.float64], y: NDArray[np.int64] +) -> tuple[NDArray[np.float64], ...]: + n_slopes = x.shape[1] + cut_params = params[n_slopes:] + cutpoints = np.cumsum(np.r_[cut_params[0], np.exp(cut_params[1:])]) + padded = np.r_[-np.inf, cutpoints, np.inf] + index = x @ params[:n_slopes] + upper = padded[y + 1] - index + lower = padded[y] - index + return upper, lower, _log_normal_interval(lower, upper) + + +def _ordered_probit_fun( + params: NDArray[np.float64], *, x: NDArray[np.float64], y: NDArray[np.int64] +) -> NDArray[np.float64]: + return -_ordered_probit_parts(params, x, y)[2] + + +def _ordered_probit_jac( + params: NDArray[np.float64], *, x: NDArray[np.float64], y: NDArray[np.int64] +) -> NDArray[np.float64]: + n_obs, n_slopes = x.shape + n_cutpoints = len(params) - n_slopes + upper, lower, loglike = _ordered_probit_parts(params, x, y) + d_upper = np.exp(_log_normal_pdf(upper) - loglike) + d_lower = -np.exp(_log_normal_pdf(lower) - loglike) + + # derivative with respect to the cutpoints, shape (n_obs, n_cutpoints) + d_cutpoints = np.zeros((n_obs, n_cutpoints + 2)) + rows = np.arange(n_obs) + d_cutpoints[rows, y + 1] += d_upper + d_cutpoints[rows, y] += d_lower + d_cutpoints = d_cutpoints[:, 1:-1] + + # cutpoint j depends on cut param m <= j; with increments on the log scale + d_cut_params = np.cumsum(d_cutpoints[:, ::-1], axis=1)[:, ::-1] + d_cut_params[:, 1:] *= np.exp(params[n_slopes + 1 :]) + + d_slopes = -(d_upper + d_lower)[:, None] * x + return -np.column_stack([d_slopes, d_cut_params]) + + +def multinomial_logit( + *, + n_obs: int, + n_alternatives: int, + n_attributes: int, + n_characteristics: int, + seed: int, + dgp_nest_dissimilarity: float = 1.0, +) -> SimulatedLikelihood: + """Simulate a multinomial logit model with attributes and characteristics. + + Utilities are V_ij = w_ij @ beta + x_i @ gamma_j with gamma_0 = 0, where w are + alternative specific attributes and x are individual characteristics including an + intercept. The params are beta followed by the rows of gamma for the alternatives + 1, ..., n_alternatives - 1, so there are n_attributes + (n_alternatives - 1) * + (n_characteristics + 1) params. + + Args: + n_obs: Number of observations. + n_alternatives: Number of alternatives. + n_attributes: Number of alternative specific attributes. + n_characteristics: Number of individual characteristics (without intercept). + seed: Seed of the random number generator. + dgp_nest_dissimilarity: If below one, the choices are generated from a nested + logit model in which alternative 0 is alone and the other alternatives + form two nests with this dissimilarity parameter. This violates the + independence of irrelevant alternatives assumed by the model. + + """ + rng = np.random.default_rng(seed) + w = sampling.standard_normal(rng, (n_obs, n_alternatives, n_attributes)) + x = _add_intercept(_covariates(rng, n_obs, n_characteristics)) + beta = _slopes(n_attributes, 1.0) + alt = np.arange(1, n_alternatives)[:, None] + col = np.arange(n_characteristics + 1)[None, :] + gamma = 0.6 * np.cos(1.7 * alt + 2.3 * col + 0.4) / np.sqrt(n_characteristics + 1) + true_params = np.r_[beta, gamma.flatten()] + + utility = _multinomial_logit_utility(true_params, w, x) + if dgp_nest_dissimilarity == 1: + y = np.argmax(utility + sampling.standard_gumbel(rng, utility.shape), axis=1) + else: + log_probs = _nested_logit_log_probabilities(utility, dgp_nest_dissimilarity) + y = sampling.categorical(rng, np.exp(log_probs)) + + return _simulated_likelihood( + fun=partial(_multinomial_logit_fun, w=w, x=x, y=y), + jac=partial(_multinomial_logit_jac, w=w, x=x, y=y), + good_start=np.zeros_like(true_params), + bad_start=-3 * true_params, + true_params=true_params if dgp_nest_dissimilarity == 1 else None, + ) + + +def _nested_logit_log_probabilities( + utility: NDArray[np.float64], dissimilarity: float +) -> NDArray[np.float64]: + """Compute nested logit choice probabilities, with alternative 0 in its own nest.""" + n_alternatives = utility.shape[1] + split = 1 + (n_alternatives - 1) // 2 + nests = [np.arange(1), np.arange(1, split), np.arange(split, n_alternatives)] + dissimilarities = [1.0, dissimilarity, dissimilarity] + log_probs = np.empty_like(utility) + inclusive = [] + for nest, lam in zip(nests, dissimilarities, strict=True): + scaled = utility[:, nest] / lam + nest_inclusive = special.logsumexp(scaled, axis=1) + log_probs[:, nest] = scaled - nest_inclusive[:, None] + inclusive.append(lam * nest_inclusive) + inclusive_arr = np.column_stack(inclusive) + log_nest_probs = inclusive_arr - special.logsumexp(inclusive_arr, axis=1)[:, None] + for i, nest in enumerate(nests): + log_probs[:, nest] += log_nest_probs[:, [i]] + return log_probs + + +def _multinomial_logit_utility( + params: NDArray[np.float64], w: NDArray[np.float64], x: NDArray[np.float64] +) -> NDArray[np.float64]: + n_obs, n_alternatives, n_attributes = w.shape + gamma = params[n_attributes:].reshape(n_alternatives - 1, x.shape[1]) + utility = w @ params[:n_attributes] + utility[:, 1:] += x @ gamma.T + return utility + + +def _multinomial_logit_fun( + params: NDArray[np.float64], + *, + w: NDArray[np.float64], + x: NDArray[np.float64], + y: NDArray[np.int64], +) -> NDArray[np.float64]: + utility = _multinomial_logit_utility(params, w, x) + chosen = utility[np.arange(len(y)), y] + return _logsumexp(utility, axis=1) - chosen + + +def _multinomial_logit_jac( + params: NDArray[np.float64], + *, + w: NDArray[np.float64], + x: NDArray[np.float64], + y: NDArray[np.int64], +) -> NDArray[np.float64]: + n_obs, n_alternatives, _ = w.shape + utility = _multinomial_logit_utility(params, w, x) + probs = special.softmax(utility, axis=1) + rows = np.arange(n_obs) + d_beta = w[rows, y] - np.einsum("ij,ijk->ik", probs, w) + chosen = np.zeros_like(probs) + chosen[rows, y] = 1.0 + d_gamma = (chosen - probs)[:, 1:, None] * x[:, None, :] + return -np.column_stack([d_beta, d_gamma.reshape(n_obs, -1)]) + + +# ====================================================================================== +# Duration: Weibull proportional hazards with censoring +# ====================================================================================== + + +def weibull_duration( + *, + n_obs: int, + n_params: int, + seed: int, + dgp_frailty_variance: float = 0.0, +) -> SimulatedLikelihood: + """Simulate a Weibull proportional hazards model with random right censoring. + + The params are the coefficients of the log hazard scale (with intercept) followed + by the log of the Weibull shape. + + Args: + n_obs: Number of observations. + n_params: Number of params. + seed: Seed of the random number generator. + dgp_frailty_variance: Variance of a gamma distributed multiplicative frailty + with mean one that the model ignores. + + """ + rng = np.random.default_rng(seed) + n_slopes = n_params - 2 + x = _add_intercept(_covariates(rng, n_obs, n_slopes)) + beta = np.r_[-0.5, _slopes(n_slopes, 0.5)] + shape = 1.5 + hazard_scale = np.exp(x @ beta) + if dgp_frailty_variance > 0: + hazard_scale = hazard_scale * sampling.gamma( + rng, 1 / dgp_frailty_variance, dgp_frailty_variance, n_obs + ) + duration = (sampling.exponential(rng, n_obs) / hazard_scale) ** (1 / shape) + censoring = 2 * np.median(duration) * sampling.exponential(rng, n_obs) + t = np.minimum(duration, censoring) + event = (duration <= censoring).astype(float) + + return _simulated_likelihood( + fun=partial(_weibull_fun, x=x, log_t=np.log(t), event=event), + jac=partial(_weibull_jac, x=x, log_t=np.log(t), event=event), + good_start=np.r_[np.log(event.sum() / t.sum()), np.zeros(n_slopes), 0.0], + bad_start=np.r_[2.0, -3 * beta[1:], np.log(4.0)], + true_params=(np.r_[beta, np.log(shape)] if dgp_frailty_variance == 0 else None), + ) + + +def _weibull_fun( + params: NDArray[np.float64], + *, + x: NDArray[np.float64], + log_t: NDArray[np.float64], + event: NDArray[np.float64], +) -> NDArray[np.float64]: + index = x @ params[:-1] + log_shape = params[-1] + shape = np.exp(log_shape) + log_cumulative_hazard = index + shape * log_t + loglike = event * (index + log_shape + (shape - 1) * log_t) - np.exp( + log_cumulative_hazard + ) + return -loglike + + +def _weibull_jac( + params: NDArray[np.float64], + *, + x: NDArray[np.float64], + log_t: NDArray[np.float64], + event: NDArray[np.float64], +) -> NDArray[np.float64]: + index = x @ params[:-1] + shape = np.exp(params[-1]) + cumulative_hazard = np.exp(index + shape * log_t) + d_index = event - cumulative_hazard + d_log_shape = event * (1 + shape * log_t) - cumulative_hazard * shape * log_t + return -np.column_stack([d_index[:, None] * x, d_log_shape]) + + +# ====================================================================================== +# Multivariate normal with Cholesky parametrized covariance +# ====================================================================================== + + +def multivariate_normal( + *, + n_obs: int, + dim: int, + seed: int, + dgp_df: float | None = None, +) -> SimulatedLikelihood: + """Simulate a multivariate normal distribution with unknown mean and covariance. + + The params are the mean followed by the lower triangle of the Cholesky factor of + the covariance matrix in row major order, with the diagonal on the log scale. There + are dim + dim * (dim + 1) / 2 params. + + Args: + n_obs: Number of observations. + dim: Dimension of the outcomes. + seed: Seed of the random number generator. + dgp_df: If not None, the data come from a multivariate t distribution with + this many degrees of freedom and the same covariance matrix. + + """ + rng = np.random.default_rng(seed) + mean = np.linspace(-2, 2, dim) + sds = np.linspace(0.5, 3, dim) + lags = np.abs(np.subtract.outer(np.arange(dim), np.arange(dim))) + cov = (-0.4) ** lags * np.outer(sds, sds) + chol = np.linalg.cholesky(cov) + z = sampling.standard_normal(rng, (n_obs, dim)) + if dgp_df is not None: + chi2 = sampling.gamma(rng, dgp_df / 2, 2.0, (n_obs, 1)) + z = z * np.sqrt((dgp_df - 2) / chi2) + y = mean + z @ chol.T + + rows, cols = np.tril_indices(dim) + is_diag = rows == cols + chol_params = chol[rows, cols] + chol_params[is_diag] = np.log(chol_params[is_diag]) + + bad_chol = np.where(is_diag, np.log(0.1), 0.0) + return _simulated_likelihood( + fun=partial(_multivariate_normal_fun, y=y), + jac=partial(_multivariate_normal_jac, y=y), + good_start=np.zeros(dim + len(rows)), + bad_start=np.r_[np.full(dim, 10.0), bad_chol], + true_params=np.r_[mean, chol_params] if dgp_df is None else None, + ) + + +def _multivariate_normal_parts( + params: NDArray[np.float64], y: NDArray[np.float64] +) -> tuple[NDArray[np.float64], ...]: + dim = y.shape[1] + rows, cols = np.tril_indices(dim) + is_diag = rows == cols + chol_params = params[dim:] + chol = np.zeros((dim, dim)) + chol[rows, cols] = np.where(is_diag, np.exp(chol_params), chol_params) + standardized = linalg.solve_triangular(chol, (y - params[:dim]).T, lower=True).T + return chol, standardized, chol_params[is_diag] + + +def _multivariate_normal_fun( + params: NDArray[np.float64], *, y: NDArray[np.float64] +) -> NDArray[np.float64]: + dim = y.shape[1] + _, standardized, log_diag = _multivariate_normal_parts(params, y) + return dim * _LOG_SQRT_2PI + log_diag.sum() + 0.5 * (standardized**2).sum(axis=1) + + +def _multivariate_normal_jac( + params: NDArray[np.float64], *, y: NDArray[np.float64] +) -> NDArray[np.float64]: + dim = y.shape[1] + rows, cols = np.tril_indices(dim) + is_diag = rows == cols + chol, standardized, _ = _multivariate_normal_parts(params, y) + # rows of d_mean are inv(chol).T @ standardized_i + d_mean = linalg.solve_triangular(chol, standardized.T, lower=True, trans="T").T + d_chol = d_mean[:, rows] * standardized[:, cols] + d_chol[:, is_diag] = d_chol[:, is_diag] * np.diag(chol) - 1 + return -np.column_stack([d_mean, d_chol]) + + +# ====================================================================================== +# Time series: GARCH(1, 1) +# ====================================================================================== + + +def garch( + *, + n_obs: int, + seed: int, + t_likelihood: bool = False, + dgp_innovation_df: float | None = None, +) -> SimulatedLikelihood: + """Simulate a GARCH(1, 1) model of returns with mean zero. + + The conditional variance is s2_t = omega + alpha * r_{t-1}**2 + beta * s2_{t-1}, + started at the sample variance. The params are (omega, alpha, beta) on their + natural scale with bounds, followed by the degrees of freedom of the standardized t + distribution if t_likelihood is True. + + Args: + n_obs: Number of observations. + seed: Seed of the random number generator. + t_likelihood: If True, the innovations are modeled as standardized t, else as + standard normal. + dgp_innovation_df: If not None, the innovations are standardized t with this + many degrees of freedom, else standard normal. + + """ + rng = np.random.default_rng(seed) + omega, alpha, beta = 0.05, 0.08, 0.9 + n_burn_in = 500 + n_total = n_obs + n_burn_in + if dgp_innovation_df is None: + innovations = sampling.standard_normal(rng, n_total) + else: + innovations = sampling.standardized_t(rng, dgp_innovation_df, n_total) + returns = np.empty(n_total) + variance = omega / (1 - alpha - beta) + for t in range(n_total): + returns[t] = np.sqrt(variance) * innovations[t] + variance = omega + alpha * returns[t] ** 2 + beta * variance + squared = returns[n_burn_in:] ** 2 + initial = squared.mean() + + good_start = np.array([0.05 * initial, 0.05, 0.9]) + bad_start = np.array([0.001 * initial, 0.6, 0.01]) + lower = np.array([1e-6, 0.0, 0.0]) + upper = np.array([np.inf, 1.0, 1.0]) + true_params = np.array([omega, alpha, beta]) + if t_likelihood: + good_start = np.r_[good_start, 8.0] + bad_start = np.r_[bad_start, 2.2] + lower = np.r_[lower, 2.1] + upper = np.r_[upper, 500.0] + true_params = np.r_[true_params, dgp_innovation_df] + + is_correct = (dgp_innovation_df is not None) == t_likelihood + return _simulated_likelihood( + fun=partial(_garch_fun, squared=squared, initial=initial), + jac=partial(_garch_jac, squared=squared, initial=initial), + good_start=good_start, + bad_start=bad_start, + true_params=true_params if is_correct else None, + lower_bounds=lower, + upper_bounds=upper, + ) + + +def _garch_variance( + params: NDArray[np.float64], squared: NDArray[np.float64], initial: float +) -> NDArray[np.float64]: + omega, alpha, beta = params[:3] + shocks = omega + alpha * squared[:-1] + recursion = signal.lfilter([1.0], [1.0, -beta], shocks, zi=[beta * initial])[0] + return np.r_[initial, recursion] + + +def _garch_variance_jac( + params: NDArray[np.float64], + squared: NDArray[np.float64], + variance: NDArray[np.float64], +) -> NDArray[np.float64]: + beta = params[2] + inputs = np.column_stack([np.ones(len(squared) - 1), squared[:-1], variance[:-1]]) + recursion = signal.lfilter([1.0], [1.0, -beta], inputs, axis=0) + return np.vstack([np.zeros((1, 3)), recursion]) + + +def _garch_loglike_and_derivative( + params: NDArray[np.float64], + squared: NDArray[np.float64], + variance: NDArray[np.float64], +) -> tuple[NDArray[np.float64], NDArray[np.float64], NDArray[np.float64] | None]: + """Return log-likelihood contributions and their derivatives wrt variance and df.""" + if len(params) == 3: + loglike = -0.5 * (np.log(2 * np.pi) + np.log(variance) + squared / variance) + d_variance = 0.5 * (squared / variance - 1) / variance + return loglike, d_variance, None + df = params[3] + ratio = squared / (variance * (df - 2)) + loglike = ( + special.gammaln((df + 1) / 2) + - special.gammaln(df / 2) + - 0.5 * np.log(np.pi * (df - 2)) + - 0.5 * np.log(variance) + - 0.5 * (df + 1) * np.log1p(ratio) + ) + d_variance = -0.5 / variance + 0.5 * (df + 1) * ratio / (variance * (1 + ratio)) + d_df = ( + 0.5 * special.digamma((df + 1) / 2) + - 0.5 * special.digamma(df / 2) + - 0.5 / (df - 2) + - 0.5 * np.log1p(ratio) + + 0.5 * (df + 1) * ratio / ((df - 2) * (1 + ratio)) + ) + return loglike, d_variance, d_df + + +def _garch_fun( + params: NDArray[np.float64], *, squared: NDArray[np.float64], initial: float +) -> NDArray[np.float64]: + variance = _garch_variance(params, squared, initial) + return -_garch_loglike_and_derivative(params, squared, variance)[0] + + +def _garch_jac( + params: NDArray[np.float64], *, squared: NDArray[np.float64], initial: float +) -> NDArray[np.float64]: + variance = _garch_variance(params, squared, initial) + _, d_variance, d_df = _garch_loglike_and_derivative(params, squared, variance) + out = d_variance[:, None] * _garch_variance_jac(params, squared, variance) + if d_df is not None: + out = np.column_stack([out, d_df]) + return -out + + +# ====================================================================================== +# Panel models with random effects: random effects probit, mixed logit +# ====================================================================================== + + +def random_effects_probit( + *, + n_individuals: int, + n_periods: int, + n_params: int, + seed: int, + n_nodes: int = 12, + dgp_bimodal_effects: bool = False, +) -> SimulatedLikelihood: + """Simulate a random effects panel probit model. + + The likelihood integrates over the normal random effect with Gauss-Hermite + quadrature. The params are the coefficients (with intercept) followed by the log + standard deviation of the random effect. + + Args: + n_individuals: Number of individuals. + n_periods: Number of periods per individual. + n_params: Number of params. + seed: Seed of the random number generator. + n_nodes: Number of quadrature nodes. + dgp_bimodal_effects: If True, the random effects follow a bimodal mixture of + normals with unit variance instead of a standard normal distribution. + + """ + rng = np.random.default_rng(seed) + n_slopes = n_params - 2 + x = sampling.standard_normal(rng, (n_individuals, n_periods, n_slopes)) + x = np.concatenate([np.ones((n_individuals, n_periods, 1)), x], axis=2) + beta = np.r_[-0.3, _slopes(n_slopes, 1.0)] + if dgp_bimodal_effects: + sign = np.where(sampling.uniform(rng, n_individuals) < 0.5, -1.0, 1.0) + effects = 0.9 * sign + np.sqrt(1 - 0.81) * sampling.standard_normal( + rng, n_individuals + ) + else: + effects = sampling.standard_normal(rng, n_individuals) + errors = sampling.standard_normal(rng, (n_individuals, n_periods)) + y = (x @ beta + effects[:, None] + errors > 0).astype(float) + + nodes, weights = np.polynomial.hermite_e.hermegauss(n_nodes) + log_weights = np.log(weights / weights.sum()) + kwargs = {"x": x, "sign": 2 * y - 1, "nodes": nodes, "log_weights": log_weights} + return _simulated_likelihood( + fun=partial(_random_effects_probit_fun, **kwargs), + jac=partial(_random_effects_probit_jac, **kwargs), + good_start=np.r_[special.ndtri(y.mean()), np.zeros(n_slopes), np.log(0.3)], + bad_start=np.r_[1.0, -3 * beta[1:], np.log(5.0)], + true_params=None if dgp_bimodal_effects else np.r_[beta, 0.0], + ) + + +def _random_effects_probit_parts( + params: NDArray[np.float64], + x: NDArray[np.float64], + sign: NDArray[np.float64], + nodes: NDArray[np.float64], + log_weights: NDArray[np.float64], +) -> tuple[NDArray[np.float64], ...]: + sd = np.exp(params[-1]) + index = x @ params[:-1] + # shape (n_individuals, n_periods, n_nodes) + arg = sign[:, :, None] * (index[:, :, None] + sd * nodes) + log_joint = special.log_ndtr(arg).sum(axis=1) + log_weights + loglike = _logsumexp(log_joint, axis=1) + return arg, log_joint, loglike, sd + + +def _random_effects_probit_fun( + params: NDArray[np.float64], + *, + x: NDArray[np.float64], + sign: NDArray[np.float64], + nodes: NDArray[np.float64], + log_weights: NDArray[np.float64], +) -> NDArray[np.float64]: + return -_random_effects_probit_parts(params, x, sign, nodes, log_weights)[2] + + +def _random_effects_probit_jac( + params: NDArray[np.float64], + *, + x: NDArray[np.float64], + sign: NDArray[np.float64], + nodes: NDArray[np.float64], + log_weights: NDArray[np.float64], +) -> NDArray[np.float64]: + arg, log_joint, loglike, sd = _random_effects_probit_parts( + params, x, sign, nodes, log_weights + ) + posterior = np.exp(log_joint - loglike[:, None]) + d_arg = sign[:, :, None] * _inverse_mills(arg) + d_beta = np.einsum("iq,itq,itk->ik", posterior, d_arg, x) + d_log_sd = np.einsum("iq,itq,q->i", posterior, d_arg, sd * nodes) + return -np.column_stack([d_beta, d_log_sd]) + + +def mixed_logit( + *, + n_individuals: int, + n_situations: int, + n_alternatives: int, + n_fixed: int, + n_random: int, + seed: int, + correlated: bool = False, + n_draws: int = 50, + zero_sd: bool = False, + dgp_lognormal: bool = False, +) -> SimulatedLikelihood: + """Simulate a panel mixed logit model, estimated by maximum simulated likelihood. + + Each individual makes n_situations choices among n_alternatives alternatives with + random attributes. The first n_fixed attributes have fixed coefficients, the others + normally distributed individual specific coefficients. The params are the fixed + coefficients, the means of the random coefficients and the Cholesky factor of their + covariance: its diagonal if correlated is False, else its lower triangle in row + major order. The diagonal of the Cholesky factor is bounded below by zero. + + With few draws relative to the number of individuals, the simulated likelihood is + noticeably biased, so the estimates can differ from the true params by more than + their standard errors suggest, and the information matrix equality fails even + though the model is correctly specified. + + Args: + n_individuals: Number of individuals. + n_situations: Number of choice situations per individual. + n_alternatives: Number of alternatives. + n_fixed: Number of attributes with fixed coefficients. + n_random: Number of attributes with random coefficients. + seed: Seed of the random number generator. + correlated: Whether the random coefficients are correlated. + n_draws: Number of simulation draws per individual. + zero_sd: If True, the last random coefficient has a standard deviation of + zero, so its bound can be active at the solution. + dgp_lognormal: If True, the random coefficients follow a lognormal distribution + with the same mean and covariance as the normal distribution. + + """ + rng = np.random.default_rng(seed) + n_attributes = n_fixed + n_random + shape = (n_individuals, n_situations, n_alternatives, n_attributes) + w = sampling.standard_normal(rng, shape) + fixed = _slopes(n_fixed, 1.0) + means = np.linspace(1.0, 2.0, n_random) + sds = np.linspace(0.8, 0.4, n_random) + if zero_sd: + sds[-1] = 0.0 + lags = np.abs(np.subtract.outer(np.arange(n_random), np.arange(n_random))) + corr = 0.3**lags if correlated else np.eye(n_random) + cov = corr * np.outer(sds, sds) + chol = np.zeros((n_random, n_random)) + n_nonzero = n_random - 1 if zero_sd else n_random + chol[:n_nonzero, :n_nonzero] = np.linalg.cholesky(cov[:n_nonzero, :n_nonzero]) + + standard = sampling.standard_normal(rng, (n_individuals, n_random)) + if dgp_lognormal: + # lognormal with the given means and sds, using the correlation of the normals + log_sd = np.sqrt(np.log1p((sds / means) ** 2)) + log_mean = np.log(means) - 0.5 * log_sd**2 + correlated_standard = standard @ np.linalg.cholesky(corr).T + coefficients = np.exp(log_mean + log_sd * correlated_standard) + else: + coefficients = means + standard @ chol.T + utility = w[..., :n_fixed] @ fixed + np.einsum( + "ntjk,nk->ntj", w[..., n_fixed:], coefficients + ) + y = np.argmax(utility + sampling.standard_gumbel(rng, utility.shape), axis=2) + draws = sampling.standard_normal(rng, (n_individuals, n_draws, n_random)) + + if correlated: + rows, cols = np.tril_indices(n_random) + else: + rows = cols = np.arange(n_random) + is_diag = rows == cols + chol_params = chol[rows, cols] + lower = np.r_[np.full(n_attributes, -np.inf), np.where(is_diag, 0.0, -np.inf)] + + kwargs = { + "w": w, + "y": y, + "draws": draws, + "n_fixed": n_fixed, + "correlated": correlated, + } + return _simulated_likelihood( + fun=partial(_mixed_logit_fun, **kwargs), + jac=partial(_mixed_logit_jac, **kwargs), + good_start=np.r_[np.zeros(n_attributes), np.where(is_diag, 0.5, 0.0)], + bad_start=np.r_[-3 * fixed, -3 * means, np.where(is_diag, 5.0, 0.0)], + true_params=None if dgp_lognormal else np.r_[fixed, means, chol_params], + lower_bounds=lower, + ) + + +def _mixed_logit_parts( + params: NDArray[np.float64], + w: NDArray[np.float64], + y: NDArray[np.int64], + draws: NDArray[np.float64], + n_fixed: int, + correlated: bool, +) -> tuple[NDArray[np.float64], ...]: + n_individuals, n_situations, n_alternatives, n_attributes = w.shape + n_random = n_attributes - n_fixed + chol = np.zeros((n_random, n_random)) + if correlated: + chol[np.tril_indices(n_random)] = params[n_attributes:] + else: + chol[np.diag_indices(n_random)] = params[n_attributes:] + # coefficients per individual and draw, shape (n_individuals, n_draws, n_attr) + random = params[n_fixed:n_attributes] + draws @ chol.T + fixed = np.broadcast_to(params[:n_fixed], (*random.shape[:2], n_fixed)) + coefficients = np.concatenate([fixed, random], axis=2) + # utility, shape (n_individuals, n_situations, n_alternatives, n_draws) + flat_w = w.reshape(n_individuals, n_situations * n_alternatives, n_attributes) + utility = (flat_w @ coefficients.transpose(0, 2, 1)).reshape( + n_individuals, n_situations, n_alternatives, -1 + ) + log_denominator = _logsumexp(utility, axis=2) + chosen = np.take_along_axis(utility, y[:, :, None, None], axis=2)[:, :, 0] + log_kernel = (chosen - log_denominator).sum(axis=1) + loglike = _logsumexp(log_kernel, axis=1) - np.log(draws.shape[1]) + return utility, log_denominator, log_kernel, loglike + + +def _mixed_logit_fun( + params: NDArray[np.float64], + *, + w: NDArray[np.float64], + y: NDArray[np.int64], + draws: NDArray[np.float64], + n_fixed: int, + correlated: bool, +) -> NDArray[np.float64]: + return -_mixed_logit_parts(params, w, y, draws, n_fixed, correlated)[3] + + +def _mixed_logit_jac( + params: NDArray[np.float64], + *, + w: NDArray[np.float64], + y: NDArray[np.int64], + draws: NDArray[np.float64], + n_fixed: int, + correlated: bool, +) -> NDArray[np.float64]: + n_individuals, n_situations, n_alternatives, n_attributes = w.shape + n_draws, n_random = draws.shape[1:] + utility, log_denominator, log_kernel, loglike = _mixed_logit_parts( + params, w, y, draws, n_fixed, correlated + ) + probs = np.exp(utility - log_denominator[:, :, None]) + posterior = np.exp(log_kernel - loglike[:, None] - np.log(n_draws)) + chosen_attributes = np.take_along_axis(w, y[:, :, None, None], axis=2)[:, :, 0] + # derivative of the log kernel wrt the coefficients, shape (n_ind, n_draws, n_attr) + flat_probs = probs.reshape(n_individuals, n_situations * n_alternatives, n_draws) + flat_w = w.reshape(n_individuals, n_situations * n_alternatives, n_attributes) + expected_attributes = flat_probs.transpose(0, 2, 1) @ flat_w + d_coefficients = chosen_attributes.sum(axis=1)[:, None, :] - expected_attributes + weighted = posterior[:, :, None] * d_coefficients + d_means = weighted.sum(axis=1) + if correlated: + rows, cols = np.tril_indices(n_random) + else: + rows = cols = np.arange(n_random) + d_chol = (weighted[:, :, n_fixed:].transpose(0, 2, 1) @ draws)[:, rows, cols] + return -np.column_stack([d_means, d_chol]) + + +# ====================================================================================== +# Mixture and selection models +# ====================================================================================== + + +def normal_mixture( + *, + n_obs: int, + seed: int, + dgp_three_components: bool = False, +) -> SimulatedLikelihood: + """Simulate a two component univariate normal mixture. + + The params are (mean_1, mean_2, log_sd_1, log_sd_2, logit_weight_1). The solution is + only unique up to swapping the component labels. + + Args: + n_obs: Number of observations. + seed: Seed of the random number generator. + dgp_three_components: If True, the data come from a mixture of three normals. + + """ + rng = np.random.default_rng(seed) + if dgp_three_components: + weights = np.array([0.3, 0.4, 0.3]) + means = np.array([-2.0, 0.0, 2.5]) + sds = np.array([0.5, 1.0, 0.7]) + else: + weights = np.array([0.35, 0.65]) + means = np.array([-1.0, 1.5]) + sds = np.array([0.7, 1.0]) + component = sampling.categorical(rng, np.tile(weights, (n_obs, 1))) + y = means[component] + sds[component] * sampling.standard_normal(rng, n_obs) + + true_params = np.r_[means, np.log(sds), special.logit(weights[0])] + center, spread = y.mean(), y.std() + return _simulated_likelihood( + fun=partial(_normal_mixture_fun, y=y), + jac=partial(_normal_mixture_jac, y=y), + good_start=np.r_[ + center - spread, center + spread, np.log(spread), np.log(spread), 0.0 + ], + bad_start=np.r_[ + center + 3 * spread, + center + 4 * spread, + np.log(spread) + 2, + np.log(spread) + 1, + 0.0, + ], + true_params=None if dgp_three_components else true_params, + unique_solution=False, + ) + + +def _normal_mixture_parts( + params: NDArray[np.float64], y: NDArray[np.float64] +) -> tuple[NDArray[np.float64], ...]: + means, log_sds, logit_weight = params[:2], params[2:4], params[4] + log_weights = np.array( + [special.log_expit(logit_weight), special.log_expit(-logit_weight)] + ) + standardized = (y[:, None] - means) * np.exp(-log_sds) + log_joint = log_weights + _log_normal_pdf(standardized) - log_sds + loglike = special.logsumexp(log_joint, axis=1) + return standardized, log_joint, loglike + + +def _normal_mixture_fun( + params: NDArray[np.float64], *, y: NDArray[np.float64] +) -> NDArray[np.float64]: + return -_normal_mixture_parts(params, y)[2] + + +def _normal_mixture_jac( + params: NDArray[np.float64], *, y: NDArray[np.float64] +) -> NDArray[np.float64]: + standardized, log_joint, loglike = _normal_mixture_parts(params, y) + posterior = np.exp(log_joint - loglike[:, None]) + d_means = posterior * standardized * np.exp(-params[2:4]) + d_log_sds = posterior * (standardized**2 - 1) + d_logit_weight = posterior[:, 0] - special.expit(params[4]) + return -np.column_stack([d_means, d_log_sds, d_logit_weight]) + + +def heckman_selection( + *, + n_obs: int, + n_selection_params: int, + n_outcome_params: int, + seed: int, + dgp_error_df: float | None = None, +) -> SimulatedLikelihood: + """Simulate a Heckman sample selection model, estimated by full maximum likelihood. + + The outcome y = x @ beta + e is observed if z @ gamma + u > 0, where (u, e) are + bivariate normal with unit variance of u, standard deviation sigma of e and + correlation rho. z contains the covariates of x plus excluded covariates. The params + are gamma, beta, log(sigma) and arctanh(rho). + + Args: + n_obs: Number of observations. + n_selection_params: Number of params of the selection equation. + n_outcome_params: Number of params of the outcome equation (at most + n_selection_params). + seed: Seed of the random number generator. + dgp_error_df: If not None, (u, e) follow a bivariate t distribution with this + many degrees of freedom and the same covariance matrix. + + """ + rng = np.random.default_rng(seed) + z = _add_intercept(_covariates(rng, n_obs, n_selection_params - 1)) + x = z[:, :n_outcome_params] + gamma = np.r_[0.3, _slopes(n_selection_params - 1, 1.0)[::-1]] + beta = np.r_[1.0, _slopes(n_outcome_params - 1, 1.0)] + sd, rho = 1.2, 0.5 + standard = sampling.standard_normal(rng, (n_obs, 2)) + if dgp_error_df is not None: + chi2 = sampling.gamma(rng, dgp_error_df / 2, 2.0, (n_obs, 1)) + standard = standard * np.sqrt((dgp_error_df - 2) / chi2) + u = standard[:, 0] + e = sd * (rho * standard[:, 0] + np.sqrt(1 - rho**2) * standard[:, 1]) + selected = (z @ gamma + u > 0).astype(float) + y = np.where(selected == 1, x @ beta + e, 0.0) + + observed = y[selected == 1] + log_sd_y = np.log(observed.std()) + return _simulated_likelihood( + fun=partial(_heckman_fun, z=z, x=x, y=y, selected=selected), + jac=partial(_heckman_jac, z=z, x=x, y=y, selected=selected), + good_start=np.r_[ + special.ndtri(selected.mean()), + np.zeros(n_selection_params - 1), + observed.mean(), + np.zeros(n_outcome_params - 1), + log_sd_y, + 0.0, + ], + bad_start=np.r_[-3 * gamma, -3 * beta, log_sd_y - 3, np.arctanh(-0.9)], + true_params=( + np.r_[gamma, beta, np.log(sd), np.arctanh(rho)] + if dgp_error_df is None + else None + ), + ) + + +def _heckman_parts( + params: NDArray[np.float64], + z: NDArray[np.float64], + x: NDArray[np.float64], + y: NDArray[np.float64], + selected: NDArray[np.float64], +) -> tuple[NDArray[np.float64], ...]: + """Return the selection index, standardized residual and the normal cdf argument. + + The argument of the normal cdf is -selection_index for unselected observations. + + """ + n_selection, n_outcome = z.shape[1], x.shape[1] + selection_index = z @ params[:n_selection] + outcome_index = x @ params[n_selection : n_selection + n_outcome] + rho = np.tanh(params[-1]) + standardized = (y - outcome_index) * np.exp(-params[-2]) + arg = np.where( + selected == 1, + (selection_index + rho * standardized) / np.sqrt(1 - rho**2), + -selection_index, + ) + return selection_index, standardized, arg + + +def _heckman_fun( + params: NDArray[np.float64], + *, + z: NDArray[np.float64], + x: NDArray[np.float64], + y: NDArray[np.float64], + selected: NDArray[np.float64], +) -> NDArray[np.float64]: + _, standardized, arg = _heckman_parts(params, z, x, y, selected) + loglike = special.log_ndtr(arg) + selected * ( + _log_normal_pdf(standardized) - params[-2] + ) + return -loglike + + +def _heckman_jac( + params: NDArray[np.float64], + *, + z: NDArray[np.float64], + x: NDArray[np.float64], + y: NDArray[np.float64], + selected: NDArray[np.float64], +) -> NDArray[np.float64]: + selection_index, standardized, arg = _heckman_parts(params, z, x, y, selected) + sd = np.exp(params[-2]) + rho = np.tanh(params[-1]) + root = np.sqrt(1 - rho**2) + mills = _inverse_mills(arg) + is_selected = selected == 1 + d_selection = np.where(is_selected, mills / root, -mills) + d_outcome = np.where( + is_selected, -mills * rho / (sd * root) + standardized / sd, 0.0 + ) + d_log_sd = np.where( + is_selected, -mills * rho * standardized / root + standardized**2 - 1, 0.0 + ) + d_atanh_rho = np.where( + is_selected, mills * (standardized + rho * selection_index) / root, 0.0 + ) + return -np.column_stack( + [ + d_selection[:, None] * z, + d_outcome[:, None] * x, + d_log_sd, + d_atanh_rho, + ] + ) diff --git a/src/optimagic/benchmarking/likelihood/problems.py b/src/optimagic/benchmarking/likelihood/problems.py new file mode 100644 index 000000000..a1c20cd2a --- /dev/null +++ b/src/optimagic/benchmarking/likelihood/problems.py @@ -0,0 +1,1332 @@ +"""Define the likelihood benchmark sets. + +There are four sets of maximum likelihood problems, all framed as minimization of the +negative log-likelihood (the sum of the negative log-likelihood contributions): + +- ``likelihood_small``: correctly specified models with 3 to 25 params. +- ``likelihood_large``: correctly specified models with 25 to 150 params. +- ``likelihood_misspecified_small``: misspecified models with 3 to 25 params. +- ``likelihood_misspecified_large``: misspecified models with 25 to 150 params. + +Each set is built from instances, i.e. an econometric model fit to a simulated dataset. +Every instance yields two problems, one with good start values (what a practitioner +would choose without knowing the solution) and one with bad start values (far from the +solution). The same econometric model appears with different numbers of params. + +Misspecified instances carry a qualitative severity: ``"tiny"``, ``"mild"``, +``"moderate"`` or ``"severe"``. A quantitative measure of misspecification for all +instances is the range of the eigenvalues of inv(H) @ OPG at the solution, where H is +the Hessian and OPG the outer product of the scores. It is one in the population for +correctly specified models. + +The ``info`` of each problem also says whether the reference computation found local +optima that are worse than the solution (``"other_local_optima"``), which is the case +for some mixed logit models. Seeds and start values were chosen such that the reference +computation (L-BFGS-B with tight tolerances, followed by Newton steps) reaches the +solution from both the good and the bad start. + +Data are simulated with fixed seeds, so the problems are deterministic. The reference +solutions are stored in ``solutions.py``, created by +``.tools/create_likelihood_solutions.py``. + +""" + +from dataclasses import dataclass +from functools import partial +from typing import Any, Callable, Literal + +import numpy as np + +from optimagic import mark +from optimagic.benchmarking.likelihood import models +from optimagic.benchmarking.likelihood.models import SimulatedLikelihood +from optimagic.benchmarking.likelihood.solutions import LIKELIHOOD_SOLUTIONS + +Severity = Literal["tiny", "mild", "moderate", "severe"] + + +@dataclass(frozen=True) +class LikelihoodInstance: + name: str + """Unique name of the instance, ending with the number of params.""" + + build: Callable[[], SimulatedLikelihood] + """Simulate the data and return the likelihood problem.""" + + model: str + """Short description of the estimated model.""" + + misspecification: str | None = None + """Description of the misspecification; None if correctly specified.""" + + severity: Severity | None = None + """Qualitative severity of the misspecification; None if correctly specified.""" + + +def _instance( + name: str, + model: str, + builder: Callable[..., SimulatedLikelihood], + misspecification: str | None = None, + severity: Severity | None = None, + /, + **kwargs: Any, +) -> LikelihoodInstance: + """Create an instance; kwargs are passed to builder.""" + return LikelihoodInstance( + name=name, + build=partial(builder, **kwargs), + model=model, + misspecification=misspecification, + severity=severity, + ) + + +_LOGIT = "binary logit" +_PROBIT = "binary probit" +_POISSON = "Poisson regression" +_NEGBIN = "negative binomial (NB2) regression" +_HETERO = "linear regression with multiplicative heteroskedasticity" +_REGRESSION = "normal linear regression" +_TOBIT = "Tobit model" +_ORDERED = "ordered probit" +_MNL = "multinomial logit with attributes and characteristics" +_WEIBULL = "Weibull proportional hazards with censoring" +_GAMMA = "gamma regression with log link" +_MVN = "multivariate normal with Cholesky parametrized covariance" +_GARCH = "GARCH(1, 1) with normal innovations" +_GARCH_T = "GARCH(1, 1) with standardized t innovations" +_RE_PROBIT = "random effects panel probit (Gauss-Hermite quadrature)" +_MIXED_LOGIT = "panel mixed logit (maximum simulated likelihood)" +_MIXTURE = "two component normal mixture" +_HECKMAN = "Heckman selection model (full maximum likelihood)" +_ZIP = "zero inflated Poisson regression" +_FRONTIER = "normal-half normal stochastic frontier" +_FE_POISSON = "Poisson regression with group fixed effects" + +LIKELIHOOD_SMALL: tuple[LikelihoodInstance, ...] = ( + _instance( + "logit_5", _LOGIT, models.binary_choice, n_obs=20_000, n_params=5, seed=1 + ), + _instance( + "logit_badly_scaled_8", + _LOGIT, + models.binary_choice, + n_obs=3000, + n_params=8, + badly_scaled=True, + seed=2, + ), + _instance( + "logit_few_obs_25", + _LOGIT, + models.binary_choice, + n_obs=500, + n_params=25, + correlation=0.5, + seed=3, + ), + _instance( + "probit_badly_scaled_6", + _PROBIT, + models.binary_choice, + n_obs=3000, + n_params=6, + model="probit", + badly_scaled=True, + seed=4, + ), + _instance( + "probit_16", + _PROBIT, + models.binary_choice, + n_obs=2000, + n_params=16, + model="probit", + correlation=0.5, + strength=1.5, + seed=5, + ), + _instance( + "poisson_5", _POISSON, models.poisson_regression, n_obs=2000, n_params=5, seed=6 + ), + _instance( + "poisson_15", + _POISSON, + models.poisson_regression, + n_obs=20_000, + n_params=15, + correlation=0.3, + seed=7, + ), + _instance( + "negative_binomial_5", + _NEGBIN, + models.negative_binomial, + n_obs=3000, + n_params=5, + seed=8, + ), + _instance( + "negative_binomial_14", + _NEGBIN, + models.negative_binomial, + n_obs=3000, + n_params=14, + seed=9, + ), + _instance( + "heteroskedastic_regression_7", + _HETERO, + models.linear_regression, + n_obs=2000, + n_mean_params=5, + n_variance_params=2, + seed=10, + ), + _instance( + "heteroskedastic_regression_20", + _HETERO, + models.linear_regression, + n_obs=3000, + n_mean_params=12, + n_variance_params=8, + seed=11, + ), + _instance("tobit_6", _TOBIT, models.tobit, n_obs=2000, n_params=6, seed=12), + _instance("tobit_16", _TOBIT, models.tobit, n_obs=3000, n_params=16, seed=13), + _instance( + "ordered_probit_8", + _ORDERED, + models.ordered_probit, + n_obs=2000, + n_slopes=4, + n_categories=5, + seed=14, + ), + _instance( + "ordered_probit_18", + _ORDERED, + models.ordered_probit, + n_obs=3000, + n_slopes=10, + n_categories=9, + seed=15, + ), + _instance( + "multinomial_logit_11", + _MNL, + models.multinomial_logit, + n_obs=2000, + n_alternatives=4, + n_attributes=2, + n_characteristics=2, + seed=16, + ), + _instance( + "multinomial_logit_23", + _MNL, + models.multinomial_logit, + n_obs=3000, + n_alternatives=5, + n_attributes=3, + n_characteristics=4, + seed=17, + ), + _instance( + "weibull_5", + _WEIBULL, + models.weibull_duration, + n_obs=10_000, + n_params=5, + seed=18, + ), + _instance( + "weibull_12", + _WEIBULL, + models.weibull_duration, + n_obs=3000, + n_params=12, + seed=19, + ), + _instance( + "gamma_regression_6", + _GAMMA, + models.gamma_regression, + n_obs=2000, + n_params=6, + seed=20, + ), + _instance( + "multivariate_normal_9", + _MVN, + models.multivariate_normal, + n_obs=1000, + dim=3, + seed=21, + ), + _instance( + "multivariate_normal_20", + _MVN, + models.multivariate_normal, + n_obs=2000, + dim=5, + seed=22, + ), + _instance("garch_3", _GARCH, models.garch, n_obs=3000, seed=23), + _instance( + "garch_t_4", + _GARCH_T, + models.garch, + n_obs=3000, + t_likelihood=True, + dgp_innovation_df=6.0, + seed=24, + ), + _instance( + "random_effects_probit_6", + _RE_PROBIT, + models.random_effects_probit, + n_individuals=500, + n_periods=5, + n_params=6, + seed=25, + ), + _instance( + "mixed_logit_8", + _MIXED_LOGIT, + models.mixed_logit, + n_individuals=300, + n_situations=8, + n_alternatives=3, + n_fixed=2, + n_random=3, + seed=26, + ), + _instance( + "mixed_logit_zero_sd_8", + _MIXED_LOGIT, + models.mixed_logit, + n_individuals=300, + n_situations=8, + n_alternatives=3, + n_fixed=2, + n_random=3, + zero_sd=True, + seed=27, + ), + _instance( + "mixed_logit_correlated_18", + _MIXED_LOGIT, + models.mixed_logit, + n_individuals=500, + n_situations=8, + n_alternatives=4, + n_fixed=4, + n_random=4, + correlated=True, + seed=121, + ), + _instance("normal_mixture_5", _MIXTURE, models.normal_mixture, n_obs=1000, seed=28), + _instance( + "heckman_10", + _HECKMAN, + models.heckman_selection, + n_obs=2000, + n_selection_params=5, + n_outcome_params=3, + seed=29, + ), + _instance( + "zero_inflated_poisson_8", + _ZIP, + models.zero_inflated_poisson, + n_obs=2000, + n_inflation_params=3, + n_count_params=5, + seed=30, + ), + _instance( + "stochastic_frontier_6", + _FRONTIER, + models.stochastic_frontier, + n_obs=2000, + n_params=6, + seed=31, + ), + _instance( + "fixed_effects_poisson_18", + _FE_POISSON, + models.fixed_effects_poisson, + n_groups=15, + n_periods=10, + n_slopes=3, + seed=32, + ), +) + +LIKELIHOOD_LARGE: tuple[LikelihoodInstance, ...] = ( + _instance( + "logit_50", + _LOGIT, + models.binary_choice, + n_obs=50_000, + n_params=50, + correlation=0.5, + seed=101, + ), + _instance( + "logit_badly_scaled_100", + _LOGIT, + models.binary_choice, + n_obs=10_000, + n_params=100, + badly_scaled=True, + seed=102, + ), + _instance( + "logit_few_obs_150", + _LOGIT, + models.binary_choice, + n_obs=3000, + n_params=150, + correlation=0.3, + seed=103, + ), + _instance( + "probit_80", + _PROBIT, + models.binary_choice, + n_obs=10_000, + n_params=80, + model="probit", + strength=1.5, + seed=104, + ), + _instance( + "poisson_60", + _POISSON, + models.poisson_regression, + n_obs=30_000, + n_params=60, + correlation=0.3, + seed=105, + ), + _instance( + "negative_binomial_41", + _NEGBIN, + models.negative_binomial, + n_obs=10_000, + n_params=41, + seed=106, + ), + _instance( + "heteroskedastic_regression_60", + _HETERO, + models.linear_regression, + n_obs=10_000, + n_mean_params=30, + n_variance_params=30, + seed=107, + ), + _instance( + "heteroskedastic_regression_120", + _HETERO, + models.linear_regression, + n_obs=8000, + n_mean_params=60, + n_variance_params=60, + seed=108, + ), + _instance("tobit_51", _TOBIT, models.tobit, n_obs=30_000, n_params=51, seed=109), + _instance( + "ordered_probit_40", + _ORDERED, + models.ordered_probit, + n_obs=10_000, + n_slopes=30, + n_categories=11, + seed=110, + ), + _instance( + "multinomial_logit_46", + _MNL, + models.multinomial_logit, + n_obs=5000, + n_alternatives=8, + n_attributes=4, + n_characteristics=5, + seed=111, + ), + _instance( + "multinomial_logit_123", + _MNL, + models.multinomial_logit, + n_obs=8000, + n_alternatives=10, + n_attributes=6, + n_characteristics=12, + seed=112, + ), + _instance( + "weibull_31", + _WEIBULL, + models.weibull_duration, + n_obs=10_000, + n_params=31, + seed=113, + ), + _instance( + "gamma_regression_41", + _GAMMA, + models.gamma_regression, + n_obs=10_000, + n_params=41, + seed=114, + ), + _instance( + "multivariate_normal_44", + _MVN, + models.multivariate_normal, + n_obs=3000, + dim=8, + seed=115, + ), + _instance( + "multivariate_normal_90", + _MVN, + models.multivariate_normal, + n_obs=5000, + dim=12, + seed=116, + ), + _instance( + "multivariate_normal_135", + _MVN, + models.multivariate_normal, + n_obs=5000, + dim=15, + seed=117, + ), + _instance( + "fixed_effects_poisson_110", + _FE_POISSON, + models.fixed_effects_poisson, + n_groups=100, + n_periods=20, + n_slopes=10, + seed=118, + ), + _instance( + "fixed_effects_poisson_150", + _FE_POISSON, + models.fixed_effects_poisson, + n_groups=140, + n_periods=10, + n_slopes=10, + seed=119, + ), + _instance( + "random_effects_probit_41", + _RE_PROBIT, + models.random_effects_probit, + n_individuals=2000, + n_periods=5, + n_params=41, + seed=120, + ), + _instance( + "mixed_logit_correlated_26", + _MIXED_LOGIT, + models.mixed_logit, + n_individuals=1000, + n_situations=10, + n_alternatives=4, + n_fixed=6, + n_random=5, + correlated=True, + seed=122, + ), + _instance( + "heckman_37", + _HECKMAN, + models.heckman_selection, + n_obs=30_000, + n_selection_params=20, + n_outcome_params=15, + seed=123, + ), + _instance( + "zero_inflated_poisson_45", + _ZIP, + models.zero_inflated_poisson, + n_obs=10_000, + n_inflation_params=20, + n_count_params=25, + seed=124, + ), + _instance( + "stochastic_frontier_32", + _FRONTIER, + models.stochastic_frontier, + n_obs=10_000, + n_params=32, + seed=125, + ), +) + +_OVERDISPERSED = "overdispersed counts (variance = {} * mean)" +_UNDERDISPERSED = "underdispersed counts (variance = {} * mean)" +_T_ERRORS = "t distributed errors with {} degrees of freedom" +_IGNORED_HETERO = "ignored heteroskedasticity (log sd slope {})" +_MISCLASSIFIED = "{:.0%} of the outcomes are misclassified" +_NESTED = "nested logit data with dissimilarity {} (violates IIA)" +_FRAILTY = "ignored gamma frailty with variance {}" +_T_INNOVATIONS = "t distributed innovations with {} degrees of freedom" +_MULTIVARIATE_T = "multivariate t data with {} degrees of freedom" + +LIKELIHOOD_MISSPECIFIED_SMALL: tuple[LikelihoodInstance, ...] = ( + _instance( + "poisson_overdispersed_tiny_5", + _POISSON, + models.poisson_regression, + _OVERDISPERSED.format(1.2), + "tiny", + n_obs=3000, + n_params=5, + dgp_dispersion=1.2, + seed=201, + ), + _instance( + "poisson_overdispersed_moderate_5", + _POISSON, + models.poisson_regression, + _OVERDISPERSED.format(2), + "moderate", + n_obs=3000, + n_params=5, + dgp_dispersion=2.0, + seed=202, + ), + _instance( + "poisson_overdispersed_severe_5", + _POISSON, + models.poisson_regression, + _OVERDISPERSED.format(5), + "severe", + n_obs=3000, + n_params=5, + dgp_dispersion=5.0, + seed=203, + ), + _instance( + "poisson_underdispersed_moderate_5", + _POISSON, + models.poisson_regression, + _UNDERDISPERSED.format(0.6), + "moderate", + n_obs=3000, + n_params=5, + dgp_dispersion=0.6, + seed=204, + ), + _instance( + "poisson_underdispersed_severe_5", + _POISSON, + models.poisson_regression, + _UNDERDISPERSED.format(0.3), + "severe", + n_obs=3000, + n_params=5, + dgp_dispersion=0.3, + seed=205, + ), + _instance( + "regression_t_errors_tiny_5", + _REGRESSION, + models.linear_regression, + _T_ERRORS.format(30), + "tiny", + n_obs=2000, + n_mean_params=4, + n_variance_params=1, + dgp_error_df=30.0, + seed=206, + ), + _instance( + "regression_t_errors_moderate_5", + _REGRESSION, + models.linear_regression, + _T_ERRORS.format(5), + "moderate", + n_obs=2000, + n_mean_params=4, + n_variance_params=1, + dgp_error_df=5.0, + seed=207, + ), + _instance( + "regression_t_errors_severe_5", + _REGRESSION, + models.linear_regression, + _T_ERRORS.format(3), + "severe", + n_obs=2000, + n_mean_params=4, + n_variance_params=1, + dgp_error_df=3.0, + seed=208, + ), + _instance( + "regression_ignored_heteroskedasticity_mild_6", + _REGRESSION, + models.linear_regression, + _IGNORED_HETERO.format(0.3), + "mild", + n_obs=2000, + n_mean_params=5, + n_variance_params=1, + dgp_heteroskedasticity=0.3, + seed=209, + ), + _instance( + "regression_ignored_heteroskedasticity_severe_6", + _REGRESSION, + models.linear_regression, + _IGNORED_HETERO.format(1.0), + "severe", + n_obs=2000, + n_mean_params=5, + n_variance_params=1, + dgp_heteroskedasticity=1.0, + seed=210, + ), + _instance( + "logit_probit_data_tiny_6", + _LOGIT, + models.binary_choice, + "probit data (normal instead of logistic latent errors)", + "tiny", + n_obs=3000, + n_params=6, + strength=1.5, + dgp_errors="normal", + seed=211, + ), + _instance( + "logit_misclassified_mild_6", + _LOGIT, + models.binary_choice, + _MISCLASSIFIED.format(0.02), + "mild", + n_obs=3000, + n_params=6, + strength=1.5, + dgp_misclassification=0.02, + seed=212, + ), + _instance( + "logit_misclassified_moderate_6", + _LOGIT, + models.binary_choice, + _MISCLASSIFIED.format(0.1), + "moderate", + n_obs=3000, + n_params=6, + strength=1.5, + dgp_misclassification=0.1, + seed=213, + ), + _instance( + "logit_misclassified_severe_6", + _LOGIT, + models.binary_choice, + _MISCLASSIFIED.format(0.25), + "severe", + n_obs=3000, + n_params=6, + strength=1.5, + dgp_misclassification=0.25, + seed=214, + ), + _instance( + "probit_heteroskedastic_moderate_8", + _PROBIT, + models.binary_choice, + "heteroskedastic latent errors (log sd slope 0.5)", + "moderate", + n_obs=3000, + n_params=8, + model="probit", + dgp_heteroskedasticity=0.5, + seed=215, + ), + _instance( + "logit_sign_restricted_moderate_8", + _LOGIT, + models.binary_choice, + "nonnegativity bounds on four slopes, two of which are negative", + "moderate", + n_obs=3000, + n_params=8, + n_sign_restricted=4, + seed=216, + ), + _instance( + "multinomial_logit_nested_mild_11", + _MNL, + models.multinomial_logit, + _NESTED.format(0.8), + "mild", + n_obs=2000, + n_alternatives=4, + n_attributes=2, + n_characteristics=2, + dgp_nest_dissimilarity=0.8, + seed=217, + ), + _instance( + "multinomial_logit_nested_severe_14", + _MNL, + models.multinomial_logit, + _NESTED.format(0.3), + "severe", + n_obs=2000, + n_alternatives=5, + n_attributes=2, + n_characteristics=2, + dgp_nest_dissimilarity=0.3, + seed=218, + ), + _instance( + "weibull_frailty_mild_5", + _WEIBULL, + models.weibull_duration, + _FRAILTY.format(0.25), + "mild", + n_obs=2000, + n_params=5, + dgp_frailty_variance=0.25, + seed=219, + ), + _instance( + "weibull_frailty_severe_5", + _WEIBULL, + models.weibull_duration, + _FRAILTY.format(1.0), + "severe", + n_obs=2000, + n_params=5, + dgp_frailty_variance=1.0, + seed=220, + ), + _instance( + "garch_t_innovations_moderate_3", + _GARCH, + models.garch, + _T_INNOVATIONS.format(10), + "moderate", + n_obs=3000, + dgp_innovation_df=10.0, + seed=221, + ), + _instance( + "garch_t_innovations_severe_3", + _GARCH, + models.garch, + _T_INNOVATIONS.format(5), + "severe", + n_obs=3000, + dgp_innovation_df=5.0, + seed=222, + ), + _instance( + "multivariate_normal_t_data_tiny_9", + _MVN, + models.multivariate_normal, + _MULTIVARIATE_T.format(30), + "tiny", + n_obs=2000, + dim=3, + dgp_df=30.0, + seed=223, + ), + _instance( + "multivariate_normal_t_data_moderate_14", + _MVN, + models.multivariate_normal, + _MULTIVARIATE_T.format(6), + "moderate", + n_obs=2000, + dim=4, + dgp_df=6.0, + seed=224, + ), + _instance( + "multivariate_normal_t_data_severe_20", + _MVN, + models.multivariate_normal, + _MULTIVARIATE_T.format(4.5), + "severe", + n_obs=2000, + dim=5, + dgp_df=4.5, + seed=225, + ), + _instance( + "normal_mixture_three_components_severe_5", + _MIXTURE, + models.normal_mixture, + "the data come from a mixture of three normals", + "severe", + n_obs=1000, + dgp_three_components=True, + seed=226, + ), + _instance( + "ordered_probit_logistic_errors_mild_8", + _ORDERED, + models.ordered_probit, + "logistic instead of normal latent errors", + "mild", + n_obs=2000, + n_slopes=4, + n_categories=5, + dgp_errors="logistic", + seed=227, + ), + _instance( + "ordered_probit_skewed_errors_moderate_8", + _ORDERED, + models.ordered_probit, + "skewed (Gumbel) instead of normal latent errors", + "moderate", + n_obs=2000, + n_slopes=4, + n_categories=5, + dgp_errors="gumbel", + seed=228, + ), + _instance( + "tobit_heteroskedastic_moderate_6", + _TOBIT, + models.tobit, + _IGNORED_HETERO.format(0.5), + "moderate", + n_obs=2000, + n_params=6, + dgp_heteroskedasticity=0.5, + seed=229, + ), + _instance( + "tobit_t_errors_severe_6", + _TOBIT, + models.tobit, + _T_ERRORS.format(4), + "severe", + n_obs=2000, + n_params=6, + dgp_error_df=4.0, + seed=230, + ), + _instance( + "gamma_regression_lognormal_data_moderate_6", + _GAMMA, + models.gamma_regression, + "lognormal data with the same mean and variance", + "moderate", + n_obs=2000, + n_params=6, + dgp_lognormal=True, + seed=231, + ), + _instance( + "random_effects_probit_bimodal_effects_moderate_6", + _RE_PROBIT, + models.random_effects_probit, + "bimodal instead of normal random effects", + "moderate", + n_individuals=500, + n_periods=5, + n_params=6, + dgp_bimodal_effects=True, + seed=232, + ), + _instance( + "zero_inflated_poisson_negbin_data_moderate_8", + _ZIP, + models.zero_inflated_poisson, + "negative binomial data without zero inflation (variance = 3 * mean)", + "moderate", + n_obs=2000, + n_inflation_params=3, + n_count_params=5, + dgp_dispersion=3.0, + seed=233, + ), + _instance( + "heckman_t_errors_severe_10", + _HECKMAN, + models.heckman_selection, + "bivariate t errors with 4 degrees of freedom", + "severe", + n_obs=2000, + n_selection_params=5, + n_outcome_params=3, + dgp_error_df=4.0, + seed=234, + ), + _instance( + "stochastic_frontier_wrong_skew_severe_6", + _FRONTIER, + models.stochastic_frontier, + "residuals skewed in the wrong direction; solution on the bound", + "severe", + n_obs=2000, + n_params=6, + dgp_wrong_skew=True, + seed=235, + ), + _instance( + "mixed_logit_lognormal_coefficients_moderate_8", + _MIXED_LOGIT, + models.mixed_logit, + "lognormal instead of normal random coefficients", + "moderate", + n_individuals=300, + n_situations=8, + n_alternatives=3, + n_fixed=2, + n_random=3, + dgp_lognormal=True, + seed=122, + ), +) + +LIKELIHOOD_MISSPECIFIED_LARGE: tuple[LikelihoodInstance, ...] = ( + _instance( + "poisson_overdispersed_tiny_40", + _POISSON, + models.poisson_regression, + _OVERDISPERSED.format(1.2), + "tiny", + n_obs=10_000, + n_params=40, + dgp_dispersion=1.2, + seed=301, + ), + _instance( + "poisson_overdispersed_severe_40", + _POISSON, + models.poisson_regression, + _OVERDISPERSED.format(5), + "severe", + n_obs=50_000, + n_params=40, + dgp_dispersion=5.0, + seed=302, + ), + _instance( + "poisson_underdispersed_severe_40", + _POISSON, + models.poisson_regression, + _UNDERDISPERSED.format(0.4), + "severe", + n_obs=10_000, + n_params=40, + dgp_dispersion=0.4, + seed=303, + ), + _instance( + "regression_t_errors_moderate_61", + _REGRESSION, + models.linear_regression, + _T_ERRORS.format(5), + "moderate", + n_obs=10_000, + n_mean_params=60, + n_variance_params=1, + dgp_error_df=5.0, + seed=304, + ), + _instance( + "regression_t_errors_severe_61", + _REGRESSION, + models.linear_regression, + _T_ERRORS.format(3), + "severe", + n_obs=30_000, + n_mean_params=60, + n_variance_params=1, + dgp_error_df=3.0, + seed=305, + ), + _instance( + "regression_ignored_heteroskedasticity_severe_31", + _REGRESSION, + models.linear_regression, + _IGNORED_HETERO.format(1.0), + "severe", + n_obs=10_000, + n_mean_params=30, + n_variance_params=1, + dgp_heteroskedasticity=1.0, + seed=306, + ), + _instance( + "logit_probit_data_tiny_100", + _LOGIT, + models.binary_choice, + "probit data (normal instead of logistic latent errors)", + "tiny", + n_obs=10_000, + n_params=100, + strength=1.5, + dgp_errors="normal", + seed=307, + ), + _instance( + "logit_misclassified_moderate_60", + _LOGIT, + models.binary_choice, + _MISCLASSIFIED.format(0.1), + "moderate", + n_obs=10_000, + n_params=60, + strength=1.5, + dgp_misclassification=0.1, + seed=308, + ), + _instance( + "logit_sign_restricted_moderate_40", + _LOGIT, + models.binary_choice, + "nonnegativity bounds on ten slopes, five of which are negative", + "moderate", + n_obs=10_000, + n_params=40, + n_sign_restricted=10, + seed=309, + ), + _instance( + "multinomial_logit_nested_moderate_46", + _MNL, + models.multinomial_logit, + _NESTED.format(0.5), + "moderate", + n_obs=5000, + n_alternatives=8, + n_attributes=4, + n_characteristics=5, + dgp_nest_dissimilarity=0.5, + seed=310, + ), + _instance( + "multinomial_logit_nested_severe_123", + _MNL, + models.multinomial_logit, + _NESTED.format(0.3), + "severe", + n_obs=8000, + n_alternatives=10, + n_attributes=6, + n_characteristics=12, + dgp_nest_dissimilarity=0.3, + seed=311, + ), + _instance( + "weibull_frailty_severe_31", + _WEIBULL, + models.weibull_duration, + _FRAILTY.format(1.0), + "severe", + n_obs=10_000, + n_params=31, + dgp_frailty_variance=1.0, + seed=312, + ), + _instance( + "multivariate_normal_t_data_moderate_44", + _MVN, + models.multivariate_normal, + _MULTIVARIATE_T.format(6), + "moderate", + n_obs=3000, + dim=8, + dgp_df=6.0, + seed=313, + ), + _instance( + "multivariate_normal_t_data_tiny_90", + _MVN, + models.multivariate_normal, + _MULTIVARIATE_T.format(30), + "tiny", + n_obs=5000, + dim=12, + dgp_df=30.0, + seed=314, + ), + _instance( + "fixed_effects_poisson_overdispersed_moderate_110", + _FE_POISSON, + models.fixed_effects_poisson, + _OVERDISPERSED.format(3), + "moderate", + n_groups=100, + n_periods=20, + n_slopes=10, + dgp_dispersion=3.0, + seed=315, + ), + _instance( + "ordered_probit_skewed_errors_moderate_40", + _ORDERED, + models.ordered_probit, + "skewed (Gumbel) instead of normal latent errors", + "moderate", + n_obs=10_000, + n_slopes=30, + n_categories=11, + dgp_errors="gumbel", + seed=316, + ), + _instance( + "tobit_heteroskedastic_moderate_51", + _TOBIT, + models.tobit, + _IGNORED_HETERO.format(0.5), + "moderate", + n_obs=10_000, + n_params=51, + dgp_heteroskedasticity=0.5, + seed=317, + ), + _instance( + "heckman_t_errors_severe_37", + _HECKMAN, + models.heckman_selection, + "bivariate t errors with 4 degrees of freedom", + "severe", + n_obs=10_000, + n_selection_params=20, + n_outcome_params=15, + dgp_error_df=4.0, + seed=318, + ), + _instance( + "zero_inflated_poisson_negbin_data_moderate_45", + _ZIP, + models.zero_inflated_poisson, + "negative binomial data without zero inflation (variance = 3 * mean)", + "moderate", + n_obs=10_000, + n_inflation_params=20, + n_count_params=25, + dgp_dispersion=3.0, + seed=319, + ), + _instance( + "random_effects_probit_bimodal_effects_moderate_41", + _RE_PROBIT, + models.random_effects_probit, + "bimodal instead of normal random effects", + "moderate", + n_individuals=2000, + n_periods=5, + n_params=41, + dgp_bimodal_effects=True, + seed=320, + ), + _instance( + "gamma_regression_lognormal_data_moderate_41", + _GAMMA, + models.gamma_regression, + "lognormal data with the same mean and variance", + "moderate", + n_obs=10_000, + n_params=41, + dgp_lognormal=True, + seed=321, + ), + _instance( + "mixed_logit_lognormal_coefficients_moderate_30", + _MIXED_LOGIT, + models.mixed_logit, + "lognormal instead of normal random coefficients", + "moderate", + n_individuals=500, + n_situations=8, + n_alternatives=4, + n_fixed=6, + n_random=12, + dgp_lognormal=True, + seed=122, + ), + _instance( + "stochastic_frontier_wrong_skew_severe_32", + _FRONTIER, + models.stochastic_frontier, + "residuals skewed in the wrong direction; solution on the bound", + "severe", + n_obs=10_000, + n_params=32, + dgp_wrong_skew=True, + seed=323, + ), +) + +LIKELIHOOD_SETS: dict[str, tuple[LikelihoodInstance, ...]] = { + "likelihood_small": LIKELIHOOD_SMALL, + "likelihood_large": LIKELIHOOD_LARGE, + "likelihood_misspecified_small": LIKELIHOOD_MISSPECIFIED_SMALL, + "likelihood_misspecified_large": LIKELIHOOD_MISSPECIFIED_LARGE, +} + + +def get_likelihood_problems(name: str) -> dict[str, dict[str, Any]]: + """Simulate the data of a likelihood benchmark set and create its problems. + + Args: + name: Name of the benchmark set, one of the keys of LIKELIHOOD_SETS. + + Returns: + Dictionary that maps problem names to problem specifications with the entries + "fun", "jac", "start_x", "solution_x", "start_criterion", + "solution_criterion", "lower_bounds", "upper_bounds" and "info". "fun" returns + the negative log-likelihood contributions and "jac" their jacobian, both + marked as likelihood functions. + + """ + problems = {} + for instance in LIKELIHOOD_SETS[name]: + likelihood = instance.build() + solution = LIKELIHOOD_SOLUTIONS[instance.name] + solution_x = np.array(solution["params"]) + n_obs = len(likelihood.fun(solution_x)) + starts = {"good": likelihood.good_start, "bad": likelihood.bad_start} + for start_name, start_x in starts.items(): + problems[f"{instance.name}_{start_name}_start"] = { + "fun": mark.likelihood(likelihood.fun), + "jac": mark.likelihood(likelihood.jac), + "start_x": start_x, + "solution_x": solution_x if likelihood.unique_solution else None, + "start_criterion": float(likelihood.fun(start_x).sum()), + "solution_criterion": float(likelihood.fun(solution_x).sum()), + "lower_bounds": likelihood.lower_bounds, + "upper_bounds": likelihood.upper_bounds, + "info": { + "model": instance.model, + "n_params": likelihood.n_params, + "n_obs": n_obs, + "start": start_name, + "misspecification": instance.misspecification, + "severity": instance.severity, + "has_bounds": likelihood.lower_bounds is not None + or likelihood.upper_bounds is not None, + "unique_solution": likelihood.unique_solution, + "other_local_optima": solution["other_local_optima"], + "opg_hessian_ratio": solution["opg_hessian_ratio"], + }, + } + return problems diff --git a/src/optimagic/benchmarking/likelihood/sampling.py b/src/optimagic/benchmarking/likelihood/sampling.py new file mode 100644 index 000000000..6cccb40f1 --- /dev/null +++ b/src/optimagic/benchmarking/likelihood/sampling.py @@ -0,0 +1,96 @@ +"""Deterministic random draws for the simulated likelihood benchmark problems. + +NumPy only guarantees stable streams for its bit generators, not for the algorithms +that turn random bits into draws from a distribution. To keep the simulated datasets +(and thus the stored reference solutions) stable across NumPy versions, every draw is +computed from uniform draws via the inverse CDF of the target distribution. + +""" + +import numpy as np +from numpy.typing import ArrayLike, NDArray +from scipy import special, stats + +_SMALLEST_UNIFORM = 2.0**-53 + + +def uniform( + rng: np.random.Generator, size: int | tuple[int, ...] +) -> NDArray[np.float64]: + """Draw from the uniform distribution on the open interval (0, 1).""" + return np.maximum(rng.random(size), _SMALLEST_UNIFORM) + + +def standard_normal( + rng: np.random.Generator, size: int | tuple[int, ...] +) -> NDArray[np.float64]: + """Draw from the standard normal distribution.""" + return special.ndtri(uniform(rng, size)) + + +def standardized_t( + rng: np.random.Generator, df: float, size: int | tuple[int, ...] +) -> NDArray[np.float64]: + """Draw from a t distribution with df > 2 degrees of freedom and unit variance.""" + return special.stdtrit(df, uniform(rng, size)) * np.sqrt((df - 2) / df) + + +def gamma( + rng: np.random.Generator, + shape: ArrayLike, + scale: ArrayLike, + size: int | tuple[int, ...], +) -> NDArray[np.float64]: + """Draw from the gamma distribution with mean shape * scale.""" + return np.asarray(scale) * special.gammaincinv(shape, uniform(rng, size)) + + +def exponential( + rng: np.random.Generator, size: int | tuple[int, ...] +) -> NDArray[np.float64]: + """Draw from the exponential distribution with mean one.""" + return -np.log(uniform(rng, size)) + + +def standard_gumbel( + rng: np.random.Generator, size: int | tuple[int, ...] +) -> NDArray[np.float64]: + """Draw from the standard Gumbel (type I extreme value) distribution.""" + return -np.log(-np.log(uniform(rng, size))) + + +def standard_logistic( + rng: np.random.Generator, size: int | tuple[int, ...] +) -> NDArray[np.float64]: + """Draw from the standard logistic distribution.""" + return special.logit(uniform(rng, size)) + + +def poisson(rng: np.random.Generator, mean: NDArray[np.float64]) -> NDArray[np.float64]: + """Draw one Poisson count per entry of mean.""" + return stats.poisson.ppf(uniform(rng, mean.shape), mean) + + +def binomial( + rng: np.random.Generator, n_trials: NDArray[np.float64], probability: float +) -> NDArray[np.float64]: + """Draw one binomial count per entry of n_trials.""" + return stats.binom.ppf(uniform(rng, n_trials.shape), n_trials, probability) + + +def categorical( + rng: np.random.Generator, probabilities: NDArray[np.float64] +) -> NDArray[np.int64]: + """Draw one category per row of probabilities. + + Args: + rng: Random number generator. + probabilities: Array of shape (n, n_categories) whose rows sum to one. + + Returns: + Integer array of shape (n,) with values in {0, ..., n_categories - 1}. + + """ + cumulative = np.cumsum(probabilities, axis=1) + u = uniform(rng, len(probabilities)) * cumulative[:, -1] + return (cumulative[:, :-1] < u[:, None]).sum(axis=1) diff --git a/src/optimagic/benchmarking/likelihood/solutions.py b/src/optimagic/benchmarking/likelihood/solutions.py new file mode 100644 index 000000000..f9d2dbf21 --- /dev/null +++ b/src/optimagic/benchmarking/likelihood/solutions.py @@ -0,0 +1,2038 @@ +"""Reference solutions of the likelihood benchmark sets. + +Created by .tools/create_likelihood_solutions.py; do not edit by hand. + +""" + +from typing import Any + +# fmt: off +LIKELIHOOD_SOLUTIONS: dict[str, dict[str, Any]] = { + "logit_5": { + "params": [ + 0.28549591357622406, 0.5186646405531851, -0.39678241855391855, + 0.6146518040023086, -0.4621371541839665, + ], + "value": 11857.102610711003, + "opg_hessian_ratio": (0.9813, 1.022), + "other_local_optima": False, + }, + "logit_badly_scaled_8": { + "params": [ + 0.3013197188178047, 46.31802812946905, -7.791655350683069, + 1.9417447619051256, -0.3011101674481257, 0.05457122087592126, + -0.019768244744016283, 0.00368692010239337, + ], + "value": 1779.857969720358, + "opg_hessian_ratio": (0.9181, 1.062), + "other_local_optima": False, + }, + "logit_few_obs_25": { + "params": [ + 0.38333876975813996, 0.363696209860695, -0.5142906978843186, + 0.31425729700345023, -0.09369626356970316, 0.3543905465649778, + -0.2256804480594658, 0.47649912546517187, -0.24573102776212674, + 0.4246728243574891, -0.30027753234161764, 0.705013717236813, + -0.41406521043589756, 0.10658131790668297, -0.33367995117785554, + -0.09710855167799444, -0.3072202586602881, 0.1770574957935847, + -0.3512988861566812, 0.45949777512873846, -0.622351898824153, + 0.3436279144532825, -0.3258937192142956, 0.1357081940064463, + 0.11078256525088334, + ], + "value": 275.11002526044297, + "opg_hessian_ratio": (0.6937, 1.402), + "other_local_optima": False, + }, + "probit_badly_scaled_6": { + "params": [ + 0.34454126707283905, 48.76176511191154, -3.455213154211489, + 0.5466802647749608, -0.048595968193520536, 0.003780669908931324, + ], + "value": 1452.5066270685977, + "opg_hessian_ratio": (0.8907, 1.068), + "other_local_optima": False, + }, + "probit_16": { + "params": [ + 0.3221786837403671, 0.4268952887968936, -0.3242809010737749, + 0.5064170237414285, -0.42059132799912485, 0.23805476409513704, + -0.34346922626706744, 0.34387522663598485, -0.5984715545486239, + 0.44027693327255285, -0.2822371653946527, 0.45088990795230577, + -0.37457514726726815, 0.2542201781441169, -0.4600402748918654, + 0.36896748676298746, + ], + "value": 932.3863311139296, + "opg_hessian_ratio": (0.8062, 1.204), + "other_local_optima": False, + }, + "poisson_5": { + "params": [ + 0.985350946682334, 0.2545949746935169, -0.21551213283002646, + 0.3035766768162159, -0.2526191850773488, + ], + "value": 3706.6269736984045, + "opg_hessian_ratio": (0.8157, 1.034), + "other_local_optima": False, + }, + "poisson_15": { + "params": [ + 0.993789413717653, 0.14065537263709008, -0.1098833214743913, + 0.16328092895530952, -0.13238212663389276, 0.0952423790260136, + -0.154654075366272, 0.12183756277960624, -0.17128470606813428, + 0.13617540378693255, -0.10281889648043802, 0.15993278266958816, + -0.12310252994372528, 0.10194991257578677, -0.14412420594081024, + ], + "value": 37336.44109767188, + "opg_hessian_ratio": (0.9148, 1.066), + "other_local_optima": False, + }, + "negative_binomial_5": { + "params": [ + 1.0252111075904975, 0.27725374338117925, -0.22250564295644548, + 0.3549076420616566, -0.3530043011672566, + ], + "value": 6584.35502944592, + "opg_hessian_ratio": (0.8603, 1.041), + "other_local_optima": False, + }, + "negative_binomial_14": { + "params": [ + 0.9922566004115487, 0.1436324649034301, -0.13852565382037602, + 0.15588914601874052, -0.10826655173256683, 0.09661999901506843, + -0.1676799491862819, 0.1314698116684641, -0.1996215302340791, + 0.1595160804097527, -0.1290110428107847, 0.14898661971646662, + -0.15832289750159093, -0.4307566148399601, + ], + "value": 6513.252797659359, + "opg_hessian_ratio": (0.7991, 1.205), + "other_local_optima": False, + }, + "heteroskedastic_regression_7": { + "params": [ + 2.0288570613369026, 0.558155654516943, -0.3941094641967376, + 0.5962685442944258, -0.4668239255733062, 0.009633019476579028, + 0.49182248115445626, + ], + "value": 2887.595495088436, + "opg_hessian_ratio": (0.7397, 1.195), + "other_local_optima": False, + }, + "heteroskedastic_regression_20": { + "params": [ + 2.006263852513678, 0.312476731631992, -0.24535231581336137, + 0.36841950694185194, -0.27452120509618044, 0.22144297060327903, + -0.3233730386679136, 0.2659933775649289, -0.38745028238052714, + 0.3142221923094815, -0.2457387189935253, 0.3569651579596412, + 0.027735933374103537, 0.16628910210793388, -0.2103677315492036, + 0.13806382953154686, -0.1795333908988099, 0.243053309142736, + -0.16563030493614764, 0.22692580646741056, + ], + "value": 4343.258161001084, + "opg_hessian_ratio": (0.7673, 1.379), + "other_local_optima": False, + }, + "tobit_6": { + "params": [ + 0.5459679584572474, 0.5389392855807885, -0.3833403037564207, + 0.5617158521546204, -0.47889685886852335, 0.38580932812444374, + ], + "value": 2749.537574557128, + "opg_hessian_ratio": (0.9092, 1.114), + "other_local_optima": False, + }, + "tobit_16": { + "params": [ + 0.5142190855525967, 0.31384953914163743, -0.20383152678266314, + 0.32066861645132244, -0.2798590710080286, 0.21066950848409635, + -0.27110234943100014, 0.22218569859690002, -0.38827139302847774, + 0.2620513080357701, -0.259190863056419, 0.2920615453018539, + -0.29865541638283355, 0.13708422952683255, -0.29297654471767265, + 0.42848704866962717, + ], + "value": 4171.128528108196, + "opg_hessian_ratio": (0.8074, 1.216), + "other_local_optima": False, + }, + "ordered_probit_8": { + "params": [ + 0.5474654887952167, -0.36704220239298635, 0.5945166760676635, + -0.4790273248111856, -1.1608179752082923, -0.1866638754050476, + -0.3171082368591089, -0.27288691822754485, + ], + "value": 2614.5601431170007, + "opg_hessian_ratio": (0.8871, 1.096), + "other_local_optima": False, + }, + "ordered_probit_18": { + "params": [ + 0.34302142825672777, -0.24066018687864524, 0.33354144687629783, + -0.3070784436647499, 0.23116452622927697, -0.3542048545065553, + 0.26651958642979523, -0.39180649125548184, 0.29570760306856236, + -0.24167389644515602, -1.7260850465974558, -0.3759711767110067, + -0.7708084101819771, -0.8726339753804232, -0.8817853598859574, + -0.9300564161977306, -0.7935307100203948, -0.5551683854343141, + ], + "value": 5677.392384496983, + "opg_hessian_ratio": (0.8552, 1.166), + "other_local_optima": False, + }, + "multinomial_logit_11": { + "params": [ + 0.8153773148046676, -0.6119652918249447, -0.09341873824879697, + -0.08165359173910836, 0.14150007711985946, -0.14770077359353573, + 0.40230917276278394, -0.29148160766063186, 0.41019818223872245, + 0.010588916689703914, -0.271659951438745, + ], + "value": 2160.161792777815, + "opg_hessian_ratio": (0.8756, 1.158), + "other_local_optima": False, + }, + "multinomial_logit_23": { + "params": [ + 0.5814362267084794, -0.4438026125116207, 0.7394096014838846, + -0.04402481928840271, -0.09406716180533523, 0.2642575500552985, + -0.19895510889705825, 0.02103795396346756, -0.26237236902849514, + 0.2904649163269016, -0.008961739987118057, 0.005095594270931455, + 0.34305809764137135, 0.1302732381683114, 0.06604075018322701, + -0.15986017326922086, 0.3114841668590654, -0.09669961890414773, + 0.2180656950936567, -0.31364116850137985, 0.2590679924654681, + -0.04212482297856231, -0.2161657491561482, + ], + "value": 3748.371278432597, + "opg_hessian_ratio": (0.8518, 1.176), + "other_local_optima": False, + }, + "weibull_5": { + "params": [ + -0.5034721581309484, 0.2896332488976031, -0.22556711310502275, + 0.3367857794235352, 0.3809727106752016, + ], + "value": 7238.567479704383, + "opg_hessian_ratio": (0.9046, 1.077), + "other_local_optima": False, + }, + "weibull_12": { + "params": [ + -0.5402239812215354, 0.17100016047329702, -0.1251943115940631, + 0.17668566120833148, -0.1900801289359814, 0.12270634859812571, + -0.17018641443941238, 0.08874880984158245, -0.1958722670415342, + 0.1761275429110874, -0.11278629048360046, 0.43330300920854603, + ], + "value": 2120.186612895542, + "opg_hessian_ratio": (0.7914, 1.332), + "other_local_optima": False, + }, + "gamma_regression_6": { + "params": [ + 0.9888537097425455, 0.28043862748106774, -0.19903013669266306, + 0.306452465804591, -0.25243338399670046, 0.6761321513397767, + ], + "value": 3758.38203044526, + "opg_hessian_ratio": (0.8862, 1.132), + "other_local_optima": False, + }, + "multivariate_normal_9": { + "params": [ + -1.9587675101386457, -0.09596595345460802, 1.989688837091807, + -0.7065937212777539, -0.6242442404501407, 0.5011245477737178, + 0.3610233776136951, -1.2315043690077354, 1.0114323549534803, + ], + "value": 5062.778781063465, + "opg_hessian_ratio": (0.8828, 1.131), + "other_local_optima": False, + }, + "multivariate_normal_20": { + "params": [ + -2.002673957385288, -1.0233470879174942, -0.009468776122634477, + 1.0320897405031275, 1.9564375825886007, -0.6835955547467866, + -0.44603025110088934, 0.052534530960547006, 0.2722003505198124, + -0.741512221539487, 0.4603544541235044, -0.17331756819483363, + 0.34836548634326314, -0.8595530537047396, 0.776659107606361, + 0.13500225396780433, -0.10048811756793882, 0.5325469793014128, + -1.165247375718446, 1.0258448249028924, + ], + "value": 17452.9800577398, + "opg_hessian_ratio": (0.7943, 1.214), + "other_local_optima": False, + }, + "garch_3": { + "params": [ + 0.046466926758513424, 0.0936504520109312, 0.8877401498022581, + ], + "value": 5263.494719623876, + "opg_hessian_ratio": (1.08, 1.279), + "other_local_optima": False, + }, + "garch_t_4": { + "params": [ + 0.04801458986052184, 0.07982116941481518, 0.8994537165517703, + 6.551114885678853, + ], + "value": 5129.550413018834, + "opg_hessian_ratio": (0.927, 1.069), + "other_local_optima": False, + }, + "random_effects_probit_6": { + "params": [ + -0.34627249941052246, 0.5602710690657398, -0.4358907042559569, + 0.622038666565665, -0.4742737272673588, -0.029468535721160025, + ], + "value": 1266.7856641901421, + "opg_hessian_ratio": (0.825, 1.125), + "other_local_optima": False, + }, + "mixed_logit_8": { + "params": [ + 0.7156944756295491, -0.5764374030908259, 0.8913787803326092, + 1.340599405283409, 1.9307240259086502, 0.8143493071964869, + 0.5776285257410395, 0.22082843789574055, + ], + "value": 1317.365961122289, + "opg_hessian_ratio": (0.7508, 2.073), + "other_local_optima": False, + }, + "mixed_logit_zero_sd_8": { + "params": [ + 0.7628915124751067, -0.6183164139814428, 1.0279832136607436, + 1.2835414718436098, 1.8969590672134657, 0.8903781895893675, + 0.492001817488894, 0.0, + ], + "value": 1280.1496034856787, + "opg_hessian_ratio": (0.7834, 1.893), + "other_local_optima": False, + }, + "mixed_logit_correlated_18": { + "params": [ + 0.5242041695359013, -0.42808458260166393, 0.5564282283828935, + -0.4080043515472019, 0.9909430908702607, 1.262471280549861, + 1.5548300369405228, 1.913439615575047, 0.6881958483596935, + 0.17905682962493846, 0.5482796364734775, 0.20507588574970045, + 0.09716511531084443, 0.4683603390079324, 0.09021411320977624, + 0.0354298468110285, 0.21571781252764785, 0.381052925940791, + ], + "value": 2509.037794701835, + "opg_hessian_ratio": (0.7061, 2.102), + "other_local_optima": True, + }, + "normal_mixture_5": { + "params": [ + -0.911489858381733, 1.5225244218982064, -0.32386899973548317, + -0.05551546448059611, -0.6081626530660666, + ], + "value": 1740.885670827295, + "opg_hessian_ratio": (0.8673, 1.531), + "other_local_optima": False, + }, + "heckman_10": { + "params": [ + 0.26417454151513153, -0.5008359886740406, 0.5392034642043677, + -0.36134813364580504, 0.512829965411797, 0.9353504272379328, + 0.7610723968431105, -0.5828370413991854, 0.17679079662829839, + 0.5635651884660042, + ], + "value": 2733.725874144562, + "opg_hessian_ratio": (0.7923, 1.295), + "other_local_optima": False, + }, + "zero_inflated_poisson_8": { + "params": [ + -1.1173399108542674, 0.44992801250672365, -0.3623469146124007, + 1.0008636902144585, -0.20374776616744175, 0.2408030458928518, + -0.15140206581934962, 0.17417711507596384, + ], + "value": 3578.2098580848424, + "opg_hessian_ratio": (0.8592, 1.102), + "other_local_optima": False, + }, + "stochastic_frontier_6": { + "params": [ + 1.0446619636688599, 0.27236610170883635, -0.20980799314219242, + 0.3323650650480676, -0.8093318473846373, 1.0438735075284362, + ], + "value": 2267.22127314502, + "opg_hessian_ratio": (0.8726, 1.166), + "other_local_optima": False, + }, + "fixed_effects_poisson_18": { + "params": [ + 0.32349181908233354, -0.2313841346739578, 0.2887815259725679, + 1.1823982329381493, 1.6162390119187013, 1.378097446165548, + 1.5371395933648768, 1.5515553672223366, 1.9975153264752321, + 2.2610439913550078, 1.6373378237830747, 1.8379742986848786, + 1.7616999934639066, 1.417094164667675, 1.650977652711313, + 1.3473209679459708, 1.8134232150834706, 1.200085305255103, + ], + "value": 312.6341915346404, + "opg_hessian_ratio": (0.1679, 1.624), + "other_local_optima": False, + }, + "logit_50": { + "params": [ + 0.31502748222807253, 0.17770028948979766, -0.1158187757865123, + 0.18157494773361957, -0.14219197332562883, 0.11929490472261131, + -0.16958583059141147, 0.12298360815430319, -0.20321863268334303, + 0.13676340885458402, -0.11186743955205639, 0.16310927249263074, + -0.12100893667140876, 0.12246208828032608, -0.18889273175105242, + 0.12475087174599021, -0.17666023853998108, 0.1502766550490955, + -0.12053116609714544, 0.15633920326227665, -0.13354811505367503, + 0.18126076207771677, -0.15147597091198153, 0.118872199796724, + -0.17766574908780844, 0.1419292396681968, -0.1209989525040971, + 0.16636828284264782, -0.11599702376178375, 0.2030429295318785, + -0.1689127777113093, 0.10485714103836248, -0.1733014754518424, + 0.11882737655709683, -0.07142902419875802, 0.15763259904039414, + -0.1276007002636322, 0.17998443018178611, -0.12696751561615435, + 0.11034134646696192, -0.16783963447946376, 0.12784337707760524, + -0.15186876444422082, 0.16228523316176569, -0.12397834626558647, + 0.1526735929080848, -0.16236970897506517, 0.09205572413626809, + -0.1484440441917198, 0.12644281465156895, + ], + "value": 31359.62431673476, + "opg_hessian_ratio": (0.9568, 1.041), + "other_local_optima": False, + }, + "logit_badly_scaled_100": { + "params": [ + 0.30545277815748995, 7.362463559097196, -10.635816360612283, + 11.772677985248626, -7.735346653187552, 3.1357454227620485, + -8.523149544769696, 4.946878749330099, -7.5424663495506845, + 5.157481507070269, -4.11017167890681, 3.220334941021829, + -1.9675104681157884, 3.475961543754836, -2.5300292531583417, + 1.5980969116862342, -3.1465261426709596, 2.912091583182477, + -2.0234995138160485, 2.0733316135635684, -1.089711295018257, + 1.737381655607921, -1.259671337453427, 0.7420152145089474, + -1.2208010925475294, 0.6492388778740025, -0.8317099764279753, + 1.1258420604069268, -0.3279177377648533, 0.6296500906583083, + -0.4774479347645797, 0.5196714410183636, -0.5747397625216456, + 0.5188822562840537, -0.2524440367023788, 0.3583251549934816, + -0.37237539845631384, 0.5380448798816089, -0.33263997862310424, + 0.18499050991113802, -0.34078597930739846, 0.17801201596009533, + -0.30709739274635484, 0.20941965485838568, -0.12121800060625522, + 0.2586021807213857, -0.06917213871556618, 0.09868611898447736, + -0.1320830664129685, 0.12720365967445027, -0.1170235998870059, + 0.049803771021270794, -0.05481486949894679, 0.09756794781078719, + -0.08009418488501084, 0.0717458943510147, -0.047733180483332735, + 0.033530154008527095, -0.07718753480240785, 0.040011812018730546, + -0.0312056969940911, 0.03497438079600459, -0.022436527349610522, + 0.037702781336395305, -0.0376587140464483, 0.017093659105909566, + -0.0247958884060855, 0.015205836358924833, -0.00833494282252631, + 0.015329462241944213, -0.010364966549290587, 0.018156271706411056, + -0.015279517460200587, 0.007004069662061855, -0.012412457358905345, + 0.009564102218937652, -0.012811842333888341, 0.008701715904434568, + -0.00421773535009157, 0.007320506342366355, -0.006675046225400473, + 0.00268626701465113, -0.0074924157310975615, 0.005188713732256839, + -0.004147991371740104, 0.003747570355401571, -0.0021286898411161464, + 0.003517594232679207, -0.003378254544728537, 0.0015841321520008488, + -0.002473527140801015, 0.0020225599692810705, -0.002370676582597727, + 0.0023472761341842003, -0.0003838342463987298, 0.0016695457259569013, + -0.0011754863686521226, 0.001501368845940407, -0.0011698635711259932, + 0.000484879206431875, + ], + "value": 5932.245796605885, + "opg_hessian_ratio": (0.8572, 1.183), + "other_local_optima": False, + }, + "logit_few_obs_150": { + "params": [ + 0.34974910197384457, -0.01136445682277158, -0.04613620811562069, + 0.16226027603787777, -0.0445233157407152, 0.047408143172760514, + -0.14589620761372363, 0.02438026554048909, -0.13091745550118283, + 0.14972531808569878, -0.08520820473018821, 0.0964175050015273, + -0.00890658996835381, 0.052652453447705645, -0.06348220801169414, + 0.10084453333824595, -0.1461355032916156, 0.055184533871146996, + -0.046008107754551365, 0.012904440455006827, -0.06831986644915486, + 0.15616533995311835, -0.03866227390444787, 0.0048071646543184675, + -0.07660931272961317, 0.07230100883174866, -0.04181796862865887, + 0.05227448399531696, -0.04891566541158934, 0.05901451994384105, + -0.09859484358414822, 0.09385912038121222, -0.02522169636157079, + 0.0869564745834235, -0.15807143096966805, 0.1931675341389949, + -0.13637649799965604, 0.17058178982643246, -0.0837980170168589, + 0.11955836752052289, -0.2015588942285681, 0.10545509273957482, + -0.09294752676493986, 0.12017868787612565, -0.1136387461318267, + 0.14065834298916635, -0.10679282622701688, 0.06819487179625568, + -0.13576851803467443, 0.08121957397472142, -0.1933062603647529, + -0.015983331305909575, -0.06174553999565479, 0.07048515706915173, + -0.11428942193568968, 0.026130902110355667, -0.14318166484800038, + 0.04704769316189418, -0.0843079168089556, 0.09714669789696197, + 0.03639507127732035, 0.11938696109113775, -0.06456882342985155, + 0.13980589385711184, -0.09288637707960526, 0.0975879781773927, + -0.11341164804464687, 0.06051480901601912, -0.05757718152402293, + 0.10713312440510393, -0.07400163095119748, 0.08909374394907162, + -0.1229494801927583, 0.052374647287721954, -0.09618349451848647, + 0.14017355076457236, -0.19289979957861497, 0.1594249883671627, + -0.07861074506340186, 0.09303675762997973, -0.05351847992877192, + 0.07035985740680449, -0.07893584309811803, 0.1396683558384157, + -0.12656876840674777, 0.12827172017474803, -0.03634912850498932, + 0.09932618652149937, -0.0989482906060903, 0.029834925760464627, + -0.043233203669642284, 0.02676030414071784, -0.09981728594059187, + 0.049948544964802784, -0.059009893272428476, 0.11186145004740947, + -0.14482189804314655, 0.03010099233864113, -0.009713792917296534, + 0.09643137688670787, -0.0849517177495558, 0.0659093687177939, + -0.02899242871262053, 0.0717635244622756, -0.015886960358204336, + 0.10020510750519568, -0.1451012027601561, 0.08994518500903487, + -0.24191689685168805, 0.11004684569576653, -0.057885198100350796, + 0.10627607374635772, -0.07035111944153687, 0.0479309670482907, + -0.08382108365040955, 0.08642419278723884, -0.05091958424602465, + 0.024396985099467753, -0.03531517533019047, 0.12998221196771717, + 0.018951874481443615, 0.14378176863430986, -0.10153317424752069, + 0.029163775819036862, -0.08601204729419976, 0.036651809829763855, + -0.08563267232833649, 0.10401531936722888, -0.11861077569720276, + 0.0303896214417643, -0.005471590331334591, 0.20022934337315404, + -0.05100168132893399, 0.040470871541070916, -0.11066504163716662, + 0.0892131750537887, -0.09932773147325907, 0.15346822947358507, + -0.10532732143532175, 0.0713635079830433, -0.07895906596392882, + 0.004261521024885929, -0.06301066109253671, 0.05195246538051233, + -0.09287925724141224, 0.09924299538161425, -0.09727540344457752, + 0.14741970234284799, -0.0698068591288387, 0.03113916984853444, + ], + "value": 1778.8317715924718, + "opg_hessian_ratio": (0.6994, 1.441), + "other_local_optima": False, + }, + "probit_80": { + "params": [ + 0.29455659821331104, 0.15683581650033757, -0.13640825976023202, + 0.1632361144726446, -0.18265052305570617, 0.0847808103892418, + -0.1920251838402694, 0.1472973443503652, -0.21880890330533484, + 0.1598940161744688, -0.12996466194552178, 0.20930844126780626, + -0.17228755368460433, 0.09369340852495725, -0.17848369563350455, + 0.13278104562663504, -0.22853399524151688, 0.1913818936310914, + -0.11049941527452672, 0.20846173149147207, -0.16573553813673236, + 0.24230370043569568, -0.17952172836279606, 0.1431540577239182, + -0.22146480525233547, 0.16916972677403294, -0.08804906784173365, + 0.19464817023995856, -0.1421146163474534, 0.1917816006374017, + -0.17891046293906557, 0.11748393914830246, -0.21325669758889024, + 0.157611389817852, -0.11653775642203153, 0.1908519886856242, + -0.14641121096987036, 0.2034716674812414, -0.1512593801607616, + 0.12389169412696367, -0.2170684528432849, 0.1686144981316139, + -0.2197545463437544, 0.18239545169515875, -0.12398810197416109, + 0.23613155701917823, -0.17498120672038192, 0.1278247916825425, + -0.14540648310082754, 0.14759254588684168, -0.22836921216920011, + 0.18439726221078034, -0.1545773256423402, 0.20288172436151836, + -0.11523951838833102, 0.21039583079631416, -0.18637778255410706, + 0.14393863309699975, -0.2094313215482506, 0.1479327317522124, + -0.11710831947453039, 0.18915021674381605, -0.13049542409400544, + 0.2202481280284994, -0.14443196049753199, 0.14701629731303356, + -0.21235377146501852, 0.150090841073006, -0.10863011237474751, + 0.1874803495634292, -0.14727992685014635, 0.16642217243392285, + -0.1459076957389124, 0.13814616638523128, -0.19820491005440047, + 0.1637260636616258, -0.2053555110969523, 0.1914668273565388, + -0.10228137452662159, 0.1829440088695525, + ], + "value": 3849.15572082927, + "opg_hessian_ratio": (0.7717, 1.302), + "other_local_optima": False, + }, + "poisson_60": { + "params": [ + 1.0003181058604622, 0.0637220502208839, -0.05378040292112767, + 0.0863412076844615, -0.06574734275334879, 0.051124010502532596, + -0.07604857393896138, 0.05347824062280726, -0.08166008955381601, + 0.06986721782345476, -0.043438145751431984, 0.07127414360642811, + -0.05683936450821191, 0.04455095187548493, -0.06791669112924566, + 0.050094833298698835, -0.07721122163330553, 0.061329452280582404, + -0.04703924267240062, 0.06623251372767244, -0.05182576679143983, + 0.08530068631514039, -0.06310765817213987, 0.04553754718854983, + -0.07889235606883024, 0.06723504331641594, -0.048033487135179645, + 0.07388001420415304, -0.05207776600939659, 0.08155218752430778, + -0.07003599312795974, 0.0539090473350014, -0.07374357822432426, + 0.05498890801402938, -0.05190379789699544, 0.07007383394205113, + -0.053671423981166165, 0.07788460248726793, -0.06376534274913336, + 0.047953190945086044, -0.0706757395380667, 0.05837533771479633, + -0.08445916216531751, 0.06168880767159854, -0.05401759845279047, + 0.07658258047838754, -0.06215116158425015, 0.05289660696823593, + -0.07103985988314954, 0.056732304195523, -0.08294084110891305, + 0.06464019162351868, -0.04705693137465407, 0.07031469725687986, + -0.05401385909727807, 0.08535290449491548, -0.06643629613716125, + 0.05407976671890183, -0.07112085837527646, 0.05284304838626171, + ], + "value": 56098.23505123465, + "opg_hessian_ratio": (0.8662, 1.137), + "other_local_optima": False, + }, + "negative_binomial_41": { + "params": [ + 1.004888043689345, 0.0849758882555862, -0.06307045634566698, + 0.09551914747321731, -0.06532840265218395, 0.044632249791091545, + -0.10555600736102132, 0.0803775598888182, -0.10199117191616709, + 0.08255926258133442, -0.05433997431679067, 0.12175127914298774, + -0.09043230108539278, 0.061493463159570244, -0.08399513643871061, + 0.062054739482128876, -0.11244783115161008, 0.090961240118372, + -0.059089768140368204, 0.09056765531287402, -0.0658498681623466, + 0.11447207222096091, -0.08086283681325844, 0.049366506169577565, + -0.09190835987889973, 0.08025541197333688, -0.0628222036494086, + 0.09016431768116283, -0.05794186667759129, 0.10120668732103856, + -0.06977705650426971, 0.08120179511123332, -0.08076081818328777, + 0.06408915932434896, -0.03206478557301967, 0.09573255591725628, + -0.07918819158590788, 0.10537353462752067, -0.07456653909759973, + 0.06493630415995966, -0.369569410174298, + ], + "value": 21633.99335783311, + "opg_hessian_ratio": (0.7817, 1.356), + "other_local_optima": False, + }, + "heteroskedastic_regression_60": { + "params": [ + 1.997301233527656, 0.1902172168540029, -0.14901468783990815, + 0.2156560661301834, -0.18402351365376313, 0.1250322908599955, + -0.19420716297552462, 0.15230717253201134, -0.22681904431731714, + 0.18918384685265965, -0.13744661984394624, 0.21114948484243826, + -0.15019448938372, 0.11608789560212296, -0.2027991722116647, + 0.15821934504902357, -0.21907191021123001, 0.19135096669207224, + -0.13821725623882383, 0.21797452807051199, -0.16272901191868397, + 0.23776125041508034, -0.20200043743173196, 0.14136101952665547, + -0.22198897809928406, 0.1649081558915957, -0.12765529631296194, + 0.22740173394714427, -0.15419387031580248, 0.23537319076960134, + -0.010300868620606278, 0.11999196368976482, -0.07905542830894624, + 0.10169519094162909, -0.05947497976849261, 0.0907675745510924, + -0.1182202924166698, 0.06448940252500554, -0.0943515643620019, + 0.11845625862360575, -0.09116167943719049, 0.10883959137048707, + -0.07672741121394458, 0.09102165891872288, -0.1130045762115177, + 0.0786263879926818, -0.10355143178199469, 0.07016693433904701, + -0.08390596950082432, 0.10695936206781691, -0.07804288903257531, + 0.09536426146234038, -0.1207722307594366, 0.08517176896756319, + -0.1185563807751837, 0.06368929717368918, -0.10850989383370188, + 0.11068678618920844, -0.07772819020587453, 0.09755057107234082, + ], + "value": 14107.931735164062, + "opg_hessian_ratio": (0.7333, 1.384), + "other_local_optima": False, + }, + "heteroskedastic_regression_120": { + "params": [ + 2.003423118707384, 0.13659497798554296, -0.09295558268927752, + 0.15712466009795886, -0.10587031379632594, 0.10192627972555142, + -0.15373104240261828, 0.11096865515883826, -0.16636086026554892, + 0.13042588927514567, -0.10721623315920227, 0.16218999080849708, + -0.1062586370757506, 0.0913235685425174, -0.14100681309656518, + 0.11361510648490118, -0.16114523562402366, 0.12564460901040134, + -0.0891330349753452, 0.14394297654632693, -0.1149984314103147, + 0.17699588806477648, -0.13114998580984147, 0.10811572152032943, + -0.1557595626031857, 0.12141381896321492, -0.1034273075406493, + 0.1456158524254996, -0.1315641325909776, 0.1545299482790885, + -0.12665316693991857, 0.09822151216143725, -0.13823297766692927, + 0.11663510724083564, -0.10895397213650808, 0.144514622741204, + -0.11468601319253524, 0.16363241526096578, -0.13758564682638957, + 0.10615994340641824, -0.15191802120144146, 0.1301089387790191, + -0.1660983698143459, 0.13259436308764896, -0.10155405625266502, + 0.15497909791655376, -0.1115978523493163, 0.0802054440992959, + -0.14769413827713374, 0.10703519279143103, -0.16922484972668358, + 0.13377859171524797, -0.07641616077525862, 0.13627567349075856, + -0.12163198858748175, 0.15970330704286695, -0.15163947839766762, + 0.09972079430641854, -0.1496734227954088, 0.12196211461465707, + -0.0024859756595271084, 0.05476472193468366, -0.0986260614092762, + 0.04337900573307731, -0.06821749596653706, 0.0999539841746771, + -0.05377491844846824, 0.07994083402337475, -0.05997015572887499, + 0.0768885064513504, -0.07902267521296703, 0.049519812301210636, + -0.07261241630352888, 0.04938937300555259, -0.06620804273464936, + 0.07935541442706333, -0.03863703516257486, 0.07634790996638326, + -0.0792103876193333, 0.05646448612004951, -0.06634060286379527, + 0.054724830046878205, -0.046787632108323186, 0.06597194139961168, + -0.06093029198255305, 0.08288888929799133, -0.022952753173990873, + 0.05839399198962614, -0.1026313030075768, 0.043976182780841915, + -0.07153783414509478, 0.08394624940325973, -0.04464386853229886, + 0.08151585340683677, -0.056064257738912764, 0.065167478095157, + -0.07645487834313766, 0.04187908616550895, -0.0722045290576432, + 0.09546615799999368, -0.055444333006650325, 0.06615485019087024, + -0.045977738148563256, 0.07086115775618763, -0.08578550312689014, + 0.04247775405546156, -0.0707023050766814, 0.040703316857865005, + -0.05652638146124025, 0.07287844212232425, -0.06081102193659647, + 0.04899550467137983, -0.09052351344922112, 0.044238220262463296, + -0.07277623291543332, 0.04686598710253599, -0.06836673552784617, + 0.07065340011608186, -0.05134342387741589, 0.06429480588975348, + ], + "value": 11278.079538593563, + "opg_hessian_ratio": (0.6182, 2.61), + "other_local_optima": False, + }, + "tobit_51": { + "params": [ + 0.49510853463029536, 0.15466701507585054, -0.12240213435164757, + 0.15883695704547834, -0.14201221709844136, 0.10764409746411821, + -0.17629208120464512, 0.13002795648041562, -0.18067938759965455, + 0.13265994809159082, -0.10547844983964903, 0.1750628302699803, + -0.14556244504759783, 0.1171826600452297, -0.16261468401067192, + 0.12540546847035572, -0.1803014694189776, 0.15090682463611957, + -0.10200509125860623, 0.15684277956166018, -0.1401309049117116, + 0.19163226429137176, -0.15831241782658087, 0.11476372300894386, + -0.1842642656478529, 0.12343247200368544, -0.10352239775041315, + 0.15670178945959443, -0.12217314943639038, 0.18012637859217667, + -0.14435212112897292, 0.11018517544580796, -0.1627567699059963, + 0.14393096713261658, -0.09337463134542195, 0.14688039521652949, + -0.1302009105281729, 0.17823998152861803, -0.15398414818378459, + 0.07199140963053718, -0.1612409927987152, 0.1350580668585412, + -0.1929267425270793, 0.15140373410009092, -0.11056700499860786, + 0.158510677266969, -0.12662724823916058, 0.09745072625337589, + -0.15754195720320202, 0.13704647475905582, 0.39334390514172085, + ], + "value": 40958.378906025835, + "opg_hessian_ratio": (0.9058, 1.123), + "other_local_optima": False, + }, + "ordered_probit_40": { + "params": [ + 0.18410709370026143, -0.14889103698434422, 0.22005620737846093, + -0.16828875141308716, 0.10897004692819967, -0.2148990445951944, + 0.16338534482218012, -0.2297555569011007, 0.1811330882572523, + -0.12102586858491242, 0.2106582023967534, -0.16057212506647425, + 0.11854948716108293, -0.19988669148693022, 0.15635959646883674, + -0.21596636137073777, 0.1878533946975022, -0.11946414990040784, + 0.20873420521350622, -0.16658790653410244, 0.2288063874510117, + -0.20427733194520575, 0.14400613290963335, -0.2126297874343379, + 0.19583117689410576, -0.13485215951957907, 0.20850162574146014, + -0.1572614340939513, 0.23292854976157712, -0.16570454093892148, + -1.9390537750380974, -0.46146786179903676, -0.8211181474288378, + -1.0007199928827326, -1.0745324069078241, -1.0989010379374269, + -1.0880227182893683, -1.055311640905049, -0.8402985887604386, + -0.5147673021596371, + ], + "value": 20648.21331175137, + "opg_hessian_ratio": (0.8582, 1.166), + "other_local_optima": False, + }, + "multinomial_logit_46": { + "params": [ + 0.49629237145198785, -0.38221959996469446, 0.6176055394759373, + -0.5091366199397312, -0.16097321309786541, -0.1795878581361014, + 0.12951394420857282, -0.3256414949927389, 0.08776476561292712, + 0.09839159538536223, -0.2889724601525948, 0.16424911523602356, + -0.1664200628881164, -0.1877269830648816, 0.1874136037507413, + -0.17797723484574926, 0.16835613150433495, -0.05229863554627681, + -0.26152066567840915, 0.2256600438470295, -0.14890128797472854, + -0.037011160990159025, 0.2222052100485621, -0.310603701289676, + 0.15787712390647696, 0.07313897925661313, -0.1604651612151315, + 0.1943302099317803, -0.15757049132523873, -0.06540587360311517, + 0.0480891756470391, -0.2196780553526462, 0.22341450390595713, + -0.07014903322056298, -0.14047135628747895, 0.2492898153697439, + -0.2195468099256684, 0.1572437339620661, 0.13772779591330542, + -0.3003214328541772, 0.2179125913120918, -0.18234038377868172, + -0.040403745531645455, 0.20681905967796854, -0.18290618801060277, + 0.09897042671775849, + ], + "value": 8299.088481553177, + "opg_hessian_ratio": (0.8171, 1.233), + "other_local_optima": False, + }, + "multinomial_logit_123": { + "params": [ + 0.4572083875154383, -0.3493605516204454, 0.4895895274944006, + -0.4065948265098127, 0.2753766488405284, -0.48538488435612426, + 0.04176746595089382, 0.004717466574208833, 0.2308716965952382, + -0.11161515348776353, 0.03827698064909954, 0.11515430864559512, + -0.13895052323525778, 0.0915260547929821, 0.02455748227813933, + -0.14776532347444798, 0.11644599651337137, -0.03179214068992563, + -0.05739327076903635, -0.11903985035908907, 0.1693955615903375, + -0.016375625910212143, -0.055925262512274934, 0.1853645680166397, + -0.12847436010519822, 0.07090969940783154, 0.07608680798731703, + -0.16975528052170982, 0.09107632884822763, -0.06304904943157906, + -0.15828979302178983, 0.17807497587316895, 0.1866499912858609, + -0.008549638031434307, -0.07170165397934952, 0.1112918241512024, + -0.07351893704194958, 0.029431482752176944, 0.13156343886189178, + -0.2171797408230764, 0.08322577684226913, 0.12623705910414876, + -0.23410258841959733, 0.07370183639602691, 0.05315551203092063, + 0.10708366187001908, -0.12706852875224472, 0.18365344417940185, + -0.03134346919562918, -0.09019461089782847, 0.18139145924740863, + -0.1376510831875536, -0.06723838362304295, 0.2522007855703826, + -0.17782705474763294, 0.03009079579484575, 0.13468790262142413, + -0.24382803686376767, -0.0870843932945572, 0.09215648097050452, + 0.07145580838269534, -0.2073587177064712, 0.1341626913766777, + 0.022055662235980888, -0.021831151254660827, 0.08055797653752252, + 0.017181925189267106, 0.01888539235889234, 0.0979553967723266, + -0.15899388868799336, 0.03006409310435696, 0.03769272188532785, + 0.13967329295392672, -0.09375209783638662, 0.05061035172889837, + 0.06712315161808452, -0.12561979963363734, 0.0455011396837244, + 0.016106450327278782, -0.08027525559275459, 0.1660184947477186, + -0.1656119030276239, -0.04832765146231134, 0.16082584006117343, + 0.17808691609702448, -0.12464082001952874, -0.029389677760307546, + 0.158682490960157, -0.15577794215336185, 0.09583880181324991, + 0.10813808821826426, -0.1470998724046993, 0.17622015099300575, + -0.0186804109280704, -0.11829531539011232, 0.2265036494156579, + -0.09701181089750548, 0.05109680900066963, -0.11588662416669102, + 0.23086965062349876, -0.07867594860243748, -0.09760403063082546, + 0.2119650024806446, -0.09845474822627724, 0.09369822685352691, + 0.14208434987220372, -0.1740381079610329, 0.06162553668498414, + -0.008827242593732356, -0.1622321858973548, -0.17827599852885095, + 0.06821453329120092, 0.05879206554873138, -0.18080122039013088, + 0.13463514996915588, -0.007970189893527609, -0.08982073025049522, + 0.17052310623222292, -0.07324207016047089, 0.0006837922105374807, + 0.046043364823478455, -0.1886840105236823, 0.15904749930488996, + ], + "value": 14826.940303544514, + "opg_hessian_ratio": (0.7744, 1.283), + "other_local_optima": False, + }, + "weibull_31": { + "params": [ + -0.5172234834697079, 0.08741822506968396, -0.09622279944370649, + 0.1337436019004008, -0.09860733448072859, 0.08542006585023781, + -0.1308066283043519, 0.09672298490157785, -0.10603269692661871, + 0.1038213719308791, -0.05887886785729315, 0.11506781534679533, + -0.07832133907893815, 0.06430692217934131, -0.08519230011788109, + 0.07007035077994118, -0.10495156890707359, 0.08080288737645858, + -0.09350681107940118, 0.1034793342829815, -0.07497217158038258, + 0.12656554949357113, -0.07471125059832373, 0.07013473859314442, + -0.08653443734332021, 0.05976916575840718, -0.05099371241862547, + 0.1005474890371523, -0.06136065891019267, 0.0891710045392443, + 0.4027629757289833, + ], + "value": 7196.947567644667, + "opg_hessian_ratio": (0.8277, 1.217), + "other_local_optima": False, + }, + "gamma_regression_41": { + "params": [ + 0.9867875377500296, 0.09279179781196213, -0.06793732537529695, + 0.08752795544337671, -0.07168563523625472, 0.06109358220465388, + -0.08634692155206372, 0.08906250556709075, -0.10707699224009894, + 0.08261732402996534, -0.05363930401805012, 0.11935418875293909, + -0.07327045168468256, 0.050847764469981294, -0.08709695529689722, + 0.0711290296068788, -0.10993335784712378, 0.08679861258234071, + -0.07058299904674273, 0.0871101429100295, -0.07633769253686859, + 0.10761274202414832, -0.07754562230952694, 0.07126009069239377, + -0.10478544471512673, 0.07286166729247372, -0.052164493597597686, + 0.09640189269430058, -0.0775710261772508, 0.1025641213108591, + -0.07240772324529608, 0.07396170641408654, -0.103435628257295, + 0.0701856378750674, -0.05322041371841254, 0.09181531345415847, + -0.06403689173373273, 0.10405944474732805, -0.06393433382455121, + 0.05683476517632284, 0.6887608988200565, + ], + "value": 18668.921084937676, + "opg_hessian_ratio": (0.8227, 1.291), + "other_local_optima": False, + }, + "multivariate_normal_44": { + "params": [ + -2.005956610537808, -1.433902151559599, -0.8334474687398474, + -0.30315301741339135, 0.26984062520293006, 0.860951075073135, + 1.4100139742478608, 1.9860235972619888, -0.6944073037731463, + -0.35767161126651104, -0.22789391917847227, 0.20935810610696348, + -0.4904477899039642, 0.0944130031033036, -0.12396933301157714, + 0.23872349802727616, -0.5992442897365057, 0.3615010165174144, + 0.04567634303919237, -0.12400534899592638, 0.34113566360835984, + -0.6985736028609489, 0.5677916523893312, 0.007339471456327559, + 0.11246844112788541, -0.14180762142322248, 0.2712113588719838, + -0.8192206238829771, 0.7281019968624401, 0.10044195836809106, + -0.09940332683478009, 0.08541646010329355, -0.18765564277111355, + 0.3172139381788259, -0.9566247273618911, 0.8759899954578018, + -0.12425167402313808, 0.06401687073509836, 0.005249903682941802, + 0.026551035871315985, -0.11198097243765572, 0.40505965733054433, + -1.130595365056289, 1.00938378551122, + ], + "value": 42199.16547758182, + "opg_hessian_ratio": (0.7582, 1.325), + "other_local_optima": False, + }, + "multivariate_normal_90": { + "params": [ + -2.0127348815563417, -1.6165646925445678, -1.28948572723869, + -0.8706807188360133, -0.5630135860735589, -0.1812555828826948, + 0.17418905874315202, 0.5351276720826347, 0.9210835543754728, + 1.2954514444557998, 1.6361564432472766, 2.0457219828700137, + -0.6893141881325582, -0.2950568438994257, -0.38694642004313884, + 0.16381996668925716, -0.3649246384849414, -0.13360647388792382, + -0.06812750590461822, 0.19130651168585364, -0.4223477466703764, + 0.08504788602767721, 0.06635684221991445, -0.07636954766727233, + 0.20320334589139852, -0.4944014340173745, 0.2421042668699728, + -0.01696529669656969, 0.05213692068750385, -0.04566789539333954, + 0.2205695963796957, -0.6253701771419325, 0.40373298288201653, + 0.035573432900638184, -0.00915990417198743, 0.04381117620762136, + -0.10901857719664577, 0.2652482289637847, -0.6836218113679917, + 0.5189518191984396, -0.03126079377174816, -0.02581184485593057, + 0.03317909994765022, 0.0151336149352598, -0.14770438609114794, + 0.32635852898079737, -0.8099162858196612, 0.6457432589618237, + 0.06787819883322914, 0.1409279295583627, -0.06111740339962745, + -0.015537215024953342, 0.11347807931234605, -0.1803568582186102, + 0.34477504851473434, -0.8637977584679996, 0.7553396736336946, + -0.001425751498261194, -0.0798631881569699, 0.03123530929012241, + -0.019663968881696376, -0.05048799219489686, 0.06186427265048931, + -0.18119447148297513, 0.3944133960535315, -0.9508901909187095, + 0.8490214468092505, -0.03642593059187491, 0.05537769330273958, + -0.0690869216389315, 0.03300637097504645, 0.0881177266813018, + -0.028509503701560017, 0.09096455096519362, -0.22100602304599998, + 0.4177936309948682, -0.944375884689938, 0.9319798257834069, + 0.02484834631187907, -0.0615410222208161, 0.031138858709298747, + -0.05977892270525717, -0.10059241611205949, 0.08408544027733035, + -0.02312146184123312, 0.09287588851257, -0.20028307471960316, + 0.3896998832211693, -1.135255258482609, 1.0045770593231054, + ], + "value": 106269.4676794092, + "opg_hessian_ratio": (0.7466, 1.323), + "other_local_optima": False, + }, + "multivariate_normal_135": { + "params": [ + -2.0039870753041735, -1.6966640112570017, -1.4270108381816615, + -1.1439805667247331, -0.8455539548459048, -0.5614048850386422, + -0.2903714256671946, 0.06155609032383358, 0.22650388085657638, + 0.6023040477004533, 0.844570105426121, 1.1291165627086974, + 1.4436196520371518, 1.6874141514362533, 2.024632171485009, + -0.6785559037489709, -0.27020900114261676, -0.48393391326532575, + 0.1325315652751993, -0.3198229036061577, -0.24490370839171366, + -0.06811421977099415, 0.14356419116348645, -0.37934127807033385, + -0.04189006601546444, 0.03110490746545246, -0.05263949927952185, + 0.17605407922145894, -0.4604874189730499, 0.10406733063709547, + 0.00653548000961182, 0.024885120317974758, -0.07806091285988584, + 0.19754899439331436, -0.5087142763361155, 0.22513452905818848, + -0.028394921962665444, -0.03718743765506444, 0.005149333003916609, + -0.08798033759513021, 0.21557072133671495, -0.5598342443860869, + 0.3734245066926002, -0.02162727200108963, 0.020994488462503944, + -0.05694505309106078, 0.009092765939461537, -0.08604186194147778, + 0.2598731220876813, -0.7156533119768103, 0.4783774292522795, + 0.021865377255031532, -0.016113410543023496, -0.005603389046551969, + 0.01663879450714723, 0.06624807858216779, -0.08310400091941172, + 0.32163751590223266, -0.7354312421284969, 0.5673078654813221, + -0.033015268322742354, 0.0007177692855937789, -0.008945268765052269, + -0.04044781453812439, -0.05367763972133643, 0.04468106577615626, + -0.13173498657389776, 0.30727825950548704, -0.8000417796666395, + 0.6556894995044373, 0.04781952831720248, 0.05526723309858258, + -0.03723487627829149, 0.021369124251549777, 0.05734010754624974, + 0.01737471154787788, -0.006207004499440197, -0.08965082746867992, + 0.3440990986911599, -0.8145959876066562, 0.7439366891410717, + -0.0336312104875003, -0.05256619667408278, 0.025161790625077285, + -0.02589789002295005, -0.022486623517844948, -0.014888735921292666, + -0.001838644406540634, 0.046314566359989214, -0.18954442171116048, + 0.31235829809064, -0.9107859590112608, 0.8321500278463417, + 0.016431799776422923, -0.03464175200078189, -0.047853829953330644, + 0.029641941934429875, -0.016799015441567342, -0.06499477640343586, + 0.030179571240589377, -0.00046730235229998807, 0.1535806336392964, + -0.1833120120297661, 0.4114649654115697, -0.9501726363157257, + 0.8801152469568535, -0.04454677487784459, -0.04270572176102477, + -0.015539356356560015, -0.041738316744053566, -0.012430654980027324, + 0.06791148803654562, -0.04550432661849048, 0.028047607576106033, + -0.0632763687691345, 0.0398379960159465, -0.16797895602111218, + 0.3804940387344799, -1.032716238366089, 0.9510588797242905, + 0.023255757079253057, 0.07260972878601274, 0.029175386401720512, + 0.08156408424882743, 0.055919681026306546, 0.02163505614623318, + 0.056836280271154324, -0.010395641347978815, 0.035416082511804996, + 0.00364860972639485, 0.09094811147759971, -0.17927991787977168, + 0.41484465740710497, -1.1124196296654338, 1.017207680349342, + ], + "value": 133316.3204564622, + "opg_hessian_ratio": (0.676, 1.4), + "other_local_optima": False, + }, + "fixed_effects_poisson_110": { + "params": [ + 0.17461045296728067, -0.12991366166945612, 0.19420470197277817, + -0.12045762313608939, 0.10900512961311497, -0.17908331838319386, + 0.12411514918406703, -0.18963918424985704, 0.15115786925557825, + -0.11729969536637551, 2.010585917257369, 1.9862972866223194, + 1.4004255103123806, 1.334919459268999, 1.4652092084351558, + 1.2060200161759007, 1.6446247385940576, 1.874822325916081, + 1.5535786352453334, 1.8054532832928847, 0.9665391206031289, + 1.7604915379289856, 1.6274439353156183, 1.4639236342364155, + 1.3849479995225464, 1.6104646734152324, 1.4802896352803065, + 1.647410692277508, 1.7981766617490662, 1.660110420629287, + 2.1766748547578603, 1.8472152369348496, 1.4760230240387642, + 1.0315074968774578, 1.6111189406341127, 1.4756254473507808, + 1.6764364200663213, 1.7700682322132644, 1.2440080603118788, + 1.730257272767048, 1.300507639751866, 1.700206360406955, + 1.3419972341033233, 1.748830444148572, 1.806496501720302, + 1.501706308344075, 1.9660478023249441, 1.2379208803460817, + 1.7952337718849198, 1.5232377555436147, 1.3994509895464284, + 1.1970226998536821, 1.8786355648385424, 1.4862914021792246, + 1.4655340865358504, 0.8738494014973305, 1.138700478386265, + 1.6963514013791166, 1.980207112958209, 1.3043021924429283, + 1.2254956205659961, 1.2389987069096033, 2.231854858476964, + 1.4274596879143693, 1.8851404575693895, 0.5600491404672587, + 1.5904070018380483, 1.1602488905306203, 1.4278527947313828, + 1.6352491020890345, 1.664364114498812, 1.5965469124162948, + 1.637424962640378, 1.2518939000452134, 1.6910273642247453, + 1.480736406522893, 1.4078534997964545, 1.940338140935199, + 1.6652527879953816, 1.5983653965446878, 0.9423956903289361, + 1.5506276587273877, 1.8513505885451862, 1.5413131032962681, + 1.6911458650422915, 1.113808693095111, 1.6783446885672042, + 1.5795056613693639, 1.1941897769259768, 1.146861995962262, + 1.645242813828544, 1.6567327350356755, 1.7284575986705621, + 1.7102298220410812, 0.7327591037032151, 1.84857238257614, + 1.639856632024075, 1.614214548921748, 1.6458144764856995, + 1.5990373566397653, 1.5643451500184324, 1.226817542072216, + 1.798137216524897, 1.2325540933826131, 1.5427289435647569, + 1.1348551196258314, 1.6086155788574832, 1.3460690001716251, + 1.247286770860654, 1.8104098640354525, + ], + "value": 4224.534488001875, + "opg_hessian_ratio": (0.32, 1.996), + "other_local_optima": False, + }, + "fixed_effects_poisson_150": { + "params": [ + 0.15958793223323267, -0.10734217826108623, 0.19261472340008648, + -0.13452832506239917, 0.11545312824536079, -0.17438984160829268, + 0.14204864181776708, -0.2127504341033872, 0.13039804458118462, + -0.11243193231348093, 1.7536927501818376, 1.5759230558834416, + 1.822632172665657, 1.2728361441736957, 1.5625591906357783, + 0.824076574216289, 1.595915208974415, 0.5904542829634322, + 1.5178120075395938, 2.1592393764482845, 1.0110291613730575, + 1.8974341696682608, 1.3932902900949555, 1.567927802387566, + 1.5371110470837115, 1.5009040711270598, 0.8581319705288859, + 0.9893150166572244, 1.097943349773817, 2.0145272916252646, + 1.5569803865787337, 1.1429895946002764, 1.5378783482214917, + 1.008128855421298, 2.3561511734788687, 1.537224463715902, + 1.4725047900285453, 1.4514736726457795, 2.026137386737073, + 1.9205031270476267, 1.0749688229443681, 1.1973171844021926, + 1.8765368826098112, 1.5817228545939952, 1.0776714233559965, + 1.7704844731292513, 1.8083677404976675, 1.5925487002847378, + 1.6202485485917248, 1.5314605598569193, 1.4843523337623614, + 1.602343412978252, 1.3963241807813085, 1.4593504009608838, + 1.329576196222217, 1.4831550181611965, 1.7312761154005698, + 1.132757395343084, 1.5699535076705016, 0.6396989449417797, + 1.432679662174445, 1.2129597986135097, 1.9039401894331707, + 0.9140631957511769, 1.0131670130604327, 1.734204995320881, + 1.2939081941687691, 1.2905545851646947, 1.430027949004896, + 1.8890654576664843, 1.6606989870784374, 1.4466507404168325, + 1.606806112561126, 1.4539688233190846, 1.4928066716911987, + 1.4911559724496593, 1.7593293233304466, 1.1412075507860306, + 1.486274836689961, 0.9759145727957157, 1.764914340045078, + 1.8865902446569216, 1.7265612187607322, 1.258896013957737, + 1.180292755278458, 1.788922958135007, 1.7461578930313468, + 1.5322125400987237, 1.568690644312637, 1.2957019630173796, + 1.3750053494606205, 1.1646342773633316, 2.1004017093126595, + 0.8400756345150086, 1.8013033453202205, 1.2240617603213, + 1.2976233104167376, 1.2457401773097834, 1.3886428798559705, + 1.8140616979161248, 1.6294224683460838, 1.8052729085529453, + 1.4022682809716556, 0.8325993787050728, 1.5014723272558659, + 2.4437814876953605, 1.6969103205337732, 1.3068314235270553, + 1.3717793142015051, 1.8307577029488364, 1.4698851244107909, + 1.8719359140902616, 1.3417250076608886, 1.2324518162060885, + 1.6546304200793667, 0.7567285676418795, 0.6425031648697954, + 0.7937165151703247, 1.0584053919251686, 1.4303300450040737, + 1.9980699960638684, 1.579976720901204, 1.8027247628123912, + 1.755360182873413, 1.1643124164382062, 0.7799897466515235, + 1.653844590389738, 1.272113883204332, 1.5903653340580282, + 1.8266535443028529, 1.663851687770312, 1.3554643421820503, + 1.8650381264373173, 1.38332281268343, 1.2300442882517026, + 1.703581086154592, 1.909718056208262, 2.1767912480383442, + 1.3491258186048303, 2.150616386322035, 1.6952002603963796, + 1.7947103599661414, 1.6055787478701704, 1.0361712159944836, + 1.6222262310574047, 1.220077920422991, 2.0957712221598372, + 1.507978218221442, 1.3581771185858975, 1.9195420843451427, + ], + "value": 2864.2776844911346, + "opg_hessian_ratio": (0.1053, 2.489), + "other_local_optima": False, + }, + "random_effects_probit_41": { + "params": [ + -0.3118844636706948, 0.1799950982141516, -0.11308901092874377, + 0.2099575721170857, -0.16669642410453497, 0.1065079440381684, + -0.1893100938720093, 0.13146852665051265, -0.20810680625734349, + 0.1610104321107868, -0.10759105597755564, 0.22413952306035279, + -0.15871307554476177, 0.11741925113754975, -0.17609048046005432, + 0.1486654305457967, -0.21984289590102332, 0.1583223544874345, + -0.15506773121661827, 0.20513071460824733, -0.15927850521487913, + 0.2218591310323383, -0.21241277150881455, 0.1259709105162344, + -0.20263080636231776, 0.18077742383366924, -0.11670110001671419, + 0.15295127971155364, -0.11264704563260412, 0.22146167143614154, + -0.18595400244892493, 0.12240126975826857, -0.19184153949868699, + 0.14512712683507853, -0.09133614587656716, 0.20274456957584588, + -0.12457387042111571, 0.21921461207002785, -0.15044814040178534, + 0.1151491980517608, 0.03377094051330394, + ], + "value": 5040.023123141813, + "opg_hessian_ratio": (0.752, 1.334), + "other_local_optima": False, + }, + "mixed_logit_correlated_26": { + "params": [ + 0.40039922015576573, -0.24875881409775402, 0.46815158048901756, + -0.3312727439173431, 0.26458930017477067, -0.414219673358871, + 0.9119825705548563, 1.0648299588143952, 1.3566883111625136, + 1.5943319895875196, 1.8387448196969507, 0.7151688487875243, + 0.2037350454018401, 0.5919090197818532, 0.06407820751710991, + 0.15971947223195668, 0.5161890943828867, 0.025853145411752567, + -0.024372770291266544, 0.18248306151550192, 0.3070146880446944, + -0.04743643306078221, -0.001169418346972499, 0.008824879674394595, + -0.14306998857981593, 0.09622505278310987, + ], + "value": 6024.264892946753, + "opg_hessian_ratio": (0.7879, 4.48), + "other_local_optima": True, + }, + "heckman_37": { + "params": [ + 0.30466413079709237, 0.26176346749742047, -0.17870069234870592, + 0.22142766723464827, -0.28794819376864267, 0.19212800871913727, + -0.24317527019353902, 0.153754432974183, -0.2173489493585374, + 0.27825577750948505, -0.17458111507561797, 0.2380133315005556, + -0.2969720478356726, 0.200931370470354, -0.2578322029231351, + 0.17111585709666507, -0.21766728173376, 0.27915250453497925, + -0.19155692337700622, 0.2472840519245545, 1.0129160213272008, + 0.28037263783248895, -0.20766440009210288, 0.313921129085566, + -0.2473999451365472, 0.1945495025527436, -0.30573876447715054, + 0.22890890099859698, -0.320571693664258, 0.2708773039966251, + -0.2109291502821516, 0.3231253111762022, -0.26960095024203307, + 0.17108244315425364, -0.29777815995620965, 0.18670757030747603, + 0.5269240536261414, + ], + "value": 41839.26200453838, + "opg_hessian_ratio": (0.9037, 1.103), + "other_local_optima": False, + }, + "zero_inflated_poisson_45": { + "params": [ + -1.043272122620468, 0.087614306533158, -0.06041211979400049, + 0.14715901644610266, -0.051708471227425716, 0.03724463405600048, + -0.10982599380954856, 0.06306783426062504, -0.17861182473828882, + 0.11260238969610677, -0.08023599134529824, 0.12559279899836132, + -0.0514042671266749, 0.08003212028229138, -0.11637615978679479, + 0.10521764627898642, -0.11400403731617366, 0.05764806289654686, + -0.07426030405613697, 0.06913782018323995, 0.9862644163971834, + -0.09605434087701287, 0.05912218597648617, -0.09632831327919261, + 0.11975651724825888, -0.06278966170046527, 0.09936141887154658, + -0.06246211686061501, 0.07621955481284312, -0.10453298246879016, + 0.06833230789859211, -0.09942058180836923, 0.06613216832125665, + -0.06825331742171939, 0.08173799725490612, -0.06926022933951387, + 0.08041991149700115, -0.11879377620319855, 0.05981164790832395, + -0.08900894936363837, 0.0624117571109452, -0.07847493955675967, + 0.1037963077880874, -0.06420795577517523, 0.08547498788207775, + ], + "value": 17871.05715802158, + "opg_hessian_ratio": (0.8074, 1.186), + "other_local_optima": False, + }, + "stochastic_frontier_32": { + "params": [ + 1.0026469568414023, 0.09523995447360407, -0.06981999934151649, + 0.11127386576866333, -0.07758293296998767, 0.05523414794701913, + -0.09536854436169552, 0.06622860859913389, -0.13682814084549502, + 0.0995112639263207, -0.07818712806336271, 0.10602988234923968, + -0.08777585974997404, 0.07873271448652774, -0.10244902714550003, + 0.07390894518162347, -0.12170575261039357, 0.08411141666799357, + -0.06429861256301274, 0.11111844021715722, -0.0807252876168975, + 0.12417966445713946, -0.10396614673408623, 0.0774462026688534, + -0.11655851925379809, 0.09054063928919767, -0.0557461577203752, + 0.08792666592262702, -0.08170412645323293, 0.11641095591298123, + -0.6980007719597809, 1.009116183467453, + ], + "value": 11600.592306432323, + "opg_hessian_ratio": (0.8543, 1.17), + "other_local_optima": False, + }, + "poisson_overdispersed_tiny_5": { + "params": [ + 0.9736572007610079, 0.26043474697596186, -0.21360495312923597, + 0.3093944106242701, -0.2190765770772529, + ], + "value": 5843.056106300912, + "opg_hessian_ratio": (1.138, 1.315), + "other_local_optima": False, + }, + "poisson_overdispersed_moderate_5": { + "params": [ + 0.9807101577112516, 0.26846986610241796, -0.19062335934238472, + 0.31337295940992854, -0.21557983263348934, + ], + "value": 6698.7101011092, + "opg_hessian_ratio": (1.752, 2.278), + "other_local_optima": False, + }, + "poisson_overdispersed_severe_5": { + "params": [ + 0.9840499651546615, 0.27026267625901457, -0.19434324859747407, + 0.280335677646997, -0.23693110889250876, + ], + "value": 9016.946299942478, + "opg_hessian_ratio": (4.001, 5.792), + "other_local_optima": False, + }, + "poisson_underdispersed_moderate_5": { + "params": [ + 0.9972629853762501, 0.2655170128104427, -0.20349729128056868, + 0.29870773048759536, -0.2379697821594156, + ], + "value": 5148.426081219831, + "opg_hessian_ratio": (0.5623, 0.6546), + "other_local_optima": False, + }, + "poisson_underdispersed_severe_5": { + "params": [ + 0.9982866878575201, 0.25643824834880136, -0.19760193483201582, + 0.28940167701722613, -0.23776177699419487, + ], + "value": 4811.534833082063, + "opg_hessian_ratio": (0.3205, 0.3664), + "other_local_optima": False, + }, + "regression_t_errors_tiny_5": { + "params": [ + 2.0152850553148256, 0.6117273066489715, -0.4792029713392593, + 0.6191612500966241, 0.0045098122689477904, + ], + "value": 2846.896690947241, + "opg_hessian_ratio": (0.9026, 1.174), + "other_local_optima": False, + }, + "regression_t_errors_moderate_5": { + "params": [ + 2.0236815616820882, 0.5777504560340379, -0.42210719210459363, + 0.6749716743829576, -0.014539791247027197, + ], + "value": 2808.7974839152907, + "opg_hessian_ratio": (0.8806, 2.528), + "other_local_optima": False, + }, + "regression_t_errors_severe_5": { + "params": [ + 2.011372280345389, 0.5551300152613218, -0.4469736788099263, + 0.6299987350485285, -0.044374803523700886, + ], + "value": 2749.1274593619437, + "opg_hessian_ratio": (0.7744, 14.72), + "other_local_optima": False, + }, + "regression_ignored_heteroskedasticity_mild_6": { + "params": [ + 1.988202366203761, 0.5109279851271986, -0.4325494959888329, + 0.5810842454005202, -0.48471598069904814, 0.12870112319672, + ], + "value": 3095.279312802785, + "opg_hessian_ratio": (0.5142, 1.757), + "other_local_optima": False, + }, + "regression_ignored_heteroskedasticity_severe_6": { + "params": [ + 1.9435973240095246, 0.3049692911607376, -0.35952304090258064, + 0.6064823004374608, -0.46354566190652335, 1.0717019753351045, + ], + "value": 4981.281017079555, + "opg_hessian_ratio": (0.1191, 88.98), + "other_local_optima": False, + }, + "logit_probit_data_tiny_6": { + "params": [ + 0.48189083576828534, 1.3021298435209863, -0.9152665854309928, + 1.4274745922144108, -1.0512185535674023, 0.9645721655188754, + ], + "value": 1158.1551220381716, + "opg_hessian_ratio": (0.8648, 1.099), + "other_local_optima": False, + }, + "logit_misclassified_mild_6": { + "params": [ + 0.29236721616159755, 0.6923618405846902, -0.5943863062792168, + 0.8390058249576143, -0.6724989087996314, 0.5007912355760934, + ], + "value": 1566.4608214364043, + "opg_hessian_ratio": (0.9564, 1.072), + "other_local_optima": False, + }, + "logit_misclassified_moderate_6": { + "params": [ + 0.19482602448137087, 0.4856013565843911, -0.3372948538733999, + 0.5611830175694638, -0.4313160958433035, 0.3461688614026828, + ], + "value": 1798.8304061207418, + "opg_hessian_ratio": (0.9264, 1.103), + "other_local_optima": False, + }, + "logit_misclassified_severe_6": { + "params": [ + 0.11257596173724589, 0.2556892027696122, -0.21000940480177327, + 0.37282569163067664, -0.29000120537592966, 0.18520965230071637, + ], + "value": 1953.6624078348923, + "opg_hessian_ratio": (0.9504, 1.102), + "other_local_optima": False, + }, + "probit_heteroskedastic_moderate_8": { + "params": [ + 0.1753701757668437, 0.28907132746037023, -0.3320820283715438, + 0.41748217032924295, -0.28473113276802015, 0.2965064573017825, + -0.3888779588297129, 0.34091736684790724, + ], + "value": 1552.0701380979172, + "opg_hessian_ratio": (0.7738, 1.354), + "other_local_optima": False, + }, + "logit_sign_restricted_moderate_8": { + "params": [ + 0.28479489057788376, 0.4554533618702854, -0.2925294541110059, + 0.4412578810803375, 0.0, 0.31646014582275095, + 0.0, 0.31601160921373794, + ], + "value": 1842.3465209581668, + "opg_hessian_ratio": (0.9411, 1.03), + "other_local_optima": False, + }, + "multinomial_logit_nested_mild_11": { + "params": [ + 0.8515828885526794, -0.6585967648880279, -0.17333940329601955, + -0.15670196506358397, 0.35924400544382257, -0.3356472805452971, + 0.23059710036774994, -0.1798485321422207, 0.17730314133200345, + -0.1384489434095102, -0.31105849099835226, + ], + "value": 2119.47157837107, + "opg_hessian_ratio": (0.8752, 1.161), + "other_local_optima": False, + }, + "multinomial_logit_nested_severe_14": { + "params": [ + 1.1574782292959227, -0.8860645045433257, -0.5234476088719588, + -0.21713245172713028, 0.6277127303102409, -0.6733989730058455, + 0.48807763338259735, -0.251176837820181, -0.055224164898937556, + 0.034266092180741795, -0.5298064398864459, -0.07557799198043645, + -0.5461961599972366, 0.3539991310316214, + ], + "value": 2091.0122013039945, + "opg_hessian_ratio": (0.7251, 1.244), + "other_local_optima": False, + }, + "weibull_frailty_mild_5": { + "params": [ + -0.6322291131394027, 0.23204841951133648, -0.22819199711236754, + 0.34414644905137287, 0.3255741306189334, + ], + "value": 1567.5052171265618, + "opg_hessian_ratio": (0.8607, 1.382), + "other_local_optima": False, + }, + "weibull_frailty_severe_5": { + "params": [ + -0.8898399209385071, 0.19514379377057917, -0.15248074367294334, + 0.28940286704295876, 0.08339757182007448, + ], + "value": 1939.8224367639627, + "opg_hessian_ratio": (0.7213, 1.363), + "other_local_optima": False, + }, + "garch_t_innovations_moderate_3": { + "params": [ + 0.053442507098345214, 0.07631254177799343, 0.9034811378521146, + ], + "value": 5431.499096382653, + "opg_hessian_ratio": (1.53, 1.964), + "other_local_optima": False, + }, + "garch_t_innovations_severe_3": { + "params": [ + 0.052719744797538985, 0.11132604337148552, 0.876323474051414, + ], + "value": 5486.970761494409, + "opg_hessian_ratio": (2.252, 4.383), + "other_local_optima": False, + }, + "multivariate_normal_t_data_tiny_9": { + "params": [ + -2.0298253311034857, 0.08968464613828447, 1.863318484739278, + -0.6937984679701128, -0.6904320618800782, 0.4482841290043616, + 0.5289625281304946, -1.0432704253672043, 1.0206917970850913, + ], + "value": 10063.98611546672, + "opg_hessian_ratio": (0.8743, 1.267), + "other_local_optima": False, + }, + "multivariate_normal_t_data_moderate_14": { + "params": [ + -1.9685961758446564, -0.6815521682709477, 0.6477770274115896, + 1.9265073854657087, -0.7111972849063172, -0.5366750839831212, + 0.16752599298232776, 0.31180567262691233, -0.7621688537950762, + 0.6382118808660033, -0.2217072532141754, 0.4646594819755998, + -1.0418966612369203, 0.9832592767634, + ], + "value": 13507.10799704822, + "opg_hessian_ratio": (0.926, 2.982), + "other_local_optima": False, + }, + "multivariate_normal_t_data_severe_20": { + "params": [ + -2.0085079727236907, -0.9786288170038896, -0.01714699257850159, + 1.0250280511603418, 1.9680980642731936, -0.6744751406555634, + -0.48168370486805595, 0.06522615201792527, 0.29641536109316946, + -0.5945922277921697, 0.406188235907865, -0.07397700895460467, + 0.31116772811124305, -0.7524550778708178, 0.8000957215085379, + 0.17912335485301403, -0.08406288590870717, 0.2983711975449253, + -0.99527449080902, 1.0273626230721535, + ], + "value": 17438.180515748572, + "opg_hessian_ratio": (0.8585, 8.35), + "other_local_optima": False, + }, + "normal_mixture_three_components_severe_5": { + "params": [ + -1.3223513571362606, 1.9956409675756266, -0.01510855358262942, + -0.016497966003717206, 0.13780482211009226, + ], + "value": 1962.722152398084, + "opg_hessian_ratio": (0.4462, 10.53), + "other_local_optima": False, + }, + "ordered_probit_logistic_errors_mild_8": { + "params": [ + 0.5160858161165569, -0.3863096599240573, 0.5651254335304468, + -0.4999161264041742, -1.3270813685464713, -0.12961808879202175, + -0.22351829437844556, -0.2201168505861023, + ], + "value": 2629.169357980522, + "opg_hessian_ratio": (0.9173, 1.308), + "other_local_optima": False, + }, + "ordered_probit_skewed_errors_moderate_8": { + "params": [ + 0.5257065546280212, -0.3879713431910795, 0.6227881985389596, + -0.489984509699899, -1.2577939247126035, -0.07450977864930898, + -0.20958505624435358, -0.2569786879738006, + ], + "value": 2564.9403292125, + "opg_hessian_ratio": (0.6959, 1.487), + "other_local_optima": False, + }, + "tobit_heteroskedastic_moderate_6": { + "params": [ + 0.3466497348877695, 0.7940666829359763, -0.42147143071422055, + 0.6563684027071714, -0.43156150416364547, 0.6392943850924159, + ], + "value": 2967.6077024906585, + "opg_hessian_ratio": (0.5433, 2.541), + "other_local_optima": False, + }, + "tobit_t_errors_severe_6": { + "params": [ + 0.4808113982612859, 0.5677448255144448, -0.38191128881041536, + 0.6498903049374082, -0.4469828875276664, 0.3835649943394483, + ], + "value": 2750.117489696088, + "opg_hessian_ratio": (0.8388, 3.091), + "other_local_optima": False, + }, + "gamma_regression_lognormal_data_moderate_6": { + "params": [ + 1.0022474633636604, 0.2663650262587376, -0.20100960587505345, + 0.3322805020887824, -0.2290974376437324, 0.9755892966976635, + ], + "value": 3586.3398808871534, + "opg_hessian_ratio": (0.7287, 2.098), + "other_local_optima": False, + }, + "random_effects_probit_bimodal_effects_moderate_6": { + "params": [ + -0.19715907194794616, 0.48995486978244185, -0.40689753381522853, + 0.55116038781658, -0.5478024277379463, 0.030648096533594713, + ], + "value": 1300.7532101021002, + "opg_hessian_ratio": (0.8312, 1.133), + "other_local_optima": False, + }, + "zero_inflated_poisson_negbin_data_moderate_8": { + "params": [ + -1.4067912992551994, 0.3442194482731368, -0.4425432157429308, + 1.2346146863450098, -0.1444024491707536, 0.1375993348492345, + -0.1348797382225202, 0.1736732270859637, + ], + "value": 4713.411302159964, + "opg_hessian_ratio": (0.9376, 3.379), + "other_local_optima": False, + }, + "heckman_t_errors_severe_10": { + "params": [ + 0.3435852196972786, -0.5641158584656712, 0.6999027413042428, + -0.3935948778584863, 0.6313893328085373, 0.9122649696752209, + 0.808378707944127, -0.584060193639549, 0.16699213677993333, + 0.699214963685038, + ], + "value": 2671.6176738978506, + "opg_hessian_ratio": (0.6871, 5.103), + "other_local_optima": False, + }, + "stochastic_frontier_wrong_skew_severe_6": { + "params": [ + 1.7714899400030453, 0.3045527706545851, -0.22456920539441302, + 0.35100049192528565, -0.22930883831576318, 0.0, + ], + "value": 2379.259389777819, + "opg_hessian_ratio": (0.6656, 1.405), + "other_local_optima": False, + }, + "mixed_logit_lognormal_coefficients_moderate_8": { + "params": [ + 0.8392209696791213, -0.6350023512442884, 0.9600963547142585, + 1.4676450995794792, 1.8988711606695587, 0.6156615713262266, + 0.4370155045044596, 0.0, + ], + "value": 1214.3852572304354, + "opg_hessian_ratio": (0.7856, 1.382), + "other_local_optima": False, + }, + "poisson_overdispersed_tiny_40": { + "params": [ + 0.9894850188641124, 0.0822237032240797, -0.07001650058780082, + 0.10182475990703631, -0.07125355532995853, 0.06084093192354098, + -0.07912991622779564, 0.057461914833234276, -0.10776904245068143, + 0.0844512184875239, -0.06286717114631428, 0.0905238760292715, + -0.07059311125758182, 0.04785348919805061, -0.08772993033314867, + 0.06442429781868332, -0.09836362414729137, 0.07319427491543261, + -0.06333308537884025, 0.0879545423121823, -0.07300379246848845, + 0.10658069913021834, -0.09156834125606596, 0.060716997758619204, + -0.09711208541954325, 0.08695148304638443, -0.06630404610395452, + 0.08729416753959693, -0.06800421058333213, 0.09401448735758283, + -0.07524177787161783, 0.07041998691154613, -0.09138615140318997, + 0.08275686398846088, -0.06370969063645951, 0.09152347980881957, + -0.04974882930279159, 0.09011686232859396, -0.07806849953875925, + 0.06123748729729384, + ], + "value": 19307.800975681486, + "opg_hessian_ratio": (0.9571, 1.482), + "other_local_optima": False, + }, + "poisson_overdispersed_severe_40": { + "params": [ + 0.9978260357115128, 0.08691715532287154, -0.06917075302417379, + 0.09361917377703473, -0.08549447999267658, 0.05957373070611095, + -0.09186725433271861, 0.0686963333770509, -0.10464121678232297, + 0.08711453193610348, -0.08090396094497859, 0.09765400452776303, + -0.06387084095928264, 0.059037424566815835, -0.08369858806593161, + 0.06455536408933871, -0.09982835372091478, 0.08487693893252073, + -0.058567172716853654, 0.09814981573448561, -0.08073517550153884, + 0.1068638577711716, -0.0781717771950914, 0.05667567239637068, + -0.09568290534234414, 0.07506757092110261, -0.06149311769015914, + 0.09407668115458023, -0.07857948264906416, 0.10590305413826724, + -0.07117038917587196, 0.0491700644015771, -0.08985006728464805, + 0.0704249549408288, -0.05294720657672399, 0.0802114699700164, + -0.06651377556729746, 0.10448792802056651, -0.08042706858558163, + 0.06743740420947511, + ], + "value": 150276.20140709134, + "opg_hessian_ratio": (4.182, 5.982), + "other_local_optima": False, + }, + "poisson_underdispersed_severe_40": { + "params": [ + 1.0049781771131017, 0.08965824073519742, -0.06266572644092248, + 0.09496582022287152, -0.08064416122590161, 0.0528340645871421, + -0.08720940367568336, 0.06595104985305705, -0.10443261341174927, + 0.08638366286753163, -0.05858387944671865, 0.09009036687983268, + -0.07479335359310399, 0.047816848966588985, -0.08601402898149554, + 0.06780274855792413, -0.09757308557844405, 0.07132766209160779, + -0.05556049704471703, 0.09613452810269572, -0.06448628001987027, + 0.10676929817163863, -0.08208783531485177, 0.06514330247958246, + -0.0971839535243577, 0.07641412785893122, -0.0558335952894882, + 0.08737354933374177, -0.06728183191376487, 0.10640868170342006, + -0.07888467081051094, 0.05448522991907326, -0.09641225064734982, + 0.07391607294054567, -0.05580527741076876, 0.0817238170081395, + -0.06631251970032953, 0.09382902861626172, -0.08017776063219183, + 0.05532393226564048, + ], + "value": 16351.659616782807, + "opg_hessian_ratio": (0.3442, 0.492), + "other_local_optima": False, + }, + "regression_t_errors_moderate_61": { + "params": [ + 2.0084451405323085, 0.1509166586267164, -0.09707257931468109, + 0.15938665192612736, -0.1260262596867826, 0.0960810206782001, + -0.15634583265458574, 0.11268777539988012, -0.15098973267248525, + 0.11849143068254843, -0.12053334119209555, 0.1476954856997467, + -0.11971208957883597, 0.10819742916696679, -0.13599257758278901, + 0.1026081425110253, -0.15760448012684233, 0.11570419425841527, + -0.10362927638379055, 0.1430912526581923, -0.1255221127343027, + 0.17191333510649032, -0.14039270912232601, 0.08967052592009135, + -0.14133160039092912, 0.13285268051176763, -0.09628461765714807, + 0.1378010340176942, -0.09710342442790507, 0.1529338145072292, + -0.1234130748027985, 0.08622411638296776, -0.1559194334215047, + 0.1300653510717577, -0.09918152591856212, 0.14699533992704744, + -0.10662984397837579, 0.16764071746079204, -0.12108976548364786, + 0.08904429614792742, -0.14853017627662105, 0.11130032194951966, + -0.15486440049822714, 0.15505610021094599, -0.08214324054970223, + 0.15418074443055657, -0.12007021033464543, 0.08291375736897078, + -0.12629058780215727, 0.10228787598328264, -0.16797074928584124, + 0.1301326425416522, -0.08708330726301254, 0.14005902068053386, + -0.11450489370452324, 0.1698438516773031, -0.12557912369301413, + 0.09587832897828674, -0.15927908906091434, 0.1295061947865674, + -0.013762249568557539, + ], + "value": 14051.762836361151, + "opg_hessian_ratio": (0.7401, 2.791), + "other_local_optima": False, + }, + "regression_t_errors_severe_61": { + "params": [ + 2.0082384281255963, 0.13716483922631365, -0.1021030454481474, + 0.15650163697697536, -0.1262084459079082, 0.0945385315923478, + -0.14571620455079032, 0.10848384412787829, -0.1657968045321277, + 0.13712862067765763, -0.10029802621664903, 0.14564517282653366, + -0.12674302510877072, 0.07390208502645287, -0.1311263297657264, + 0.10530158039875909, -0.16181656100899916, 0.1283060635816091, + -0.09247863372503647, 0.143813617100201, -0.11351073891490655, + 0.1665355481032876, -0.13940228929361476, 0.09910516803585985, + -0.164880071184379, 0.12103034028634152, -0.09521117819569401, + 0.15283686033257926, -0.12168493219873758, 0.16213326889538726, + -0.12795607212461088, 0.10180510396185811, -0.15280356047686733, + 0.1170401154264058, -0.09140140160233672, 0.13973291726716605, + -0.10433052623722562, 0.1551151286357136, -0.1247580047842074, + 0.08863977746237016, -0.14599425858813164, 0.12353558676655231, + -0.15118738388042727, 0.13386390097446324, -0.10200021093249138, + 0.15603284126703199, -0.1215991384328776, 0.07735233743853676, + -0.14989551402233267, 0.106899502085159, -0.1670258019775891, + 0.1303077418640672, -0.09821757631907385, 0.1493076912479999, + -0.11918484511879272, 0.17274518057551985, -0.14708004649753798, + 0.09526029649519659, -0.15474012110980273, 0.1251968012102199, + -0.02625063814320463, + ], + "value": 41780.636851844036, + "opg_hessian_ratio": (0.6984, 52.74), + "other_local_optima": False, + }, + "regression_ignored_heteroskedasticity_severe_31": { + "params": [ + 2.020661656867948, 0.25300393506587604, -0.1781517115554248, + 0.23577165358371147, -0.16976974664747643, 0.1739618847413741, + -0.22013612422612416, 0.1762266521874215, -0.2564311640661213, + 0.20239896820126504, -0.11895053674760425, 0.2177658901276907, + -0.16674049628421658, 0.11079011108996921, -0.1494088532873317, + 0.12154868349223395, -0.21767433648264195, 0.1629410155798545, + -0.12529813264887227, 0.14674403741059863, -0.15196151989161982, + 0.2572226282926167, -0.14235483951508282, 0.16773426721998735, + -0.22563329332597398, 0.20921102588299598, -0.17062870195087845, + 0.17162171140498858, -0.18187290302970155, 0.23755557733443208, + 0.969964068448936, + ], + "value": 23889.02601653609, + "opg_hessian_ratio": (0.1395, 27.67), + "other_local_optima": False, + }, + "logit_probit_data_tiny_100": { + "params": [ + 0.5555850093052845, 0.2955669013725302, -0.23812962692293244, + 0.3321273563187775, -0.2496309885018739, 0.18401979582219372, + -0.28424359940693705, 0.22614961471134376, -0.33439044623991176, + 0.2533701979838902, -0.16692065783611074, 0.3855944254165342, + -0.2945682174476604, 0.20749424373342107, -0.26249154738170005, + 0.25426281232428594, -0.31356814778577025, 0.22324085747224726, + -0.20769543474142388, 0.28537305432493953, -0.19879024142135682, + 0.332150468131854, -0.2711303592159777, 0.2445550344878261, + -0.32033138212087936, 0.257042149715874, -0.2060035482242176, + 0.2793742270855427, -0.26404570098109786, 0.3715363179097818, + -0.259176001497583, 0.18103675391586058, -0.30933687521541076, + 0.21773644030468498, -0.16571087458546355, 0.3354349194896423, + -0.251900444088605, 0.29758044922808174, -0.22014870624490657, + 0.19605915124949752, -0.3072518441799259, 0.22458126159463432, + -0.3376443812993042, 0.2204745662846462, -0.15621661426660527, + 0.3121777407892841, -0.2724047050027662, 0.18909586887885885, + -0.28026479503085105, 0.21118452521076475, -0.35759154541174326, + 0.27251867859601764, -0.2518383872740719, 0.30738209585981613, + -0.26887851883205915, 0.36291057824917117, -0.35441511717270385, + 0.20716624053586274, -0.31885014401088074, 0.32036253397133824, + -0.1747808196334515, 0.28803196231907785, -0.26370670080701236, + 0.36263789039605476, -0.24976186095357264, 0.19513045056595688, + -0.29486361555604795, 0.23012486655884223, -0.17925884036863668, + 0.28803999614264575, -0.24893982082111046, 0.354100539975605, + -0.2582680606335046, 0.17021419824662523, -0.27030300201253754, + 0.21606445474516045, -0.3660599552260148, 0.2413086015381475, + -0.23045714245086263, 0.2926795304154868, -0.26473150951529545, + 0.15553246352763525, -0.2928047266478087, 0.21998072681613887, + -0.3489983396916302, 0.3186551801332021, -0.1770506581185912, + 0.3104840202339226, -0.2500317445802513, 0.166003232343661, + -0.28442071479075653, 0.24425007706205706, -0.31694677454232417, + 0.248984136278347, -0.1796482098508221, 0.27690606133914564, + -0.2453004317307378, 0.3950465802874274, -0.23419545167992228, + 0.1725168861573005, + ], + "value": 3863.6697572425173, + "opg_hessian_ratio": (0.764, 1.333), + "other_local_optima": False, + }, + "logit_misclassified_moderate_60": { + "params": [ + 0.24559925962698018, 0.15058072857958468, -0.08033497882468728, + 0.2119675011905134, -0.15416900766584798, 0.10681402588585512, + -0.14431597233940702, 0.09150492105336117, -0.2044187681292464, + 0.12181048953395351, -0.11680533161339329, 0.16086031628005112, + -0.11122559845972228, 0.05991023882613938, -0.15017563588077526, + 0.14883573128014319, -0.16002675324665958, 0.13372487493190238, + -0.15557661555027283, 0.19367031351352507, -0.10055421984065009, + 0.16370658129079285, -0.16403729522172314, 0.11435168878569835, + -0.13585751908021204, 0.13914716675732813, -0.13675973024338856, + 0.17027936086344378, -0.06858508167887685, 0.1955957393010549, + -0.14412116241707265, 0.1174972877782569, -0.18633695981694656, + 0.11878689620915595, -0.08968873591336549, 0.15638069198554336, + -0.08910504552133547, 0.1669269695117358, -0.17794451192932095, + 0.14007731477591373, -0.18478425346626365, 0.17301396674572186, + -0.20846341875918709, 0.15192121553523863, -0.08558208713157231, + 0.21367856656518433, -0.11929633797885421, 0.10542017205676354, + -0.1727329043789457, 0.11692204027365827, -0.1837828392513998, + 0.13670354657253708, -0.12228430852210659, 0.17090423426010695, + -0.1451939397580153, 0.1889432787199008, -0.14234337973962305, + 0.07014904774350308, -0.12996373900777472, 0.13130468459428943, + ], + "value": 5769.572937288045, + "opg_hessian_ratio": (0.8685, 1.175), + "other_local_optima": False, + }, + "logit_sign_restricted_moderate_40": { + "params": [ + 0.299256665563879, 0.16967557886898002, -0.1318749544093276, + 0.14815036294749803, -0.13981378497729005, 0.11698154950366024, + -0.1656306728828371, 0.14829330641369687, -0.19634087607801728, + 0.17741883692726781, -0.14156694175942977, 0.18488835883747898, + -0.15419062901728542, 0.11695087104351387, -0.1986126983502533, + 0.1471142900916766, -0.19522685490760106, 0.1780093866563292, + -0.07014234768302949, 0.17811115388898158, -0.14696983608472697, + 0.18449114917211065, -0.15812067569530353, 0.14679955665479358, + -0.16450099554639083, 0.15285072183776593, -0.08216002266801928, + 0.15331511888387914, -0.13453923407453489, 0.14464050942653017, + 0.0, 0.10276916086493243, 0.0, + 0.13998174984911407, 0.0, 0.18683734386123896, + 0.0, 0.1693099758819776, 0.0, + 0.09747147132960722, + ], + "value": 6073.74670624275, + "opg_hessian_ratio": (0.9151, 1.092), + "other_local_optima": False, + }, + "multinomial_logit_nested_moderate_46": { + "params": [ + 0.7488751304162534, -0.569264901644181, 0.8300918692111973, + -0.6420158669669689, -0.5716882718083087, -0.08073173664308515, + 0.4297168218495656, -0.31128865193920247, 0.08778086267673214, + 0.3327881602551769, -0.6976635292162643, 0.4832017212144164, + -0.1099975318134282, -0.04084325256087604, 0.3247521497854458, + -0.22870983894409574, -0.08179928725062138, 0.0175825624540981, + -0.3042373080807566, 0.4356836997860505, -0.30959241864203313, + 0.044189763342599435, -0.35458994452125286, -0.31753930343494496, + 0.4112887756829654, 0.0696755451449862, -0.3867803774600755, + 0.4513260860941127, -0.9088423042545721, 0.16966876175584872, + 0.27234993328420226, -0.41085963395732267, 0.34951823946270283, + -0.008459065449865912, -0.6277213729015069, 0.41082406552307504, + -0.2794275646848899, 0.1279043651268357, 0.14295077048897709, + -0.24651039123584192, -0.19373410848589467, -0.10841925378782453, + -0.16546337720625498, 0.4030526877746077, -0.46117746176985785, + 0.20363369166691572, + ], + "value": 7030.85947328325, + "opg_hessian_ratio": (0.7813, 1.283), + "other_local_optima": False, + }, + "multinomial_logit_nested_severe_123": { + "params": [ + 0.8002597186839903, -0.5817766740441531, 0.8965323588911506, + -0.6934750979652176, 0.5218553448754653, -0.8133796507947827, + -0.9975644436147968, -0.009013961508200448, 0.32755253387866606, + -0.3108961787885432, 0.15728125808423152, 0.016002312045305892, + -0.3433579697619132, 0.2631031930135845, -0.01145642687499174, + -0.19897858429176057, 0.3691101589778249, -0.18118317761900282, + -0.10139437658295099, -1.1342688603445636, 0.39074576889992757, + -0.11737746785502609, -0.14905926767539343, 0.286452243670255, + -0.48429292959453835, 0.057753450239852996, 0.17666327242754307, + -0.3561629479589947, 0.35040207913253796, -0.08603423618081207, + -0.2280815739618472, 0.25262678489923457, -0.6248393664564503, + 0.08065401862086648, -0.2508788174596168, 0.30262639390760576, + -0.24361660128328272, -0.27281072751343954, 0.26155032078597235, + -0.2963660367833246, 0.17006279260653492, 0.22480743358770597, + -0.2902082071012967, 0.3369048688837166, -0.04272238285438748, + -0.636753336404789, -0.1936173554369433, 0.24352644165227738, + -0.019403506008252552, -0.2766847110928886, 0.18371595884856592, + -0.16101749251541678, -0.12017840063686687, 0.2897103224712674, + -0.24768148983678162, 0.24492231883108467, 0.17902739504930018, + -0.32365972130602394, -1.2022569294717962, 0.16735770279448953, + 0.14502149587238347, -0.3583614159628709, 0.1854902569219033, + -0.04282788232053318, -0.3304310421994188, 0.20843778884885789, + -0.11125421963568588, -0.049320106215842326, 0.3546527788737347, + -0.2049408044271667, 0.01836053630574235, -1.0486248953385287, + 0.3106103501499926, -0.28907859010012266, 0.06179553998526323, + 0.14654986186323554, -0.4956750921050316, 0.15745170092768346, + -0.022375703491833914, -0.24611323689109593, 0.40628402596136937, + -0.22489512761158045, -0.0656715293371091, 0.1770927064194669, + -0.5698441434002667, -0.1539628710917098, -0.1423317953736677, + 0.2632069079668797, -0.29931482724982234, 0.04706366639577053, + 0.1434149944334352, -0.3228102560866591, 0.28701343642652105, + -0.04989137337330926, -0.29301140042624246, 0.39668219505298435, + -0.31069660005052435, -0.9397568889975406, -0.19877256275656274, + 0.28794082224022277, -0.23676871147745737, -0.23869473235082841, + 0.283360465046399, -0.26479144264661963, 0.053162413490285235, + 0.23136349531624864, -0.34470650388894514, 0.3183845901238802, + 0.016692308001042516, -0.2808792857795393, -1.3467059557216436, + 0.4160139932414959, 0.02271415610277933, -0.3084600414072088, + 0.3115644145234293, -0.21992236438419446, -0.1456658127971863, + 0.28963590771005493, -0.2865130602773821, 0.1585860153998192, + 0.26886933692336606, -0.32345355977518014, 0.17817888155340497, + ], + "value": 10645.59198324737, + "opg_hessian_ratio": (0.6989, 1.551), + "other_local_optima": False, + }, + "weibull_frailty_severe_31": { + "params": [ + -0.8384461014787421, 0.05917507752596592, -0.04919411525051506, + 0.08728835344020656, -0.05628629830000571, 0.04230998270689505, + -0.07773531535564926, 0.033080271509054494, -0.07811263694218343, + 0.06863584932403448, -0.02561689876505698, 0.07064602705324953, + -0.08375008862658118, 0.039105393268316316, -0.05595351195691934, + 0.060719232612691576, -0.06608607044311093, 0.06670906568694147, + -0.05040808241123803, 0.07364263583336618, -0.06552634169724617, + 0.08982305467147916, -0.06676028195547207, 0.06896006604007318, + -0.0560541223122287, 0.06779638642235747, -0.033880964918168825, + 0.07093213452365447, -0.04953040904883778, 0.060306502984338095, + 0.07128430796319737, + ], + "value": 9682.557461046958, + "opg_hessian_ratio": (0.7654, 1.898), + "other_local_optima": False, + }, + "multivariate_normal_t_data_moderate_44": { + "params": [ + -2.000656511712786, -1.4156932159321722, -0.8635306814991878, + -0.243177873643901, 0.2939536824327876, 0.8760221480596831, + 1.400097849537468, 2.0409484516500593, -0.71986757059773, + -0.32700215988648285, -0.2807143304455817, 0.17282026709763873, + -0.4269653441339175, 0.07857588734459912, -0.10150602241838212, + 0.24852155619760663, -0.6304528194718674, 0.3572559041098071, + 0.002573135524227544, -0.12117041932437563, 0.3012631225278094, + -0.6602886042944031, 0.574434363689281, -0.012163107455212391, + 0.1830248165991362, -0.07675195211571509, 0.37662455837673875, + -0.7884969951621508, 0.763894531763276, 0.035355040794098444, + -0.04225543965671989, 0.0499181644181108, -0.2192294777653733, + 0.35301910440821344, -0.9325524449363893, 0.8889003832021751, + 0.17476033204364297, 0.15173915704658533, 0.043803390597659024, + 0.2320102342683732, -0.2316665747921737, 0.3313850450358499, + -1.093818416080696, 0.9968270274501589, + ], + "value": 42032.44338646013, + "opg_hessian_ratio": (0.8236, 5.135), + "other_local_optima": False, + }, + "multivariate_normal_t_data_tiny_90": { + "params": [ + -2.000481297097065, -1.6451624266942897, -1.2610593375767436, + -0.9219934086960205, -0.549925079397843, -0.19074874124158625, + 0.17783344882768856, 0.5534105027615178, 0.9049835201553149, + 1.2692211349970561, 1.6189459963003898, 1.9464610285672714, + -0.69753461036401, -0.28582528433536863, -0.42249821851971797, + 0.15397057924777205, -0.33799466268951994, -0.12367269439368454, + -0.06311782324960863, 0.16377720386909586, -0.42363010793084005, + 0.07928634186058457, 0.026171682011751213, -0.06730599761173786, + 0.20163878240585728, -0.5123414015999642, 0.2569186859106779, + -0.025398188972312226, -0.025591675228275813, -0.07979520848003757, + 0.2382873625085994, -0.577626612951904, 0.40369004977838074, + 0.043020673846713674, 0.01847918886146205, 0.0629703098312934, + -0.07848674555348194, 0.2303586551948759, -0.6908041993726226, + 0.5284186283168955, -0.07804719879483923, -0.026929107547569057, + -0.01973365313917562, 0.014011896635467367, -0.1226941481816789, + 0.2934346788287791, -0.7138991571499319, 0.6418167558236737, + -0.016217639779621686, -0.00747839521797193, 0.04630422760794887, + -0.014299038480665773, 0.06403724311176683, -0.11173972177119115, + 0.3357485809248996, -0.8759695011395421, 0.7655433718991052, + 0.054519551052690116, 0.0020237685891643688, 0.02986206627600048, + 0.025449766720546496, -0.0303852658301853, 0.024839674189527344, + -0.16689779822173775, 0.4091649943169877, -0.9447464872103928, + 0.8635412534054051, -0.04003784270244431, -0.06339397593166385, + -0.039323215229795185, -0.03155146625591811, 0.006611416564825263, + -0.03165238908421614, 0.035072025504290595, -0.17519527825661382, + 0.3836912756453208, -1.0188767609672675, 0.9303023709385605, + 0.03845356687895474, 0.06503552520951297, 0.06939358112309814, + 0.10302259005784029, -0.03499369134010065, 0.013090700156918687, + -0.022372776963805612, 0.06792061423844134, -0.14262134056685818, + 0.3842398303366647, -1.114309681234887, 0.9959010395207583, + ], + "value": 106244.8768631635, + "opg_hessian_ratio": (0.7535, 1.671), + "other_local_optima": False, + }, + "fixed_effects_poisson_overdispersed_moderate_110": { + "params": [ + 0.1736644888945124, -0.11287952847462039, 0.19013404562109293, + -0.1369154309787014, 0.1053223299425166, -0.1817977922331325, + 0.13851724637438412, -0.21138388724128035, 0.1740100247007789, + -0.11974567143996433, 1.5740302584801755, 2.0081074687488747, + 1.4793513847680757, 1.7402925337190662, 2.2807913905112716, + 1.8506708686464375, 1.343128254886811, 1.6692571526136888, + 1.4646689417264944, 1.1742216520822268, 1.2413888850046755, + 1.8055182487007648, 1.7605251999696494, 1.726283826719532, + 2.3479225588589197, 1.6744306473118014, 1.898362960262627, + 1.873204636742344, 1.0546018922127365, 1.8346794413158676, + 2.0467603610308522, 2.273113832069005, 1.8501016983503786, + 1.4536125555169666, 1.7752875523609013, 1.627565709775224, + 1.822325445087151, 1.9132317314099168, 1.7415786458276423, + 1.4400450406811829, 1.234798488193789, 1.0317169106312833, + 1.811577481453546, 2.0742983721784047, 2.2755895556199834, + 1.9423000719932915, 1.2037179726051868, 2.222118261199312, + 1.0257915615174968, 1.9030910568067676, 1.8588522330721706, + 1.7622589621844507, 2.0677169901222596, 1.2409467460516268, + 1.2159647699056386, 1.3697651244438387, 1.3195378852825808, + 1.2911937053147686, 1.3224543504597905, 1.156298249329463, + 1.876053079292714, 1.9623340644478149, 2.152144980553639, + 1.974863899874203, 1.4434097082734965, 1.6613505498591294, + 1.7326187173951988, 1.0123236208943354, 1.4600042618894027, + 1.2322556599596752, 1.8078470691995918, 1.3379994418400265, + 0.8225931134825458, 1.3346809508122799, 1.5762441870463, + 1.6808915994491072, 1.5060235823171815, 2.0368213337563743, + 1.5980508769824133, 1.203619212624051, 1.7231949978947554, + 1.737022411356947, 1.0242890840728593, 1.1332168436334928, + 1.7545427004145513, 1.7531345386287212, 1.9352429363633281, + 0.6006300495157731, 1.9047284329823562, 1.670315439415361, + 1.6871739862527757, 1.058966237918777, 1.0814060732070077, + 0.9103002823099725, 1.2340178985908323, 1.2598576454829724, + 1.5547076531036268, 1.226490560064792, 1.138979930004521, + 1.0588548144426744, 1.282505896118784, 1.7735726244648784, + 1.6835856601137702, 1.507956337329236, 1.3852873858802397, + 1.7425587882686144, 1.9615319825354016, 1.4936233778810362, + 1.3917338662006045, 1.4560026786849642, + ], + "value": 5819.496936708289, + "opg_hessian_ratio": (0.8286, 6.713), + "other_local_optima": False, + }, + "ordered_probit_skewed_errors_moderate_40": { + "params": [ + 0.21531783548338407, -0.16299964053861937, 0.24523793340744093, + -0.1839881077518522, 0.12484188230874296, -0.20578170157879774, + 0.16976509531379214, -0.24542373226706984, 0.18811003893240846, + -0.13803587336389045, 0.22262471780854892, -0.19104200861214884, + 0.12651716030656956, -0.22819778272757907, 0.15046673309995312, + -0.234926103510427, 0.1833973526240864, -0.12621525071458425, + 0.21857644400598591, -0.1703955000580883, 0.2475743264025776, + -0.1994760626768214, 0.157740515481479, -0.23158092239287043, + 0.18826441957443457, -0.14587623598553998, 0.22875615794595897, + -0.17020346616273024, 0.22410474636897187, -0.17343947589873177, + -2.142886170039982, -0.2233331809530035, -0.6751694149271069, + -0.8587702771649535, -1.0270633162549094, -1.043843868330466, + -1.1137786614596712, -1.0576815943625195, -0.9084038253950238, + -0.6422160698906341, + ], + "value": 20345.492979910363, + "opg_hessian_ratio": (0.6711, 1.711), + "other_local_optima": False, + }, + "tobit_heteroskedastic_moderate_51": { + "params": [ + 0.37106243368680486, 0.4890800451384777, -0.12066995339968796, + 0.21644585864431468, -0.16055526598651565, 0.08122223115894046, + -0.1811898279740862, 0.12311112143003602, -0.21797102656630665, + 0.12390092612285229, -0.11927251362258073, 0.17797048708423496, + -0.1596302993516515, 0.10606596639263764, -0.2290184969991704, + 0.11979464716615441, -0.19081266613022127, 0.14698846362907178, + -0.09869175062261581, 0.1618406926899102, -0.14471001366268724, + 0.21557968363547597, -0.1622773775674213, 0.11902530237832906, + -0.16711568263774812, 0.11345043941447908, -0.06933003530671697, + 0.19288985837937953, -0.1302139366838184, 0.18482543272779803, + -0.1666434927390609, 0.16110229450149938, -0.1805810529519519, + 0.14454491569847552, -0.12742458070369278, 0.16682245676309784, + -0.1209132036589723, 0.19933192137259176, -0.18762464458964245, + 0.06366676472516837, -0.22304730246730473, 0.1384313313392666, + -0.21257945641089623, 0.16578880163888235, -0.11832336456030641, + 0.19699753067668813, -0.14703361185787786, 0.10389619558942473, + -0.18902346785069482, 0.12800989135400861, 0.6267417537652925, + ], + "value": 14704.195196731429, + "opg_hessian_ratio": (0.5037, 3.612), + "other_local_optima": False, + }, + "heckman_t_errors_severe_37": { + "params": [ + 0.3229169011317771, 0.3051320107513332, -0.1980716442914009, + 0.2790740502768813, -0.33649642739312874, 0.2217217031239882, + -0.26206433100220233, 0.20578911428923985, -0.2682647678387611, + 0.3104306337508259, -0.23835328606200917, 0.2689894426184552, + -0.34120960230246916, 0.25056149778302, -0.3065670507051497, + 0.1639019077473041, -0.23181423708862958, 0.32516918297807496, + -0.2360354998291929, 0.2697665567597773, 0.9688249242060168, + 0.25941259660263966, -0.24112705262151052, 0.34127883949211885, + -0.26739788365896405, 0.21775898163768448, -0.31117142704202305, + 0.2583698433759855, -0.35725230359848825, 0.29041174766410216, + -0.20657272576289196, 0.325025962795664, -0.27099205704567875, + 0.18454227656709063, -0.28365090184716846, 0.16375080705574627, + 0.5412282951370349, + ], + "value": 13408.661486325422, + "opg_hessian_ratio": (0.7651, 10.67), + "other_local_optima": False, + }, + "zero_inflated_poisson_negbin_data_moderate_45": { + "params": [ + -1.4637578909068156, 0.14356515854634158, -0.10625896846004111, + 0.1181705267455839, -0.19548346884043874, 0.09480607428041536, + -0.1271762055030995, 0.12036965622740763, -0.1430751829816729, + 0.14848341447372224, -0.08821290743838511, 0.09605734075095947, + -0.08913037675693389, 0.10670048146942646, -0.16211026956976549, + 0.12489877992259354, -0.14033853405136598, 0.19281822409160693, + -0.12245753816792336, 0.11953822666997717, 1.2238298216134085, + -0.059291623414201404, 0.0616609063111873, -0.060986816826497904, + 0.08127620460461316, -0.05630965973362776, 0.09228264266297406, + -0.03873678777074401, 0.056132031332742645, -0.0732833711165124, + 0.048093763697739135, -0.08057637924528438, 0.014576179711216422, + -0.05273099802987723, 0.07029644968772666, -0.03818158292276153, + 0.04212220573085365, -0.06532813191194617, 0.03744215521219198, + -0.06506579779479531, 0.03215170932812109, -0.04865062028121113, + 0.08317945013044194, -0.04113979574684357, 0.060042823695772435, + ], + "value": 23236.4531013268, + "opg_hessian_ratio": (0.8676, 3.359), + "other_local_optima": False, + }, + "random_effects_probit_bimodal_effects_moderate_41": { + "params": [ + -0.31895467952647805, 0.1856266070664855, -0.14291356672792954, + 0.17769934308825827, -0.15484079813138493, 0.11694717189287851, + -0.17697524750820098, 0.12969137682261356, -0.20219407978475457, + 0.16311161260703563, -0.12790797600773696, 0.1899446972574959, + -0.13568868689802138, 0.10708490377569692, -0.1780631416629434, + 0.1378226997298685, -0.21522638084533346, 0.1801815781432026, + -0.07659437328351082, 0.21351135352967301, -0.14353070264711626, + 0.20293339496547835, -0.1688243705145744, 0.14327088092723708, + -0.21461150602742682, 0.16882249706931862, -0.08924918330160493, + 0.16419826263647774, -0.15969474376790987, 0.2205976300260199, + -0.18903820186936454, 0.12436014036323717, -0.20094068573344048, + 0.1560826223782494, -0.08668233281055603, 0.14747179168721064, + -0.12696562409134285, 0.2048191628492048, -0.19252150337594753, + 0.09448981275766885, 0.1152804405524566, + ], + "value": 5049.446391476008, + "opg_hessian_ratio": (0.7176, 1.317), + "other_local_optima": False, + }, + "gamma_regression_lognormal_data_moderate_41": { + "params": [ + 1.0111702974297387, 0.0800458321006574, -0.0665841204938496, + 0.09560609208004374, -0.08100694890363212, 0.06449067312323804, + -0.0941855399797003, 0.0753788916245459, -0.10957323363593649, + 0.08863699662920693, -0.06545046142340374, 0.09891111324399444, + -0.07500280115794622, 0.0490409790631445, -0.09072394319616257, + 0.07250343796411789, -0.10902596646103006, 0.07564450914632884, + -0.06396771562718254, 0.10003631430796187, -0.07265176296447086, + 0.10175847478718035, -0.07360092165375529, 0.06585465738437132, + -0.10255930101492355, 0.07386799294407569, -0.056605280150514824, + 0.08504136069818104, -0.07105223345133159, 0.08066151699776267, + -0.07996298796191785, 0.057283746925105766, -0.1025978248102153, + 0.07729279804885153, -0.047482496025520994, 0.07991396661737003, + -0.06869149211687521, 0.08785717758113143, -0.06453582088811843, + 0.06615331259002533, 0.977669676491409, + ], + "value": 18007.99230247018, + "opg_hessian_ratio": (0.684, 2.09), + "other_local_optima": False, + }, + "mixed_logit_lognormal_coefficients_moderate_30": { + "params": [ + 0.2841033803180181, -0.2303024911341492, 0.36546213317289566, + -0.33755884564055455, 0.1683888196434019, -0.39391891152134856, + 0.6978863983435648, 0.9169351877329907, 0.8932775981800455, + 0.8953292518981811, 0.9929000893344259, 1.1037446624628677, + 1.1643947036957498, 1.2568755426632794, 1.3351114761545029, + 1.4136144067771474, 1.4037454377758156, 1.537647215152686, + 0.5029259353563937, 0.6069132010897409, 0.4745954872106493, + 0.4457397777885767, 0.43455941538952386, 0.2836163653924528, + 0.0, 0.48733143630015524, 0.34021158844403065, + 0.0, 0.2369122056442748, 0.0, + ], + "value": 2105.7568150292245, + "opg_hessian_ratio": (0.6173, 3.013), + "other_local_optima": False, + }, + "stochastic_frontier_wrong_skew_severe_32": { + "params": [ + 1.7889410092968867, 0.09514380728417024, -0.07167606358004106, + 0.11135160073103866, -0.09015400893765999, 0.057897717158561, + -0.11823784508892798, 0.06672077683062969, -0.1121431432934636, + 0.09532834059447562, -0.053597201803942986, 0.10474751789954567, + -0.07586409279484176, 0.05016979375576074, -0.09427870790778826, + 0.08104114622612305, -0.11250004623602848, 0.07593413136184944, + -0.06593526347137008, 0.10482615476746836, -0.07871040697802047, + 0.12917868661186477, -0.09598374678481092, 0.09395331380210481, + -0.11910170323445499, 0.0835694400265658, -0.0645973582879582, + 0.11318183290838131, -0.07339099411531186, 0.11805564903493133, + -0.2520151980600318, 0.0, + ], + "value": 11669.23335144641, + "opg_hessian_ratio": (0.7459, 1.431), + "other_local_optima": False, + }, +} +# fmt: on diff --git a/src/optimagic/benchmarking/run_benchmark.py b/src/optimagic/benchmarking/run_benchmark.py index b4c619e25..652148c4d 100644 --- a/src/optimagic/benchmarking/run_benchmark.py +++ b/src/optimagic/benchmarking/run_benchmark.py @@ -14,7 +14,8 @@ from optimagic.algorithms import AVAILABLE_ALGORITHMS from optimagic.optimization.optimize import minimize from optimagic.pytree import tree_leaves -from optimagic.typing import PyTreeNamespace +from optimagic.shared.process_user_function import infer_aggregation_level +from optimagic.typing import AggregationLevel, PyTreeNamespace def run_benchmark( @@ -181,10 +182,11 @@ def _process_one_result(optimize_result, problem): """ _criterion = problem["noise_free_fun"] + _problem_type = infer_aggregation_level(_criterion) _start_x = problem["inputs"]["params"] _start_crit_value = _criterion(_start_x) if isinstance(_start_crit_value, np.ndarray): - _start_crit_value = (_start_crit_value**2).sum() + _start_crit_value = _aggregate_residuals(_start_crit_value, _problem_type) _is_noisy = problem["noisy"] _solution_crit = problem["solution"]["value"] @@ -203,7 +205,9 @@ def _process_one_result(optimize_result, problem): if _is_noisy: criterion_history = np.array([_criterion(p) for p in params_history]) if criterion_history.ndim == 2: - criterion_history = (criterion_history**2).sum(axis=1) + criterion_history = _aggregate_residuals( + criterion_history, _problem_type + ) else: criterion_history = history.fun criterion_history = np.clip(criterion_history, _solution_crit, np.inf) @@ -217,3 +221,15 @@ def _process_one_result(optimize_result, problem): "batches_history": batches_history, "solution": optimize_result, } + + +def _aggregate_residuals(value, problem_type): + """Aggregate residuals or likelihood contributions along the last axis. + + Likelihood contributions are summed; anything else is treated as least-squares + residuals and squared before summing. + + """ + if problem_type == AggregationLevel.LIKELIHOOD: + return value.sum(axis=-1) + return (value**2).sum(axis=-1) diff --git a/tests/optimagic/benchmarking/likelihood/__init__.py b/tests/optimagic/benchmarking/likelihood/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/optimagic/benchmarking/likelihood/test_models.py b/tests/optimagic/benchmarking/likelihood/test_models.py new file mode 100644 index 000000000..0a437e3ec --- /dev/null +++ b/tests/optimagic/benchmarking/likelihood/test_models.py @@ -0,0 +1,449 @@ +from functools import partial + +import numpy as np +import pytest +from scipy import special + +import optimagic as om +from optimagic.benchmarking.likelihood import models +from optimagic.benchmarking.likelihood.models import _log_normal_interval + +# Small versions of all models, covering all options of the data generating processes. +# The second entry says whether the model is correctly specified. +MODELS = { + "logit": (partial(models.binary_choice, n_obs=300, n_params=5), True), + "logit_scaled": ( + partial(models.binary_choice, n_obs=300, n_params=6, badly_scaled=True), + True, + ), + "logit_correlated": ( + partial(models.binary_choice, n_obs=300, n_params=4, correlation=0.5), + True, + ), + "probit": ( + partial(models.binary_choice, n_obs=300, n_params=5, model="probit"), + True, + ), + "logit_probit_data": ( + partial(models.binary_choice, n_obs=300, n_params=5, dgp_errors="normal"), + False, + ), + "logit_misclassified": ( + partial(models.binary_choice, n_obs=300, n_params=5, dgp_misclassification=0.1), + False, + ), + "probit_heteroskedastic": ( + partial( + models.binary_choice, + n_obs=300, + n_params=5, + model="probit", + dgp_heteroskedasticity=0.5, + ), + False, + ), + "logit_sign_restricted": ( + partial(models.binary_choice, n_obs=300, n_params=6, n_sign_restricted=3), + False, + ), + "poisson": (partial(models.poisson_regression, n_obs=300, n_params=4), True), + "poisson_overdispersed": ( + partial(models.poisson_regression, n_obs=300, n_params=4, dgp_dispersion=3.0), + False, + ), + "poisson_underdispersed": ( + partial(models.poisson_regression, n_obs=300, n_params=4, dgp_dispersion=0.4), + False, + ), + "fixed_effects_poisson": ( + partial(models.fixed_effects_poisson, n_groups=5, n_periods=10, n_slopes=3), + True, + ), + "fixed_effects_poisson_overdispersed": ( + partial( + models.fixed_effects_poisson, + n_groups=5, + n_periods=10, + n_slopes=3, + dgp_dispersion=2.0, + ), + False, + ), + "negative_binomial": ( + partial(models.negative_binomial, n_obs=300, n_params=5), + True, + ), + "zero_inflated_poisson": ( + partial( + models.zero_inflated_poisson, + n_obs=300, + n_inflation_params=3, + n_count_params=4, + ), + True, + ), + "zero_inflated_poisson_negbin_data": ( + partial( + models.zero_inflated_poisson, + n_obs=300, + n_inflation_params=4, + n_count_params=3, + dgp_dispersion=3.0, + ), + False, + ), + "heteroskedastic_regression": ( + partial( + models.linear_regression, n_obs=300, n_mean_params=4, n_variance_params=3 + ), + True, + ), + "regression_t_errors": ( + partial( + models.linear_regression, + n_obs=300, + n_mean_params=4, + n_variance_params=1, + dgp_error_df=4.0, + ), + False, + ), + "regression_ignored_heteroskedasticity": ( + partial( + models.linear_regression, + n_obs=300, + n_mean_params=4, + n_variance_params=1, + dgp_heteroskedasticity=0.5, + correlation=0.3, + ), + False, + ), + "tobit": (partial(models.tobit, n_obs=300, n_params=5), True), + "tobit_t_errors": ( + partial(models.tobit, n_obs=300, n_params=5, dgp_error_df=4.0), + False, + ), + "tobit_heteroskedastic": ( + partial(models.tobit, n_obs=300, n_params=5, dgp_heteroskedasticity=0.5), + False, + ), + "gamma_regression": (partial(models.gamma_regression, n_obs=300, n_params=5), True), + "gamma_regression_lognormal_data": ( + partial(models.gamma_regression, n_obs=300, n_params=5, dgp_lognormal=True), + False, + ), + "stochastic_frontier": ( + partial(models.stochastic_frontier, n_obs=300, n_params=5), + True, + ), + "stochastic_frontier_wrong_skew": ( + partial(models.stochastic_frontier, n_obs=300, n_params=5, dgp_wrong_skew=True), + False, + ), + "ordered_probit": ( + partial(models.ordered_probit, n_obs=300, n_slopes=3, n_categories=5), + True, + ), + "ordered_probit_logistic_errors": ( + partial( + models.ordered_probit, + n_obs=300, + n_slopes=3, + n_categories=4, + dgp_errors="logistic", + ), + False, + ), + "ordered_probit_gumbel_errors": ( + partial( + models.ordered_probit, + n_obs=300, + n_slopes=3, + n_categories=4, + dgp_errors="gumbel", + ), + False, + ), + "multinomial_logit": ( + partial( + models.multinomial_logit, + n_obs=300, + n_alternatives=4, + n_attributes=2, + n_characteristics=2, + ), + True, + ), + "multinomial_logit_nested_data": ( + partial( + models.multinomial_logit, + n_obs=300, + n_alternatives=5, + n_attributes=2, + n_characteristics=1, + dgp_nest_dissimilarity=0.5, + ), + False, + ), + "weibull": (partial(models.weibull_duration, n_obs=300, n_params=4), True), + "weibull_frailty": ( + partial( + models.weibull_duration, n_obs=300, n_params=4, dgp_frailty_variance=0.5 + ), + False, + ), + "multivariate_normal": ( + partial(models.multivariate_normal, n_obs=300, dim=4), + True, + ), + "multivariate_normal_t_data": ( + partial(models.multivariate_normal, n_obs=300, dim=3, dgp_df=5.0), + False, + ), + "garch": (partial(models.garch, n_obs=500), True), + "garch_t_innovations": ( + partial(models.garch, n_obs=500, dgp_innovation_df=5.0), + False, + ), + "garch_t_likelihood": ( + partial(models.garch, n_obs=500, t_likelihood=True, dgp_innovation_df=6.0), + True, + ), + "random_effects_probit": ( + partial( + models.random_effects_probit, n_individuals=100, n_periods=4, n_params=4 + ), + True, + ), + "random_effects_probit_bimodal_effects": ( + partial( + models.random_effects_probit, + n_individuals=100, + n_periods=4, + n_params=4, + dgp_bimodal_effects=True, + ), + False, + ), + "mixed_logit": ( + partial( + models.mixed_logit, + n_individuals=50, + n_situations=4, + n_alternatives=3, + n_fixed=2, + n_random=2, + n_draws=20, + ), + True, + ), + "mixed_logit_correlated_zero_sd": ( + partial( + models.mixed_logit, + n_individuals=50, + n_situations=4, + n_alternatives=3, + n_fixed=1, + n_random=3, + n_draws=20, + correlated=True, + zero_sd=True, + ), + True, + ), + "mixed_logit_lognormal_coefficients": ( + partial( + models.mixed_logit, + n_individuals=50, + n_situations=4, + n_alternatives=3, + n_fixed=1, + n_random=2, + n_draws=20, + correlated=True, + dgp_lognormal=True, + ), + False, + ), + "normal_mixture": (partial(models.normal_mixture, n_obs=300), True), + "normal_mixture_three_components": ( + partial(models.normal_mixture, n_obs=300, dgp_three_components=True), + False, + ), + "heckman_selection": ( + partial( + models.heckman_selection, + n_obs=300, + n_selection_params=4, + n_outcome_params=3, + ), + True, + ), + "heckman_selection_t_errors": ( + partial( + models.heckman_selection, + n_obs=300, + n_selection_params=4, + n_outcome_params=2, + dgp_error_df=4.0, + ), + False, + ), +} + + +def _bounds(likelihood): + k = likelihood.n_params + lower = likelihood.lower_bounds + upper = likelihood.upper_bounds + lower = np.full(k, -np.inf) if lower is None else lower + upper = np.full(k, np.inf) if upper is None else upper + return lower, upper + + +def _interior_point(likelihood, seed): + """Perturb the true params or the good start, staying inside the bounds.""" + lower, upper = _bounds(likelihood) + base = likelihood.true_params + if base is None or not np.isfinite(base).all(): + base = likelihood.good_start + point = base + 0.1 * np.random.default_rng(seed).normal(size=len(base)) + return np.clip(point, lower + 1e-3, upper - 1e-3) + + +@pytest.fixture(params=list(MODELS), scope="module") +def model_case(request): + builder, is_correct = MODELS[request.param] + return builder(seed=1), is_correct + + +def test_shapes_and_finite_values(model_case): + likelihood, _ = model_case + k = likelihood.n_params + points = [ + likelihood.good_start, + likelihood.bad_start, + _interior_point(likelihood, 0), + ] + for x in points: + contributions = likelihood.fun(x) + jac = likelihood.jac(x) + assert contributions.ndim == 1 + assert jac.shape == (len(contributions), k) + assert np.isfinite(contributions).all() + assert np.isfinite(jac).all() + + +@pytest.mark.parametrize("point", ["good_start", "bad_start", "interior"]) +def test_jac_matches_numerical_derivative(model_case, point): + likelihood, _ = model_case + if point == "interior": + x = _interior_point(likelihood, 1) + else: + x = getattr(likelihood, point) + lower, upper = _bounds(likelihood) + numerical = om.first_derivative( + likelihood.fun, x, bounds=om.Bounds(lower=lower, upper=upper) + ).derivative + analytical = likelihood.jac(x) + scale = max(1.0, np.abs(analytical).max()) + np.testing.assert_allclose(analytical / scale, numerical / scale, atol=1e-6) + + +def test_start_values_satisfy_bounds(model_case): + likelihood, _ = model_case + lower, upper = _bounds(likelihood) + for x in [likelihood.good_start, likelihood.bad_start]: + assert x.shape == (likelihood.n_params,) + assert (x >= lower).all() + assert (x <= upper).all() + + +def test_good_start_differs_from_bad_start(model_case): + likelihood, _ = model_case + assert not np.allclose(likelihood.good_start, likelihood.bad_start) + + +def test_true_params_iff_correctly_specified(model_case): + likelihood, is_correct = model_case + if is_correct: + assert likelihood.true_params is not None + assert likelihood.true_params.shape == (likelihood.n_params,) + else: + assert likelihood.true_params is None + + +@pytest.mark.parametrize("name", ["logit", "mixed_logit", "garch", "ordered_probit"]) +def test_simulation_is_deterministic(name): + builder, _ = MODELS[name] + first = builder(seed=3) + second = builder(seed=3) + other_seed = builder(seed=4) + x = first.good_start + np.testing.assert_array_equal(first.fun(x), second.fun(x)) + assert not np.array_equal(first.fun(x), other_seed.fun(x)) + + +def test_sign_restrictions_are_lower_bounds(): + likelihood = models.binary_choice( + n_obs=300, n_params=6, seed=1, n_sign_restricted=2 + ) + expected = np.array([-np.inf] * 4 + [0.0] * 2) + np.testing.assert_array_equal(likelihood.lower_bounds, expected) + assert likelihood.upper_bounds is None + + +def test_mixed_logit_bounds_only_restrict_cholesky_diagonal(): + likelihood = models.mixed_logit( + n_individuals=20, + n_situations=2, + n_alternatives=3, + n_fixed=1, + n_random=2, + seed=1, + correlated=True, + ) + # params: 1 fixed, 2 means, chol entries (0, 0), (1, 0), (1, 1) + expected = np.array([-np.inf, -np.inf, -np.inf, 0.0, -np.inf, 0.0]) + np.testing.assert_array_equal(likelihood.lower_bounds, expected) + + +def test_multivariate_normal_true_params_reproduce_covariance(): + likelihood = models.multivariate_normal(n_obs=20_000, dim=3, seed=1) + true = likelihood.true_params + assert true is not None + rows, cols = np.tril_indices(3) + chol = np.zeros((3, 3)) + chol[rows, cols] = true[3:] + chol[np.diag_indices(3)] = np.exp(np.diag(chol)) + assert chol[1, 0] < 0 + # the true params are close to the maximum likelihood estimates + score = -likelihood.jac(true).sum(axis=0) / 20_000 + assert np.abs(score).max() < 0.05 + + +def test_normal_mixture_solution_is_not_unique(): + likelihood = models.normal_mixture(n_obs=100, seed=1) + assert not likelihood.unique_solution + swapped = likelihood.good_start[[1, 0, 3, 2, 4]] * np.array([1, 1, 1, 1, -1]) + np.testing.assert_allclose( + likelihood.fun(likelihood.good_start).sum(), likelihood.fun(swapped).sum() + ) + + +def test_log_normal_interval_is_accurate_in_tails(): + lower = np.array([-np.inf, -40.0, 39.0, -1.0, 2.0]) + upper = np.array([-38.0, -39.0, np.inf, 1.0, 2.0 + 1e-9]) + got = _log_normal_interval(lower, upper) + expected = np.array( + [ + special.log_ndtr(-38.0), + special.log_ndtr(-39.0) + + np.log1p(-np.exp(special.log_ndtr(-40.0) - special.log_ndtr(-39.0))), + special.log_ndtr(-39.0), + np.log(special.ndtr(1.0) - special.ndtr(-1.0)), + np.log(1e-9) - 0.5 * 2.0**2 - 0.5 * np.log(2 * np.pi), + ] + ) + np.testing.assert_allclose(got, expected, rtol=1e-6) diff --git a/tests/optimagic/benchmarking/likelihood/test_problems.py b/tests/optimagic/benchmarking/likelihood/test_problems.py new file mode 100644 index 000000000..2f4f7d61b --- /dev/null +++ b/tests/optimagic/benchmarking/likelihood/test_problems.py @@ -0,0 +1,171 @@ +import numpy as np +import pytest + +from optimagic.benchmarking.likelihood.problems import ( + LIKELIHOOD_SETS, + get_likelihood_problems, +) +from optimagic.benchmarking.likelihood.solutions import LIKELIHOOD_SOLUTIONS + +PARAM_RANGES = { + "likelihood_small": (3, 25), + "likelihood_large": (25, 150), + "likelihood_misspecified_small": (3, 25), + "likelihood_misspecified_large": (25, 150), +} + +INSTANCES = [ + (set_name, instance) + for set_name, instances in LIKELIHOOD_SETS.items() + for instance in instances +] + + +@pytest.fixture( + params=INSTANCES, ids=[instance.name for _, instance in INSTANCES], scope="module" +) +def case(request): + set_name, instance = request.param + return set_name, instance, instance.build() + + +def _bounds(likelihood): + k = likelihood.n_params + lower = likelihood.lower_bounds + upper = likelihood.upper_bounds + lower = np.full(k, -np.inf) if lower is None else lower + upper = np.full(k, np.inf) if upper is None else upper + return lower, upper + + +def test_set_names_match_param_ranges(): + assert set(LIKELIHOOD_SETS) == set(PARAM_RANGES) + + +def test_instance_names_are_unique(): + names = [instance.name for _, instance in INSTANCES] + assert len(names) == len(set(names)) + + +def test_stored_solutions_match_instances(): + names = {instance.name for _, instance in INSTANCES} + assert set(LIKELIHOOD_SOLUTIONS) == names + + +@pytest.mark.parametrize("set_name", list(LIKELIHOOD_SETS)) +def test_misspecification_is_documented(set_name): + is_misspecified_set = "misspecified" in set_name + for instance in LIKELIHOOD_SETS[set_name]: + if is_misspecified_set: + assert instance.misspecification is not None + assert instance.severity in {"tiny", "mild", "moderate", "severe"} + assert f"_{instance.severity}_" in instance.name + else: + assert instance.misspecification is None + assert instance.severity is None + + +def test_n_params_matches_name_and_range(case): + set_name, instance, likelihood = case + low, high = PARAM_RANGES[set_name] + assert low <= likelihood.n_params <= high + assert instance.name.endswith(f"_{likelihood.n_params}") + + +def test_true_params_iff_correctly_specified(case): + _, instance, likelihood = case + if instance.misspecification is None: + assert likelihood.true_params is not None + else: + assert likelihood.true_params is None + + +def test_stored_solution_value_is_reproduced(case): + _, instance, likelihood = case + solution = LIKELIHOOD_SOLUTIONS[instance.name] + value = likelihood.fun(np.array(solution["params"])).sum() + np.testing.assert_allclose(value, solution["value"], rtol=1e-10) + + +def test_stored_solution_satisfies_optimality_conditions(case): + _, instance, likelihood = case + x = np.array(LIKELIHOOD_SOLUTIONS[instance.name]["params"]) + lower, upper = _bounds(likelihood) + assert (x >= lower).all() + assert (x <= upper).all() + + jac = likelihood.jac(x) + gradient = jac.sum(axis=0) + # on a bound, the gradient must not point into the feasible set + assert (gradient[x == lower] >= -1e-6).all() + assert (gradient[x == upper] <= 1e-6).all() + + # at free params, the gradient must be zero; measured in the OPG metric, this is + # the squared Wald distance to the optimum + free = (x > lower) & (x < upper) + jac_free = jac[:, free] + direction = np.linalg.lstsq(jac_free, np.ones(len(jac)), rcond=None)[0] + decrement = gradient[free] @ direction + assert decrement < 1e-10 + + +def test_solution_is_better_than_start_values(case): + _, instance, likelihood = case + x = np.array(LIKELIHOOD_SOLUTIONS[instance.name]["params"]) + value = likelihood.fun(x).sum() + assert value < likelihood.fun(likelihood.good_start).sum() + assert value < likelihood.fun(likelihood.bad_start).sum() + + +def test_stored_solution_metadata_is_valid(): + for solution in LIKELIHOOD_SOLUTIONS.values(): + low, high = solution["opg_hessian_ratio"] + assert 0 < low <= high + assert isinstance(solution["other_local_optima"], bool) + + +def test_get_likelihood_problems(): + problems = get_likelihood_problems("likelihood_misspecified_small") + instances = LIKELIHOOD_SETS["likelihood_misspecified_small"] + assert len(problems) == 2 * len(instances) + + instance = instances[0] + good = problems[f"{instance.name}_good_start"] + bad = problems[f"{instance.name}_bad_start"] + expected_keys = { + "fun", + "jac", + "start_x", + "solution_x", + "start_criterion", + "solution_criterion", + "lower_bounds", + "upper_bounds", + "info", + } + assert set(good) == expected_keys + assert good["info"]["start"] == "good" + assert bad["info"]["start"] == "bad" + assert good["info"]["severity"] == instance.severity + assert isinstance(good["info"]["other_local_optima"], bool) + assert good["solution_criterion"] == bad["solution_criterion"] + np.testing.assert_allclose( + good["start_criterion"], good["fun"](good["start_x"]).sum() + ) + np.testing.assert_array_equal(good["solution_x"], bad["solution_x"]) + + +def test_get_likelihood_problems_without_unique_solution(): + problems = get_likelihood_problems("likelihood_small") + problem = problems["normal_mixture_5_good_start"] + assert problem["solution_x"] is None + assert not problem["info"]["unique_solution"] + assert np.isfinite(problem["solution_criterion"]) + + +def test_get_likelihood_problems_with_bounds(): + problems = get_likelihood_problems("likelihood_small") + problem = problems["garch_3_bad_start"] + assert problem["info"]["has_bounds"] + np.testing.assert_array_equal(problem["lower_bounds"], [1e-6, 0, 0]) + np.testing.assert_array_equal(problem["upper_bounds"], [np.inf, 1, 1]) diff --git a/tests/optimagic/benchmarking/likelihood/test_sampling.py b/tests/optimagic/benchmarking/likelihood/test_sampling.py new file mode 100644 index 000000000..61ffb6a39 --- /dev/null +++ b/tests/optimagic/benchmarking/likelihood/test_sampling.py @@ -0,0 +1,69 @@ +import numpy as np +import pytest +from scipy import special + +from optimagic.benchmarking.likelihood import sampling + +N_DRAWS = 200_000 + + +def _rng(): + return np.random.default_rng(1234) + + +def test_draws_are_stable_across_versions(): + # The stored reference solutions are only valid if these values never change. + got = sampling.uniform(np.random.default_rng(0), 3) + expected = np.array([0.6369616873214543, 0.2697867137638703, 0.04097352393619469]) + np.testing.assert_allclose(got, expected, rtol=1e-15) + + got = sampling.standard_normal(np.random.default_rng(0), 3) + expected = special.ndtri(expected) + np.testing.assert_allclose(got, expected, rtol=1e-15) + + +def test_same_seed_gives_same_draws(): + first = sampling.standardized_t(np.random.default_rng(5), 4.0, 10) + second = sampling.standardized_t(np.random.default_rng(5), 4.0, 10) + np.testing.assert_array_equal(first, second) + + +def test_uniform_is_in_open_unit_interval(): + draws = sampling.uniform(_rng(), N_DRAWS) + assert draws.min() > 0 + assert draws.max() < 1 + assert draws.shape == (N_DRAWS,) + + +@pytest.mark.parametrize( + "draw, mean, var", + [ + (lambda rng: sampling.standard_normal(rng, N_DRAWS), 0, 1), + (lambda rng: sampling.standardized_t(rng, 6.0, N_DRAWS), 0, 1), + (lambda rng: sampling.gamma(rng, 2.0, 1.5, N_DRAWS), 3.0, 4.5), + (lambda rng: sampling.exponential(rng, N_DRAWS), 1, 1), + (lambda rng: sampling.standard_gumbel(rng, N_DRAWS), np.euler_gamma, 1.645), + (lambda rng: sampling.standard_logistic(rng, N_DRAWS), 0, np.pi**2 / 3), + (lambda rng: sampling.poisson(rng, np.full(N_DRAWS, 2.5)), 2.5, 2.5), + (lambda rng: sampling.binomial(rng, np.full(N_DRAWS, 10.0), 0.3), 3, 2.1), + ], +) +def test_draws_have_expected_moments(draw, mean, var): + draws = draw(_rng()) + assert np.abs(draws.mean() - mean) < 0.02 + assert np.abs(draws.var() / var - 1) < 0.03 + + +def test_gamma_with_array_shape_and_scale(): + shape = np.array([0.5, 5.0]) + scale = np.array([2.0, 0.1]) + draws = sampling.gamma(_rng(), shape, scale, (N_DRAWS, 2)) + np.testing.assert_allclose(draws.mean(axis=0), shape * scale, rtol=0.02) + + +def test_categorical(): + probabilities = np.tile([0.2, 0.0, 0.5, 0.3], (N_DRAWS, 1)) + draws = sampling.categorical(_rng(), probabilities) + shares = np.bincount(draws, minlength=4) / N_DRAWS + np.testing.assert_allclose(shares, [0.2, 0.0, 0.5, 0.3], atol=0.005) + assert draws.dtype.kind == "i" diff --git a/tests/optimagic/benchmarking/test_get_benchmark_problems.py b/tests/optimagic/benchmarking/test_get_benchmark_problems.py index 134ae4f41..41be82300 100644 --- a/tests/optimagic/benchmarking/test_get_benchmark_problems.py +++ b/tests/optimagic/benchmarking/test_get_benchmark_problems.py @@ -3,6 +3,7 @@ import numpy as np import pytest +import optimagic as om from optimagic.benchmarking.get_benchmark_problems import ( _step_func, get_benchmark_problems, @@ -48,3 +49,66 @@ def test_step_func(): got = _step_func(p, lambda x: x @ x) assert np.allclose(got, 0) assert not np.allclose(p @ p, 0) + + +LIKELIHOOD_SET_NAMES = [ + "likelihood_small", + "likelihood_large", + "likelihood_misspecified_small", + "likelihood_misspecified_large", +] + + +@pytest.mark.parametrize("name", LIKELIHOOD_SET_NAMES) +def test_get_likelihood_problems(name): + problems = get_benchmark_problems(name) + for problem in problems.values(): + inputs = problem["inputs"] + assert set(inputs) <= {"fun", "params", "jac", "bounds"} + assert len(inputs["jac"]) == 2 + assert problem["info"]["has_bounds"] == ("bounds" in inputs) + start_value = inputs["fun"](inputs["params"]).sum() + np.testing.assert_allclose(start_value, problem["start_criterion"]) + assert problem["solution"]["value"] < problem["start_criterion"] + + +@pytest.mark.parametrize("problem_name", ["logit_5_good_start", "garch_3_bad_start"]) +def test_likelihood_derivatives_and_bounds_with_scaling(problem_name): + unscaled = get_benchmark_problems("likelihood_small")[problem_name] + problem = get_benchmark_problems("likelihood_small", scaling=True)[problem_name] + inputs = problem["inputs"] + params = inputs["params"] + # default scaling options + scaling_factor = np.linspace(0.1, 10, len(params)) + np.testing.assert_allclose(params, unscaled["inputs"]["params"] * scaling_factor) + + np.testing.assert_allclose( + inputs["fun"](params), unscaled["inputs"]["fun"](unscaled["inputs"]["params"]) + ) + + gradient, jac = inputs["jac"] + bounds = inputs.get("bounds", om.Bounds()) + numerical = om.first_derivative(inputs["fun"], params, bounds=bounds).derivative + np.testing.assert_allclose(jac(params), numerical, rtol=1e-5, atol=1e-5) + np.testing.assert_allclose(gradient(params), jac(params).sum(axis=0)) + + if "bounds" in inputs: + unscaled_bounds = unscaled["inputs"]["bounds"] + np.testing.assert_allclose( + inputs["bounds"].lower, unscaled_bounds.lower * scaling_factor + ) + np.testing.assert_allclose( + inputs["bounds"].upper, unscaled_bounds.upper * scaling_factor + ) + + +def test_noisy_likelihood_problems_use_numerical_derivatives(): + problems = get_benchmark_problems("likelihood_small", additive_noise=True) + assert all("jac" not in problem["inputs"] for problem in problems.values()) + + +@pytest.mark.parametrize("problem_name", ["logit_5_bad_start", "garch_3_good_start"]) +def test_minimize_likelihood_problem(problem_name): + problem = get_benchmark_problems("likelihood_small")[problem_name] + res = om.minimize(**problem["inputs"], algorithm="scipy_lbfgsb") + np.testing.assert_allclose(res.fun, problem["solution"]["value"], rtol=1e-6) diff --git a/tests/optimagic/benchmarking/test_run_benchmark.py b/tests/optimagic/benchmarking/test_run_benchmark.py index d501dd17e..f2685aacd 100644 --- a/tests/optimagic/benchmarking/test_run_benchmark.py +++ b/tests/optimagic/benchmarking/test_run_benchmark.py @@ -1,3 +1,4 @@ +import numpy as np import pytest from optimagic import get_benchmark_problems @@ -64,3 +65,44 @@ def test_run_benchmark_failing(): key = (failing_name, "scipy_lbfgsb") assert isinstance(result[key]["solution"], str) + + +def test_run_benchmark_likelihood_problems(): + all_problems = get_benchmark_problems("likelihood_small") + names = ["logit_5_good_start", "garch_3_bad_start"] + problems = {name: all_problems[name] for name in names} + + with pytest.warns(): + result = run_benchmark( + problems=problems, + optimize_options=["scipy_lbfgsb", "scipy_ls_trf"], + max_criterion_evaluations=50, + ) + + for name, problem in problems.items(): + # least-squares optimizers fail on likelihood problems; the start value of the + # failed run is the sum of the likelihood contributions + failed = result[(name, "scipy_ls_trf")] + assert isinstance(failed["solution"], str) + np.testing.assert_allclose( + failed["criterion_history"][0], problem["start_criterion"] + ) + + history = result[(name, "scipy_lbfgsb")]["criterion_history"] + np.testing.assert_allclose(history[0], problem["start_criterion"]) + assert history[-1] < problem["start_criterion"] + + +def test_run_benchmark_noisy_likelihood_problem(): + all_problems = get_benchmark_problems("likelihood_small", additive_noise=True) + name = "poisson_5_good_start" + problems = {name: all_problems[name]} + + result = run_benchmark( + problems=problems, + optimize_options=["scipy_neldermead"], + max_criterion_evaluations=20, + ) + + history = result[(name, "scipy_neldermead")]["criterion_history"] + np.testing.assert_allclose(history[0], problems[name]["start_criterion"]) From 76f33396669955a3cb4c4623fe0295bbbe4f4153 Mon Sep 17 00:00:00 2001 From: Janos Gabler Date: Sun, 25 Oct 2026 10:33:48 +0100 Subject: [PATCH 2/2] Add changelog entry for #722 Co-Authored-By: Claude Opus 5.5 --- CHANGES.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 4b1484e25..9eb90421d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,9 @@ releases are available on [Anaconda.org](https://anaconda.org/optimagic-dev/opti This release adds experimental support for **SciPy-style callbacks**, replaces pybaum by **optree** for pytree handling and uses **pydantic** to validate algorithm options. +- {gh}`722` Adds four likelihood benchmark sets (`likelihood_small`, `likelihood_large`, + `likelihood_misspecified_small`, `likelihood_misspecified_large`) with simulated data, + closed form derivatives and bounds ({ghuser}`janosg`). - {gh}`697` Adds experimental support for SciPy-style `callback(xk)` in `minimize` and `maximize`. The callback is called after each objective evaluation; its behavior might change in upcoming releases ({ghuser}`Pragati5-DEBUG`).