Skip to content

Commit 93d6c5a

Browse files
committed
[core] error checking for eta.ada
1 parent ba4776d commit 93d6c5a

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

smcpp/_smcpp.pyx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ aca = np.ascontiguousarray
6262
cdef ParameterVector make_params(a, s, dlist) except *:
6363
cdef ParameterVector ret
6464
cdef vector[adouble] r
65+
assert np.all(a > 0)
6566
assert len(a) > 0
6667
for aa in a:
6768
if not isinstance(aa, ADF):

smcpp/model.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,16 @@ def __call__(self, x):
168168

169169
def match(self, other_model):
170170
a = np.cumsum(self.s)
171+
a0 = np.cumsum(other_model.s)
171172
def f(x):
172173
self[:] = x
173-
return ((self(a).astype('float') - other_model(a).astype('float')) ** 2).sum()
174-
res = scipy.optimize.minimize(f, self[:].astype('float'))
175-
# logger.debug(res)
174+
r1 = ((self(a).astype('float') - other_model(a).astype('float')) ** 2).sum()
175+
r2 = ((self(a0).astype('float') - other_model(a0).astype('float')) ** 2).sum()
176+
return r1 + r2
177+
m = other_model[:].astype('float').min()
178+
M = other_model[:].astype('float').max()
179+
bounds = ((m, M),) * len(self[:])
180+
res = scipy.optimize.minimize(f, self[:].astype('float'), bounds=bounds)
176181
self[:] = res.x
177182

178183
def stepwise_values(self):

0 commit comments

Comments
 (0)