@@ -53,8 +53,8 @@ def testFixFree(self):
5353 recipe = self .recipe
5454 con = self .fitcontribution
5555
56- recipe .addVar (con .A , 2 , tag = "tagA" )
57- recipe .addVar (con .k , 1 , tag = "tagk" )
56+ recipe .addVar (con .A , 2 , tag = "tagA" )
57+ recipe .addVar (con .k , 1 , tag = "tagk" )
5858 recipe .addVar (con .c , 0 )
5959 recipe .newVar ("B" , 0 )
6060
@@ -78,7 +78,7 @@ def testFixFree(self):
7878 self .assertTrue (recipe .isFree (recipe .k ))
7979 self .assertTrue (recipe .isFree (recipe .c ))
8080 self .assertTrue (recipe .isFree (recipe .B ))
81- recipe .fix (recipe .A , "tagk" , c = 3 )
81+ recipe .fix (recipe .A , "tagk" , c = 3 )
8282 self .assertFalse (recipe .isFree (recipe .A ))
8383 self .assertFalse (recipe .isFree (recipe .k ))
8484 self .assertFalse (recipe .isFree (recipe .c ))
@@ -91,7 +91,7 @@ def testFixFree(self):
9191 self .assertFalse (recipe .isFree (recipe .B ))
9292
9393 self .assertRaises (ValueError , recipe .free , "junk" )
94- self .assertRaises (ValueError , recipe .fix , tagA = 1 )
94+ self .assertRaises (ValueError , recipe .fix , tagA = 1 )
9595 self .assertRaises (ValueError , recipe .fix , "junk" )
9696 return
9797
@@ -143,7 +143,6 @@ def testVars(self):
143143 self .assertTrue (2 in values )
144144 return
145145
146-
147146 def testResidual (self ):
148147 """Test the residual and everything that can change it."""
149148
@@ -156,13 +155,13 @@ def testResidual(self):
156155 y = sin (x + 1 )
157156 self .recipe .cont .c .setValue (1 )
158157 res = self .recipe .residual ()
159- self .assertTrue ( array_equal (y - self .profile .y , res ) )
158+ self .assertTrue (array_equal (y - self .profile .y , res ))
160159
161160 # Try some constraints
162161 # Make c = 2*A, A = Avar
163162 var = self .recipe .newVar ("Avar" )
164- self .recipe .constrain (self .fitcontribution .c , "2*A" ,
165- { "A" : self .fitcontribution .A })
163+ self .recipe .constrain (self .fitcontribution .c ,
164+ "2*A" , { "A" : self .fitcontribution .A })
166165 self .assertEqual (2 , self .fitcontribution .c .value )
167166 self .recipe .constrain (self .fitcontribution .A , var )
168167 self .assertEqual (1 , var .getValue ())
@@ -173,39 +172,39 @@ def testResidual(self):
173172 x = self .profile .x
174173 y = sin (x + 2 )
175174 res = self .recipe .residual ()
176- self .assertTrue ( array_equal (y - self .profile .y , res ) )
175+ self .assertTrue (array_equal (y - self .profile .y , res ))
177176
178177 # Now try some restraints. We want c to be exactly zero. It should give
179178 # a penalty of (c-0)**2, which is 4 in this case
180179 r1 = self .recipe .restrain (self .fitcontribution .c , 0 , 0 , 1 )
181180 self .recipe ._ready = False
182181 res = self .recipe .residual ()
183182 chi2 = 4 + dot (y - self .profile .y , y - self .profile .y )
184- self .assertAlmostEqual (chi2 , dot (res , res ) )
183+ self .assertAlmostEqual (chi2 , dot (res , res ))
185184
186185 # Clear the constraint and restore the value of c to 0. This should
187186 # give us chi2 = 0 again.
188187 self .recipe .unconstrain (self .fitcontribution .c )
189188 self .fitcontribution .c .setValue (0 )
190189 res = self .recipe .residual ([self .recipe .cont .A .getValue ()])
191190 chi2 = 0
192- self .assertAlmostEqual (chi2 , dot (res , res ) )
191+ self .assertAlmostEqual (chi2 , dot (res , res ))
193192
194193 # Remove the restraint and variable
195194 self .recipe .unrestrain (r1 )
196195 self .recipe .delVar (self .recipe .Avar )
197196 self .recipe ._ready = False
198197 res = self .recipe .residual ()
199198 chi2 = 0
200- self .assertAlmostEqual (chi2 , dot (res , res ) )
199+ self .assertAlmostEqual (chi2 , dot (res , res ))
201200
202201 # Add constraints at the fitcontribution level.
203202 self .fitcontribution .constrain (self .fitcontribution .c , "2*A" )
204203 # This should evaluate to sin(x+2)
205204 x = self .profile .x
206205 y = sin (x + 2 )
207206 res = self .recipe .residual ()
208- self .assertTrue ( array_equal (y - self .profile .y , res ) )
207+ self .assertTrue (array_equal (y - self .profile .y , res ))
209208
210209 # Add a restraint at the fitcontribution level.
211210 r1 = self .fitcontribution .restrain (self .fitcontribution .c , 0 , 0 , 1 )
@@ -215,7 +214,7 @@ def testResidual(self):
215214 x = self .profile .x
216215 y = sin (x + 2 )
217216 chi2 = 4 + dot (y - self .profile .y , y - self .profile .y )
218- self .assertAlmostEqual (chi2 , dot (res , res ) )
217+ self .assertAlmostEqual (chi2 , dot (res , res ))
219218
220219 # Remove those
221220 self .fitcontribution .unrestrain (r1 )
@@ -224,7 +223,7 @@ def testResidual(self):
224223 self .fitcontribution .c .setValue (0 )
225224 res = self .recipe .residual ()
226225 chi2 = 0
227- self .assertAlmostEqual (chi2 , dot (res , res ) )
226+ self .assertAlmostEqual (chi2 , dot (res , res ))
228227
229228 # Now try to use the observed profile inside of the equation
230229 # Set the equation equal to the data
@@ -239,7 +238,6 @@ def testResidual(self):
239238
240239 return
241240
242-
243241 def testPrintFitHook (self ):
244242 "check output from default PrintFitHook."
245243 self .recipe .addVar (self .fitcontribution .c )
@@ -266,5 +264,6 @@ def testPrintFitHook(self):
266264
267265# ----------------------------------------------------------------------------
268266
267+
269268if __name__ == "__main__" :
270269 unittest .main ()
0 commit comments