Skip to content

Commit 5eb0349

Browse files
authored
Merge pull request #1 from HugoMVale/odr_fit
add `odr_fit`, a new interface inspired from scipy.optimize.curve_fit
2 parents 90685c9 + 577143b commit 5eb0349

20 files changed

Lines changed: 1613 additions & 356 deletions

.github/workflows/build-wheels.yml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -85,23 +85,23 @@ jobs:
8585
name: cibw-sdist
8686
path: dist/*.tar.gz
8787

88-
upload_pypi:
89-
name: Publish to PyPI
90-
needs: [build_wheels, build_sdist]
91-
runs-on: ubuntu-latest
92-
environment:
93-
name: pypi
94-
permissions:
95-
id-token: write
96-
# if: github.event_name == 'release' && github.event.action == 'published'
97-
steps:
98-
- uses: actions/download-artifact@v4
99-
with:
100-
pattern: cibw-*
101-
path: dist
102-
merge-multiple: true
88+
# upload_pypi:
89+
# name: Publish to PyPI
90+
# needs: [build_wheels, build_sdist]
91+
# runs-on: ubuntu-latest
92+
# environment:
93+
# name: pypi
94+
# permissions:
95+
# id-token: write
96+
# # if: github.event_name == 'release' && github.event.action == 'published'
97+
# steps:
98+
# - uses: actions/download-artifact@v4
99+
# with:
100+
# pattern: cibw-*
101+
# path: dist
102+
# merge-multiple: true
103103

104-
- uses: pypa/gh-action-pypi-publish@release/v1
104+
# - uses: pypa/gh-action-pypi-publish@release/v1
105105

106106
# upload_test_pypi:
107107
# name: Publish to TestPyPI

docs/examples/explicit-model.ipynb

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"import matplotlib.pyplot as plt\n",
3030
"import numpy as np\n",
3131
"\n",
32-
"from odrpack import odr"
32+
"from odrpack import odr_fit"
3333
]
3434
},
3535
{
@@ -45,19 +45,19 @@
4545
"metadata": {},
4646
"outputs": [],
4747
"source": [
48-
"x = np.array([0.100, 0.300, 0.400, 0.500, 0.600, 0.700, 0.800])\n",
49-
"y = np.array([0.059, 0.243, 0.364, 0.486, 0.583, 0.721, 0.824])"
48+
"xdata = np.array([0.100, 0.300, 0.400, 0.500, 0.600, 0.700, 0.800])\n",
49+
"ydata = np.array([0.059, 0.243, 0.364, 0.486, 0.583, 0.721, 0.824])"
5050
]
5151
},
5252
{
5353
"cell_type": "code",
54-
"execution_count": 3,
54+
"execution_count": null,
5555
"metadata": {},
5656
"outputs": [],
5757
"source": [
5858
"def f(beta: np.ndarray, x: np.ndarray) -> np.ndarray:\n",
5959
" b1, b2 = beta\n",
60-
" return (b1*x**2 + x*(1-x))/(b1*x**2 + 2*x*(1-x) + b2*(1-x)**2)"
60+
" return (b1*x**2 + x*(1 - x))/(b1*x**2 + 2*x*(1 - x) + b2*(1 - x)**2)"
6161
]
6262
},
6363
{
@@ -95,15 +95,15 @@
9595
"sigma_x = 0.01\n",
9696
"sigma_y = 0.05\n",
9797
"\n",
98-
"wd = 1/sigma_x**2\n",
99-
"we = 1/sigma_y**2"
98+
"weight_x = 1/sigma_x**2\n",
99+
"weight_y = 1/sigma_y**2"
100100
]
101101
},
102102
{
103103
"cell_type": "markdown",
104104
"metadata": {},
105105
"source": [
106-
"We can now launch the regression! If you want to see a brief computation report, set `iprint=1001`."
106+
"We can now launch the regression! If you want to see a brief computation report, set `report='short'`."
107107
]
108108
},
109109
{
@@ -112,7 +112,9 @@
112112
"metadata": {},
113113
"outputs": [],
114114
"source": [
115-
"sol = odr(f, beta0, y, x, lower=lower, upper=upper, we=we, wd=wd)"
115+
"sol = odr_fit(f, xdata, ydata, beta0,\n",
116+
" bounds=(lower, upper),\n",
117+
" weight_x=weight_x, weight_y=weight_y)"
116118
]
117119
},
118120
{
@@ -199,7 +201,7 @@
199201
"_, ax = plt.subplots()\n",
200202
"\n",
201203
"# Plot experimental data\n",
202-
"ax.plot(x, y, 'o')\n",
204+
"ax.plot(xdata, ydata, 'o')\n",
203205
"\n",
204206
"# Plot fitted model\n",
205207
"xm = np.linspace(0.0, 1.0, 100)\n",

docs/examples/implicit-model.ipynb

Lines changed: 14 additions & 11 deletions
Large diffs are not rendered by default.

docs/reference/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
:::odrpack
22
options:
33
members:
4-
- odr
4+
- odr_fit
55
- OdrResult
66
- OdrStop

meson.build

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
project(
22
'odrpack',
33
['cpp'],
4-
version : '0.2.0',
4+
version : '0.3.0',
55
meson_version: '>=1.5.0',
66
default_options: [
77
'buildtype=release',
@@ -36,11 +36,12 @@ nanobind_ext = python.extension_module(
3636
python.install_sources(
3737
[
3838
'src/odrpack/__init__.py',
39-
'src/odrpack/driver.py',
39+
'src/odrpack/__odrpack.pyi',
40+
'src/odrpack/odr_fortran.py',
41+
'src/odrpack/odr_scipy.py',
4042
'src/odrpack/exceptions.py',
4143
'src/odrpack/result.py',
4244
'src/odrpack/py.typed',
43-
'src/odrpack/__odrpack.pyi',
4445
],
4546
subdir: 'odrpack'
4647
)

src/odrpack/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
to the observations of the dependent variable.
1010
"""
1111

12-
__version__ = '0.2.0'
12+
__version__ = '0.3.0'
1313

14-
from odrpack.driver import *
1514
from odrpack.exceptions import *
15+
from odrpack.odr_fortran import *
16+
from odrpack.odr_scipy import *
1617
from odrpack.result import *

0 commit comments

Comments
 (0)