|
29 | 29 | "import matplotlib.pyplot as plt\n", |
30 | 30 | "import numpy as np\n", |
31 | 31 | "\n", |
32 | | - "from odrpack import odr" |
| 32 | + "from odrpack import odr_fit" |
33 | 33 | ] |
34 | 34 | }, |
35 | 35 | { |
|
45 | 45 | "metadata": {}, |
46 | 46 | "outputs": [], |
47 | 47 | "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])" |
50 | 50 | ] |
51 | 51 | }, |
52 | 52 | { |
53 | 53 | "cell_type": "code", |
54 | | - "execution_count": 3, |
| 54 | + "execution_count": null, |
55 | 55 | "metadata": {}, |
56 | 56 | "outputs": [], |
57 | 57 | "source": [ |
58 | 58 | "def f(beta: np.ndarray, x: np.ndarray) -> np.ndarray:\n", |
59 | 59 | " 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)" |
61 | 61 | ] |
62 | 62 | }, |
63 | 63 | { |
|
95 | 95 | "sigma_x = 0.01\n", |
96 | 96 | "sigma_y = 0.05\n", |
97 | 97 | "\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" |
100 | 100 | ] |
101 | 101 | }, |
102 | 102 | { |
103 | 103 | "cell_type": "markdown", |
104 | 104 | "metadata": {}, |
105 | 105 | "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'`." |
107 | 107 | ] |
108 | 108 | }, |
109 | 109 | { |
|
112 | 112 | "metadata": {}, |
113 | 113 | "outputs": [], |
114 | 114 | "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)" |
116 | 118 | ] |
117 | 119 | }, |
118 | 120 | { |
|
199 | 201 | "_, ax = plt.subplots()\n", |
200 | 202 | "\n", |
201 | 203 | "# Plot experimental data\n", |
202 | | - "ax.plot(x, y, 'o')\n", |
| 204 | + "ax.plot(xdata, ydata, 'o')\n", |
203 | 205 | "\n", |
204 | 206 | "# Plot fitted model\n", |
205 | 207 | "xm = np.linspace(0.0, 1.0, 100)\n", |
|
0 commit comments