Skip to content
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

Core API change #102

Merged
merged 9 commits into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

<!--next-version-placeholder-->

## v0.1.2.dev23 (14/12/2022)

### CoFI Core

- [#91](https://github.com/inlab-geo/cofi/issues/91) Raise warning when people set solver params that are not in optional list
- [#97](https://github.com/inlab-geo/cofi/issues/97) Make walkers_start_pos a property of InversionOptions instead of BaseProblem
- [#98](https://github.com/inlab-geo/cofi/issues/98) Typo, wording fixes; shorten error messages

## v0.1.2.dev22 (23/11/2022)

### CoFI Core
Expand Down
8 changes: 8 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@ SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
BUILDDIR = build
EXAMPLESDIR = examples
TUTORIALSDIR = tutorials
GENERATEDDIR = generated

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

clean_all:
@$(SPHINXBUILD) -M clean "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
rm -rf $(SOURCEDIR)/$(EXAMPLESDIR)/$(GENERATEDDIR)/*
rm -rf $(SOURCEDIR)/$(TUTORIALSDIR)/$(GENERATEDDIR)/*

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
Expand Down
20 changes: 0 additions & 20 deletions docs/source/api/generated/cofi.BaseProblem.rst
Original file line number Diff line number Diff line change
Expand Up @@ -349,15 +349,6 @@ cofi.BaseProblem















Expand Down Expand Up @@ -655,13 +646,6 @@ cofi.BaseProblem



.. automethod:: BaseProblem.set_walkers_starting_pos






.. automethod:: BaseProblem.suggest_tools


Expand Down Expand Up @@ -748,10 +732,6 @@ cofi.BaseProblem

.. autoattribute:: BaseProblem.residual_defined

.. autoattribute:: BaseProblem.walkers_starting_pos

.. autoattribute:: BaseProblem.walkers_starting_pos_defined


:ref:`back to top <top_BaseProblem>`

Expand Down
1 change: 0 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@
"ignore_pattern": "._lib.py|_preprocessing.py",
"pypandoc": True,
"download_all_examples": False,
"backreferences_dir" : "api/generated/backreferences",
"doc_module": "cofi",
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@
},
"outputs": [],
"source": [
"######## CoFI BaseProblem - provide additional information\ninv_problem.set_log_prior(log_prior)\ninv_problem.set_log_likelihood(log_likelihood)\ninv_problem.set_walkers_starting_pos(walkers_start)\n\n######## CoFI InversionOptions - get a different tool\ninv_options_3 = InversionOptions()\ninv_options_3.set_tool(\"emcee\") # Here we use to Affine Invariant McMC sampler from Goodman and Weare (2010).\ninv_options_3.set_params(nwalkers=nwalkers, nsteps=nsteps, progress=True)\n\n######## CoFI Inversion - run it\ninv_3 = Inversion(inv_problem, inv_options_3)\ninv_result_3 = inv_3.run()\n\n######## CoFI InversionResult - check result\nprint(f\"The inversion result from `emcee`:\")\ninv_result_3.summary()"
"######## CoFI BaseProblem - provide additional information\ninv_problem.set_log_prior(log_prior)\ninv_problem.set_log_likelihood(log_likelihood)\ninv_problem.set_model_shape(ndim)\n\n######## CoFI InversionOptions - get a different tool\ninv_options_3 = InversionOptions()\ninv_options_3.set_tool(\"emcee\") # Here we use to Affine Invariant McMC sampler from Goodman and Weare (2010).\ninv_options_3.set_params(nwalkers=nwalkers, nsteps=nsteps, progress=True, initial_state=walkers_start)\n\n######## CoFI Inversion - run it\ninv_3 = Inversion(inv_problem, inv_options_3)\ninv_result_3 = inv_3.run()\n\n######## CoFI InversionResult - check result\nprint(f\"The inversion result from `emcee`:\")\ninv_result_3.summary()"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -702,12 +702,12 @@ def log_prior(model): # uniform distribution
######## CoFI BaseProblem - provide additional information
inv_problem.set_log_prior(log_prior)
inv_problem.set_log_likelihood(log_likelihood)
inv_problem.set_walkers_starting_pos(walkers_start)
inv_problem.set_model_shape(ndim)

######## CoFI InversionOptions - get a different tool
inv_options_3 = InversionOptions()
inv_options_3.set_tool("emcee") # Here we use to Affine Invariant McMC sampler from Goodman and Weare (2010).
inv_options_3.set_params(nwalkers=nwalkers, nsteps=nsteps, progress=True)
inv_options_3.set_params(nwalkers=nwalkers, nsteps=nsteps, progress=True, initial_state=walkers_start)

######## CoFI Inversion - run it
inv_3 = Inversion(inv_problem, inv_options_3)
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2cb73ba6d1076e3d54021e6c5ffe7f0c
eb7d98418661f81519e47d3aa3f5881d

Large diffs are not rendered by default.

Binary file not shown.
10,890 changes: 5,445 additions & 5,445 deletions docs/source/examples/generated/field_data/pygimli_dcip_century_tri_mesh.rst

Large diffs are not rendered by default.

Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

Computation times
=================
**04:23.827** total execution time for **examples_generated_field_data** files:
**04:21.481** total execution time for **examples_generated_field_data** files:

+-----------------------------------------------------------------------------------------------------------------------+-----------+--------+
| :ref:`sphx_glr_examples_generated_field_data_linear_regression_sealevel.py` (``linear_regression_sealevel.py``) | 02:35.673 | 0.0 MB |
| :ref:`sphx_glr_examples_generated_field_data_linear_regression_sealevel.py` (``linear_regression_sealevel.py``) | 02:32.564 | 0.0 MB |
+-----------------------------------------------------------------------------------------------------------------------+-----------+--------+
| :ref:`sphx_glr_examples_generated_field_data_pygimli_dcip_century_tri_mesh.py` (``pygimli_dcip_century_tri_mesh.py``) | 01:48.154 | 0.0 MB |
| :ref:`sphx_glr_examples_generated_field_data_pygimli_dcip_century_tri_mesh.py` (``pygimli_dcip_century_tri_mesh.py``) | 01:48.917 | 0.0 MB |
+-----------------------------------------------------------------------------------------------------------------------+-----------+--------+
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
},
"outputs": [],
"source": [
"my_options = cofi.InversionOptions()\n\n# cofi's own simple newton's matrix-based optimization solver\nmy_options.set_tool(\"cofi.simple_newton\")\nmy_options.set_params(max_iterations=6, step_length=1, verbose=True)"
"my_options = cofi.InversionOptions()\n\n# cofi's own simple newton's matrix-based optimization solver\nmy_options.set_tool(\"cofi.simple_newton\")\nmy_options.set_params(num_iterations=6, step_length=1, verbose=True)"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def hessian(slowness, reg, sigma, reduce_data=None): # reduce_data=(idx_f

# cofi's own simple newton's matrix-based optimization solver
my_options.set_tool("cofi.simple_newton")
my_options.set_params(max_iterations=6, step_length=1, verbose=True)
my_options.set_params(num_iterations=6, step_length=1, verbose=True)

######################################################################
#
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ec27105e84301116c44b0e9ce8763399
a49ef5a42993d8cb1fb9e3f4941d107c
10 changes: 5 additions & 5 deletions docs/source/examples/generated/synth_data/fmm_tomography.rst
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ Review what information is included in the ``BaseProblem`` object:
---------------------------------------------------------------------
List of functions/properties that can be further set for the problem:
( not all of these may be relevant to your inversion workflow )
['log_posterior', 'log_posterior_with_blobs', 'log_likelihood', 'log_prior', 'hessian_times_vector', 'residual', 'jacobian', 'jacobian_times_vector', 'data_misfit', 'regularization', 'regularization_matrix', 'regularization_factor', 'forward', 'data', 'data_covariance', 'data_covariance_inv', 'walkers_starting_pos', 'blobs_dtype', 'bounds', 'constraints']
['log_posterior', 'log_posterior_with_blobs', 'log_likelihood', 'log_prior', 'hessian_times_vector', 'residual', 'jacobian', 'jacobian_times_vector', 'data_misfit', 'regularization', 'regularization_matrix', 'regularization_factor', 'forward', 'data', 'data_covariance', 'data_covariance_inv', 'blobs_dtype', 'bounds', 'constraints']
Expand All @@ -423,7 +423,7 @@ Review what information is included in the ``BaseProblem`` object:
# cofi's own simple newton's matrix-based optimization solver
my_options.set_tool("cofi.simple_newton")
my_options.set_params(max_iterations=6, step_length=1, verbose=True)
my_options.set_params(num_iterations=6, step_length=1, verbose=True)
Expand Down Expand Up @@ -459,11 +459,11 @@ Review what’s been defined for the inversion we are about to run:
Use `suggest_solving_methods()` to check available solving methods.
-----------------------------
Backend tool: `cofi.simple_newton` - CoFI's own solver - simple Newton's approach (for testing mainly)
References: ['https://en.wikipedia.org/wiki/Newton%27s_method_in_optimization', 'https://en.wikipedia.org/wiki/Backtracking_line_search']
References: ['https://en.wikipedia.org/wiki/Newton%27s_method_in_optimization']
Use `suggest_tools()` to check available backend tools.
-----------------------------
Solver-specific parameters:
max_iterations = 6
num_iterations = 6
step_length = 1
verbose = True
Use `suggest_solver_params()` to check required/optional solver-specific parameters.
Expand Down Expand Up @@ -608,7 +608,7 @@ sphinx_gallery_thumbnail_number = -1

.. rst-class:: sphx-glr-timing

**Total running time of the script:** ( 0 minutes 7.992 seconds)
**Total running time of the script:** ( 0 minutes 9.712 seconds)


.. _sphx_glr_download_examples_generated_synth_data_fmm_tomography.py:
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@
},
"outputs": [],
"source": [
"######## Provide additional information\ninv_problem.set_log_prior(log_prior)\ninv_problem.set_log_likelihood(log_likelihood)\ninv_problem.set_walkers_starting_pos(walkers_start)\n\n######## Set a different tool\ninv_options_3 = InversionOptions()\ninv_options_3.set_tool(\"emcee\")\ninv_options_3.set_params(nwalkers=nwalkers, nsteps=nsteps)\n\n######## Run it\ninv_3 = Inversion(inv_problem, inv_options_3)\ninv_result_3 = inv_3.run()\n\n######## Check result\nprint(f\"The inversion result from `emcee`:\")\ninv_result_3.summary()"
"######## Provide additional information\ninv_problem.set_log_prior(log_prior)\ninv_problem.set_log_likelihood(log_likelihood)\ninv_problem.set_model_shape(ndim)\n\n######## Set a different tool\ninv_options_3 = InversionOptions()\ninv_options_3.set_tool(\"emcee\")\ninv_options_3.set_params(nwalkers=nwalkers, nsteps=nsteps, initial_state=walkers_start)\n\n######## Run it\ninv_3 = Inversion(inv_problem, inv_options_3)\ninv_result_3 = inv_3.run()\n\n######## Check result\nprint(f\"The inversion result from `emcee`:\")\ninv_result_3.summary()"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -744,12 +744,12 @@ def log_prior(model): # uniform distribution
######## Provide additional information
inv_problem.set_log_prior(log_prior)
inv_problem.set_log_likelihood(log_likelihood)
inv_problem.set_walkers_starting_pos(walkers_start)
inv_problem.set_model_shape(ndim)

######## Set a different tool
inv_options_3 = InversionOptions()
inv_options_3.set_tool("emcee")
inv_options_3.set_params(nwalkers=nwalkers, nsteps=nsteps)
inv_options_3.set_params(nwalkers=nwalkers, nsteps=nsteps, initial_state=walkers_start)

######## Run it
inv_3 = Inversion(inv_problem, inv_options_3)
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
33db0120b2daa10a0b2bd7002bd17a30
8b64a5826889c93ac6d0ca3bb5f3ea3e
26 changes: 13 additions & 13 deletions docs/source/examples/generated/synth_data/linear_regression.rst
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ Recall that the function we are going to fit is:
.. code-block:: none
<matplotlib.legend.Legend object at 0x7fdd1e701660>
<matplotlib.legend.Legend object at 0x7f2d28db09a0>
Expand Down Expand Up @@ -310,7 +310,7 @@ object.
---------------------------------------------------------------------
List of functions/properties that can be further set for the problem:
( not all of these may be relevant to your inversion workflow )
['objective', 'log_posterior', 'log_posterior_with_blobs', 'log_likelihood', 'log_prior', 'gradient', 'hessian', 'hessian_times_vector', 'residual', 'jacobian_times_vector', 'data_misfit', 'regularization', 'regularization_matrix', 'regularization_factor', 'forward', 'data_covariance', 'data_covariance_inv', 'initial_model', 'model_shape', 'walkers_starting_pos', 'blobs_dtype', 'bounds', 'constraints']
['objective', 'log_posterior', 'log_posterior_with_blobs', 'log_likelihood', 'log_prior', 'gradient', 'hessian', 'hessian_times_vector', 'residual', 'jacobian_times_vector', 'data_misfit', 'regularization', 'regularization_matrix', 'regularization_factor', 'forward', 'data_covariance', 'data_covariance_inv', 'initial_model', 'model_shape', 'blobs_dtype', 'bounds', 'constraints']
Expand Down Expand Up @@ -389,7 +389,7 @@ categories of inversion approaches you’d like to use.

.. code-block:: none
Here's a complete list of inversion solvers supported by CoFI (grouped by methods):
Here's a complete list of inversion tools supported by CoFI (grouped by methods):
{
"optimization": [
"scipy.optimize.minimize",
Expand Down Expand Up @@ -478,7 +478,7 @@ function shows available options and set your desired backend solver.
Use `InversionOptions.set_tool(tool_name)` to set a specific tool from above
Use `InversionOptions.set_solving_method(method_name)` to change solving method
Use `InversionOptions.unset_solving_method()` if you'd like to see more options
Check CoFI documentation 'Advanced Usage' section for how to plug in your own solver
Check CoFI documentation 'Advanced Usage' section for how to plug in your own tool or solver
Expand Down Expand Up @@ -578,7 +578,7 @@ and is an engine to actually perform the inversion.
['jacobian_times_vector']
List of functions/properties that can be further set for the problem:
( not all of these may be relevant to your inversion workflow )
['objective', 'log_posterior', 'log_posterior_with_blobs', 'log_likelihood', 'log_prior', 'gradient', 'hessian', 'hessian_times_vector', 'residual', 'jacobian_times_vector', 'data_misfit', 'regularization', 'regularization_matrix', 'regularization_factor', 'forward', 'data_covariance', 'data_covariance_inv', 'initial_model', 'model_shape', 'walkers_starting_pos', 'blobs_dtype', 'bounds', 'constraints']
['objective', 'log_posterior', 'log_posterior_with_blobs', 'log_likelihood', 'log_prior', 'gradient', 'hessian', 'hessian_times_vector', 'residual', 'jacobian_times_vector', 'data_misfit', 'regularization', 'regularization_matrix', 'regularization_factor', 'forward', 'data_covariance', 'data_covariance_inv', 'initial_model', 'model_shape', 'blobs_dtype', 'bounds', 'constraints']
Expand Down Expand Up @@ -718,9 +718,9 @@ any).
['jacobian_times_vector']
List of functions/properties that can be further set for the problem:
( not all of these may be relevant to your inversion workflow )
['objective', 'log_posterior', 'log_posterior_with_blobs', 'log_likelihood', 'log_prior', 'gradient', 'hessian', 'hessian_times_vector', 'residual', 'jacobian_times_vector', 'data_misfit', 'regularization', 'regularization_matrix', 'regularization_factor', 'forward', 'data_covariance', 'data_covariance_inv', 'initial_model', 'model_shape', 'walkers_starting_pos', 'blobs_dtype', 'bounds', 'constraints']
['objective', 'log_posterior', 'log_posterior_with_blobs', 'log_likelihood', 'log_prior', 'gradient', 'hessian', 'hessian_times_vector', 'residual', 'jacobian_times_vector', 'data_misfit', 'regularization', 'regularization_matrix', 'regularization_factor', 'forward', 'data_covariance', 'data_covariance_inv', 'initial_model', 'model_shape', 'blobs_dtype', 'bounds', 'constraints']
List of functions/properties got used by the backend tool:
['data', 'jacobian']
['jacobian', 'data']
Expand Down Expand Up @@ -765,7 +765,7 @@ ground truth.
.. code-block:: none
<matplotlib.legend.Legend object at 0x7fdd02a31a50>
<matplotlib.legend.Legend object at 0x7f2d5580fee0>
Expand Down Expand Up @@ -970,7 +970,7 @@ CoFI.
.. code-block:: none
<matplotlib.legend.Legend object at 0x7fdd1e6fe800>
<matplotlib.legend.Legend object at 0x7f2d30a65f00>
Expand Down Expand Up @@ -1214,12 +1214,12 @@ Finally, we attach all above information to our ``BaseProblem`` and
######## Provide additional information
inv_problem.set_log_prior(log_prior)
inv_problem.set_log_likelihood(log_likelihood)
inv_problem.set_walkers_starting_pos(walkers_start)
inv_problem.set_model_shape(ndim)
######## Set a different tool
inv_options_3 = InversionOptions()
inv_options_3.set_tool("emcee")
inv_options_3.set_params(nwalkers=nwalkers, nsteps=nsteps)
inv_options_3.set_params(nwalkers=nwalkers, nsteps=nsteps, initial_state=walkers_start)
######## Run it
inv_3 = Inversion(inv_problem, inv_options_3)
Expand Down Expand Up @@ -1483,7 +1483,7 @@ posterior ensemble and compare to the data.
.. code-block:: none
<matplotlib.legend.Legend object at 0x7fdd2d5982b0>
<matplotlib.legend.Legend object at 0x7f2d5c77ef80>
Expand Down Expand Up @@ -1656,7 +1656,7 @@ sphinx_gallery_thumbnail_number = -1

.. rst-class:: sphx-glr-timing

**Total running time of the script:** ( 0 minutes 7.269 seconds)
**Total running time of the script:** ( 0 minutes 7.315 seconds)


.. _sphx_glr_download_examples_generated_synth_data_linear_regression.py:
Expand Down
Binary file not shown.
46 changes: 24 additions & 22 deletions docs/source/examples/generated/synth_data/pygimli_dcip.rst
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ the problem in ``cofi`` by setting the problem information for a

.. code-block:: none
Based on what you've provided so far, here are possible solvers:
Based on what you've provided so far, here are possible tools:
{
"optimization": [
"scipy.optimize.minimize",
Expand Down Expand Up @@ -812,26 +812,28 @@ the problem in ``cofi`` by setting the problem information for a

.. code-block:: none
Iteration #0, objective value: 40.95771199605638
Iteration #1, objective value: 33.00676105436523
Iteration #2, objective value: 27.517003420370493
Iteration #3, objective value: 23.856374111765216
Iteration #4, objective value: 21.50039198382915
Iteration #5, objective value: 20.031913540512758
Iteration #6, objective value: 19.94374499736552
Iteration #7, objective value: 19.827200872787692
Iteration #8, objective value: 19.68751418779837
Iteration #9, objective value: 19.529728014788613
Iteration #10, objective value: 19.358622701101357
Iteration #11, objective value: 19.178021476346988
Iteration #12, objective value: 18.990944837951876
Iteration #13, objective value: 18.80075206647256
Iteration #14, objective value: 18.61164377301345
Iteration #15, objective value: 18.428027398821495
Iteration #16, objective value: 18.253580046588773
Iteration #17, objective value: 18.090719054250933
Iteration #18, objective value: 17.940812351147578
Iteration #19, objective value: 17.80478600956866
/home/jiawen/cofi/src/cofi/solvers/base_solver.py:267: UserWarning: the following options are defined but not in parameter list for the chosen tool: ['lr']
warnings.warn(
Iteration #0, objective value: 40.95771199605861
Iteration #1, objective value: 33.006761054365505
Iteration #2, objective value: 27.517003420367388
Iteration #3, objective value: 23.856374111760857
Iteration #4, objective value: 21.50039198382136
Iteration #5, objective value: 20.03191354052629
Iteration #6, objective value: 19.94374499737532
Iteration #7, objective value: 19.827200872779063
Iteration #8, objective value: 19.687514187805156
Iteration #9, objective value: 19.529728014807965
Iteration #10, objective value: 19.35862270111142
Iteration #11, objective value: 19.178021476356154
Iteration #12, objective value: 18.990944837953872
Iteration #13, objective value: 18.800752066476278
Iteration #14, objective value: 18.61164377300838
Iteration #15, objective value: 18.428027398836804
Iteration #16, objective value: 18.253580046609493
Iteration #17, objective value: 18.090719054270597
Iteration #18, objective value: 17.94081235117483
Iteration #19, objective value: 17.804786009588636
Expand Down Expand Up @@ -914,7 +916,7 @@ sphinx_gallery_thumbnail_number = -1

.. rst-class:: sphx-glr-timing

**Total running time of the script:** ( 2 minutes 57.612 seconds)
**Total running time of the script:** ( 3 minutes 4.958 seconds)


.. _sphx_glr_download_examples_generated_synth_data_pygimli_dcip.py:
Expand Down
Binary file not shown.
Loading