New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update criterion functions for new estimagic interface #389
Conversation
Codecov Report
@@ Coverage Diff @@
## main #389 +/- ##
==========================================
- Coverage 76.59% 74.17% -2.42%
==========================================
Files 50 50
Lines 3640 3636 -4
==========================================
- Hits 2788 2697 -91
- Misses 852 939 +87
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
…nts were already converted to external moments one step before
for more information, see https://pre-commit.ci
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Annica Gehlen <39128048+amageh@users.noreply.github.com>
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
* [pre-commit.ci] pre-commit autoupdate (#401) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> * [pre-commit.ci] pre-commit autoupdate updates: - [github.com/asottile/pyupgrade: v2.11.0 → v2.12.0](asottile/pyupgrade@v2.11.0...v2.12.0) - [github.com/PyCQA/flake8: 3.9.0 → 3.9.1](PyCQA/flake8@3.9.0...3.9.1) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Annica Gehlen <39128048+amageh@users.noreply.github.com>
for more information, see https://pre-commit.ci
updates: - [github.com/asottile/pyupgrade: v2.11.0 → v2.13.0](asottile/pyupgrade@v2.11.0...v2.13.0) - [github.com/asottile/reorder_python_imports: v2.4.0 → v2.5.0](asottile/reorder-python-imports@v2.4.0...v2.5.0) - [github.com/psf/black: 20.8b1 → 21.4b0](psf/black@20.8b1...21.4b0) - [github.com/PyCQA/flake8: 3.9.0 → 3.9.1](PyCQA/flake8@3.9.0...3.9.1) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Annica Gehlen <39128048+amageh@users.noreply.github.com>
Current behavior
The current criterion functions will not work for upcoming changes to estimagic's optimization capabilities. In particular, the way outputs are returned needs to be adjusted,
get_log_like_func
for maximum likelihood estimation:The following arguments control what objects will be returned:
return_scalar
: If True returns mean log-likelihood, if False returns NumPy.array of individual log-likelihood contributions.return_comparison_plot_data
: If True returns pandas.DataFrame in tidy data format with the columnsidentifier
,period
,choice
,value
, andkind
.value
column contains likelihood contributions (see Restructure likelihood.py for #310 and estimagic's comparison plot. #313)If both are True, the criterion will return a tuple.
get_moment_errors_func
for method of simulated moments estimation:The following arguments control what objects will be returned:
return_scalar
: If True will return the square product of weighted moment errors (float), if False will return moment errors multiplied by the root of weighting matrix.return_simulated_moments
: If True will return simulated moments in the same data structure as input empirical_moments.return_comparison_plot_data
: If True will return pandas.DataFrame in tidy data format with empirical and simulated moments (see Add comparison_plot_data to msm and return moments. #363)If
return_simulated_moments
orreturn_comparison_plot_data
are True, function will return tuple. Both can't be True at the same time.Desired behavior
To fit the new estimagic optimization interface, the criterion should return either a scalar/NumPy.ndarray or a dictionary containing the additional information (contributions).
Solution / Implementation
Both functions now return either a scalar or dictionary (no tuples). I implemented this by eliminating the function arguments
return_simulated_moments
andreturn_comparison_plot_data
. There are definitely other ways to do it but I feel like this could make the functions more concise. Backwards-compatibility will be compromised either way with these changes as far as I can judge.I detailed in both function docstrings how the function outputs will look like. As for the comparison plot data, some additional details:
Likelihood function:
kw_94_one
model (1000 agents and 40 periods). The pickled output is around 1.7 MB.The columns contain the following data types:
Simulated Method of Moments:
Example of comparison plot data created for
kw_94_one
on a sample of 320 moments. The pickled output here is around 30 kb but will obviously vary quite a lot with the choice of moments. I imposed only few data types (the columnsmoment_set
andkind
are set to categorical) since most depend on user-defined inputs.Todo