@@ -163,7 +163,7 @@ def chiexp(self, yobs, pdict, p0, plot, errinfo):
163
163
164
164
w , v = numpy .linalg .eig (self .Hmat (pdict , p0 ))
165
165
mask = w != 0
166
- pyobs .assertion (sum (numpy .abs (w )> 1e-16 ) == len (w ), "Badly conditioned system" )
166
+ pyobs .assertion (sum (numpy .abs (w ) > 1e-16 ) == len (w ), "Badly conditioned system" )
167
167
winv = w
168
168
winv [mask ] = 1 / w [mask ]
169
169
Hinv = v @ numpy .diag (winv ) @ v .T
@@ -175,8 +175,8 @@ def chiexp(self, yobs, pdict, p0, plot, errinfo):
175
175
chiexp = yobs @ v
176
176
_ , ce , dce = chiexp .error_core (plot = plot , errinfo = errinfo , pfile = None )
177
177
return w @ ce , w @ dce
178
-
179
-
178
+
179
+
180
180
class mfit :
181
181
r"""
182
182
Class to perform fits to multiple observables, via the minimization
@@ -277,7 +277,6 @@ def __add__(self, mf):
277
277
n += 1
278
278
return res
279
279
280
-
281
280
def check_yobs (self , yobs ):
282
281
if len (self .csq ) > 1 :
283
282
pyobs .check_type (yobs , "yobs" , list )
@@ -289,11 +288,11 @@ def check_yobs(self, yobs):
289
288
f"Unexpected number of observables for { len (self .csq )} fits" ,
290
289
)
291
290
return yobs
292
-
291
+
293
292
@pyobs .log_timer ("mfit" )
294
293
def __call__ (self , yobs , p0 = None , min_search = None ):
295
294
yobs = self .check_yobs (yobs )
296
-
295
+
297
296
if p0 is None :
298
297
p0 = [1.0 ] * len (self .pdict )
299
298
if min_search is None :
@@ -349,43 +348,44 @@ def chisquared(self, pars):
349
348
350
349
def chiexp (self , yobs , pars , plot = False , errinfo = {}):
351
350
yobs = self .check_yobs (yobs )
352
-
351
+
353
352
ce , dce = 0 , 0
354
353
for i in range (len (self .csq )):
355
354
tmp = self .csq [i ].chiexp (yobs [i ], self .pdict , pars .mean , plot , errinfo )
356
355
ce += tmp [0 ]
357
356
dce += tmp [1 ] ** 2
358
357
return ce , dce ** 0.5
359
358
360
-
361
359
def pvalue (self , rng , yobs , errinfo , plot = False , nmc = 10000 ):
362
- yobs = self .check_yobs (yobs )
360
+ yobs = self .check_yobs (yobs )
363
361
364
362
cexp = numpy .zeros (nmc )
365
363
for i in range (len (self .csq )):
366
364
n = self .csq [i ].n
367
-
365
+
368
366
C = yobs [i ].covariance_matrix (errinfo )[0 ]
369
367
w , _ = numpy .linalg .eig (C @ self .csq [i ].PP )
370
368
w -= self .c2 / n
371
-
372
- cexp += rng .sample_normal (n * nmc ).reshape (nmc ,n ) ** 2 @ w
373
-
369
+
370
+ cexp += rng .sample_normal (n * nmc ).reshape (nmc , n ) ** 2 @ w
371
+
374
372
th = numpy .array (cexp ) < 0.0
375
373
p = 1.0 - numpy .mean (th )
376
- dp = numpy .std (th ,ddof = 1 )/ (nmc )** 0.5
377
-
374
+ dp = numpy .std (th , ddof = 1 ) / (nmc ) ** 0.5
375
+
378
376
if plot :
379
377
plt .figure ()
380
- plt .title (f' p-value = { p :.2f} +- { dp :.2f} ' )
381
- h = plt .hist (cexp + self .c2 , density = True , bins = 40 , label = 'MC' )
378
+ plt .title (f" p-value = { p :.2f} +- { dp :.2f} " )
379
+ h = plt .hist (cexp + self .c2 , density = True , bins = 40 , label = "MC" )
382
380
if h :
383
- plt .plot ([self .c2 ,self .c2 ], [0 ,max (h [0 ])], label = r'$\chi^2$' )
384
- plt .plot ([self .ce ,self .ce ], [0 ,max (h [0 ])], label = r'$\chi_\mathrm{exp}$' )
381
+ plt .plot ([self .c2 , self .c2 ], [0 , max (h [0 ])], label = r"$\chi^2$" )
382
+ plt .plot (
383
+ [self .ce , self .ce ], [0 , max (h [0 ])], label = r"$\chi_\mathrm{exp}$"
384
+ )
385
385
plt .legend ()
386
-
386
+
387
387
return [p , dp , cexp ]
388
-
388
+
389
389
def eval (self , xax , pars ):
390
390
"""
391
391
Evaluates the function on a list of coordinates using the parameters
0 commit comments