Skip to content

Commit bc24486

Browse files
committed
raise ValueError if the the number of regression points is less than the number of parameters in _residual
1 parent 6fdc0af commit bc24486

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

news/enough-regression-points.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* Raise ``ValueError`` if the number of shared grid points between morphed and target functions is less than the number of parameters.
4+
5+
**Changed:**
6+
7+
* <news item>
8+
9+
**Deprecated:**
10+
11+
* <news item>
12+
13+
**Removed:**
14+
15+
* <news item>
16+
17+
**Fixed:**
18+
19+
* <news item>
20+
21+
**Security:**
22+
23+
* <news item>

src/diffpy/morph/refine.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,13 @@ def _residual(self, pvals):
8383
self.x_morph, self.y_morph, self.x_target, self.y_target
8484
)
8585
rvec = _y_target - _y_morph
86-
86+
if len(rvec) < len(pvals):
87+
raise ValueError(
88+
"Not enough shared grid points between morphed function "
89+
"and target function to fit the chosen parameters. "
90+
"Please adjust the functions or "
91+
"reduce the number of parameters."
92+
)
8793
# If first time computing residual
8894
if self.res_length is None:
8995
self.res_length = len(rvec)
@@ -145,6 +151,9 @@ def refine(self, *args, **kw):
145151
------
146152
ValueError
147153
Exception raised if a minimum cannot be found.
154+
ValueError
155+
If the number of shared grid points between morphed function and
156+
target function is smaller than the number of parameters.
148157
"""
149158

150159
self.pars = args or self.chain.config.keys()

0 commit comments

Comments
 (0)