Skip to content

Commit d7700de

Browse files
author
Jack Doughty
committed
updates docs & new unit test
1 parent 3ac77ed commit d7700de

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

doc/fitting/fitting.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ See the following example on how to define these.
111111

112112
import lmfit
113113

114-
def model(x: float, m: float, c: float) -> float:
114+
def model(x: float, c1: float, c0: float) -> float:
115115

116-
return m * x + c # y = mx + c
116+
return c1 * x + c0 # y = mx + c
117117

118118
def guess(x: npt.NDArray[np.float64], y: npt.NDArray[np.float64]) -> dict[str, lmfit.Parameter]:
119119

@@ -125,12 +125,12 @@ def guess(x: npt.NDArray[np.float64], y: npt.NDArray[np.float64]) -> dict[str, l
125125
numerator = sum(x * y) - sum(x) * sum(y)
126126
denominator = sum(x**2) - sum(x) ** 2
127127

128-
m = numerator / denominator
129-
c = (sum(y) - m * sum(x)) / len(x)
128+
c1 = numerator / denominator
129+
c0 = (sum(y) - c1 * sum(x)) / len(x)
130130

131131
init_guess = {
132-
"m": lmfit.Parameter("m", m), # gradient
133-
"c": lmfit.Parameter("c", c), # y - intercept
132+
"c1": lmfit.Parameter("c1", c1), # gradient
133+
"c0": lmfit.Parameter("c0", c0), # y - intercept
134134
}
135135

136136
return init_guess
@@ -155,9 +155,9 @@ This means that aslong as the parameters returned from the guess function match
155155
import lmfit
156156
from ibex_bluesky_core.callbacks.fitting.fitting_utils import Linear
157157

158-
def different_model(x: float, m: float, c: float) -> float:
158+
def different_model(x: float, c1: float, c0: float) -> float:
159159

160-
return m * x + c ** 2 # y = mx + (c ** 2)
160+
return c1 * x + c0 ** 2 # y = mx + (c ** 2)
161161

162162

163163
fit_method = FitMethod(different_model, Linear.guess())
@@ -179,8 +179,8 @@ from ibex_bluesky_core.callbacks.fitting.fitting_utils import Linear
179179
def different_guess(x: float, m: float, c: float) -> float:
180180

181181
init_guess = {
182-
"m": lmfit.Parameter("m", 1), # gradient
183-
"c": lmfit.Parameter("c", 0), # y - intercept
182+
"c1": lmfit.Parameter("c1", 1), # gradient
183+
"c0": lmfit.Parameter("c0", 0), # y - intercept
184184
}
185185

186186
return init_guess

doc/fitting/standard_fits.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22

33
## Linear
44

5-
- `m` - Gradient
6-
- `c` - (y) Intercept
5+
- `c1` - Gradient
6+
- `c0` - (y) Intercept
77

88
```{math}
9-
y = mx + c
9+
y = c_1x + c_0
1010
```
1111

1212
## Polynomial
1313

14-
- `a` ... `d` - Polynomial coefficients
14+
- `cn` ... `c0` - Polynomial coefficients
1515

1616
For a polynomial degree `n`:
1717
```{math}
18-
y = ax^n + bx^n-1 + ... + cx^1 + d
18+
y = c_{n}x^n + c_{n-1}x^n-1 + ... + c_1 * x^1 + c_0
1919
```
2020

2121
## Gaussian

tests/callbacks/fitting/test_fitting_methods.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,13 @@ def test_y_intercept_guess(self):
248248

249249
assert pytest.approx(outp["c0"]) == 0.0
250250

251+
def test_zero_gradient_guess(self):
252+
x = np.array([-1.0, 0.0, 1.0])
253+
y = np.array([0.0, 0.0, 0.0])
254+
outp = Linear.guess()(x, y)
255+
256+
assert pytest.approx(outp["c1"]) == 0.0
257+
251258

252259
class TestPolynomial:
253260
class TestPolynomialModel:

0 commit comments

Comments
 (0)