@@ -1142,6 +1142,53 @@ def func(a, x):
11421142 assert cd [0 ] != cd [0 ] # Check for nan
11431143 assert np .all (np .array (cd [1 :]) > 0 )
11441144
1145+ N = 5
1146+
1147+ def fitf (a , x ):
1148+ return a [0 ] + 0 * x
1149+
1150+ def fitf_multi (a , x ):
1151+ return a [0 ] + 0 * x [0 ] + 0 * x [1 ]
1152+
1153+ for priors in [None , [pe .cov_Obs (3 , 1 , 'p' )]]:
1154+ if priors is None :
1155+ lp = 0
1156+ else :
1157+ lp = len (priors )
1158+ x = [1. for i in range (N )]
1159+ y = [pe .cov_Obs (i , .1 , '%d' % (i )) for i in range (N )]
1160+ [o .gm () for o in y ]
1161+ res = pe .fits .least_squares (x , y , fitf , expected_chisquare = True , priors = priors )
1162+ assert (res .dof == N - 1 + lp )
1163+ if priors is None :
1164+ assert (np .isclose (res .chisquare_by_expected_chisquare , res .chisquare_by_dof ))
1165+
1166+ kl = ['a' , 'b' ]
1167+ x = {k : [1. for i in range (N )] for k in kl }
1168+ y = {k : [pe .cov_Obs (i , .1 , '%d%s' % (i , k )) for i in range (N )] for k in kl }
1169+ [[o .gm () for o in y [k ]] for k in y ]
1170+ res = pe .fits .least_squares (x , y , {k : fitf for k in kl }, expected_chisquare = True , priors = priors )
1171+ assert (res .dof == 2 * N - 1 + lp )
1172+ if priors is None :
1173+ assert (np .isclose (res .chisquare_by_expected_chisquare , res .chisquare_by_dof ))
1174+
1175+ x = np .array ([[1. , 2. ] for i in range (N )]).T
1176+ y = [pe .cov_Obs (i , .1 , '%d' % (i )) for i in range (N )]
1177+ [o .gm () for o in y ]
1178+ res = pe .fits .least_squares (x , y , fitf_multi , expected_chisquare = True , priors = priors )
1179+ assert (res .dof == N - 1 + lp )
1180+ if priors is None :
1181+ assert (np .isclose (res .chisquare_by_expected_chisquare , res .chisquare_by_dof ))
1182+
1183+ x = {k : np .array ([[1. , 2. ] for i in range (N )]).T for k in kl }
1184+ y = {k : [pe .cov_Obs (i , .1 , '%d%s' % (i , k )) for i in range (N )] for k in kl }
1185+ [[o .gm () for o in y [k ]] for k in y ]
1186+ res = pe .fits .least_squares (x , y , {k : fitf_multi for k in kl }, expected_chisquare = True , priors = priors )
1187+
1188+ assert (res .dof == 2 * N - 1 + lp )
1189+ if priors is None :
1190+ assert (np .isclose (res .chisquare_by_expected_chisquare , res .chisquare_by_dof ))
1191+
11451192
11461193def test_combined_fit_constant_shape ():
11471194 N1 = 16
0 commit comments