|
1 | | -# odrpack |
| 1 | +# odrpack (-python) |
2 | 2 |
|
3 | 3 | [](https://github.com/HugoMVale/odrpack-python/actions) |
4 | 4 | [](https://codecov.io/gh/HugoMVale/odrpack-python) |
5 | 5 | [](https://img.shields.io/github/last-commit/HugoMVale/odrpack-python) |
6 | 6 |
|
7 | 7 | ## Description |
8 | 8 |
|
9 | | -`odrpack` is a package for weighted orthogonal distance regression (ODR), also known as [errors-in-variables regression]. |
10 | | -It is designed primarily for instances when both the explanatory and response variables have significant errors. |
11 | | -The package implements a highly efficient algorithm for minimizing the sum of the squares of the weighted orthogonal |
12 | | -distances between each data point and the curve described by the model equation, subject to parameter bounds. The nonlinear |
13 | | -model can be either explicit or implicit. Additionally, `odrpack` can be used to solve the ordinary least squares problem where all of |
14 | | -the errors are attributed to the observations of the dependent variable. |
| 9 | +This Python package provides bindings for the well-known weighted orthogonal distance regression |
| 10 | +(ODR) solver [odrpack95]. This design ensures that users benefit from the performance and reliability |
| 11 | +of the original Fortran implementation, while working within the modern Python ecosystem. |
| 12 | + |
| 13 | +ODR, also known as [errors-in-variables regression], is designed primarily for instances when both |
| 14 | +the explanatory and response variables have significant errors. |
15 | 15 |
|
16 | 16 | <p align="center"> |
17 | 17 | <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/8/81/Total_least_squares.svg/220px-Total_least_squares.svg.png" width="200" alt="Deming regression; special case of ODR."> |
18 | 18 | </p> |
19 | 19 |
|
20 | 20 | [errors-in-variables regression]: https://en.wikipedia.org/wiki/Errors-in-variables_models |
21 | | - |
22 | | -## Python Bindings for Fortran Implementation |
23 | | - |
24 | | -The `odrpack` Python package provides convient bindings for the efficient ODR solver available |
25 | | -in the Fortran [odrpack95] repository. This design ensures that users benefit from the performance |
26 | | -and reliability of the original Fortran implementation, while working within the modern Python |
27 | | -ecosystem. |
28 | | - |
29 | 21 | [odrpack95]: https://github.com/HugoMVale/odrpack95 |
30 | 22 |
|
31 | 23 |
|
@@ -55,23 +47,13 @@ def f(beta: np.ndarray, x: np.ndarray) -> np.ndarray: |
55 | 47 | return beta[0] * np.exp(beta[1]*x) |
56 | 48 |
|
57 | 49 |
|
58 | | -def fjacb(beta: np.ndarray, x: np.ndarray) -> np.ndarray: |
59 | | - "Model jacobian w.r.t. the model parameters." |
60 | | - jac = np.zeros((beta.size, x.size)) |
61 | | - jac[0, :] = np.exp(beta[1]*x) |
62 | | - jac[1, :] = beta[0]*x*np.exp(beta[1]*x) |
63 | | - return jac |
64 | | - |
65 | | - |
66 | | -def fjacd(beta: np.ndarray, x: np.ndarray) -> np.ndarray: |
67 | | - "Model jacobian w.r.t. the error in the explanatory variable." |
68 | | - return beta[0] * beta[1] * np.exp(beta[1]*x) |
69 | | - |
70 | | - |
71 | | -sol = odr(f, beta0, y, x, lower=lower, upper=upper, |
72 | | - fjacb=fjacb, fjacd=fjacd, |
73 | | - job=20, iprint=1001) |
| 50 | +sol = odr(f, beta0, y, x, lower=lower, upper=upper, iprint=1001) |
74 | 51 |
|
75 | 52 | print("\n beta:", sol.beta) |
76 | 53 | print("\n delta:", sol.delta) |
| 54 | +``` |
| 55 | + |
| 56 | +```sh |
| 57 | +beta: [1.63337057 0.9 ] |
| 58 | +delta: [-0.36885787 -0.31272733 0.02928942 0.11031791] |
77 | 59 | ``` |
0 commit comments