@@ -53,8 +53,8 @@ def testFixFree(self):
53
53
recipe = self .recipe
54
54
con = self .fitcontribution
55
55
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" )
58
58
recipe .addVar (con .c , 0 )
59
59
recipe .newVar ("B" , 0 )
60
60
@@ -78,7 +78,7 @@ def testFixFree(self):
78
78
self .assertTrue (recipe .isFree (recipe .k ))
79
79
self .assertTrue (recipe .isFree (recipe .c ))
80
80
self .assertTrue (recipe .isFree (recipe .B ))
81
- recipe .fix (recipe .A , "tagk" , c = 3 )
81
+ recipe .fix (recipe .A , "tagk" , c = 3 )
82
82
self .assertFalse (recipe .isFree (recipe .A ))
83
83
self .assertFalse (recipe .isFree (recipe .k ))
84
84
self .assertFalse (recipe .isFree (recipe .c ))
@@ -91,7 +91,7 @@ def testFixFree(self):
91
91
self .assertFalse (recipe .isFree (recipe .B ))
92
92
93
93
self .assertRaises (ValueError , recipe .free , "junk" )
94
- self .assertRaises (ValueError , recipe .fix , tagA = 1 )
94
+ self .assertRaises (ValueError , recipe .fix , tagA = 1 )
95
95
self .assertRaises (ValueError , recipe .fix , "junk" )
96
96
return
97
97
@@ -143,7 +143,6 @@ def testVars(self):
143
143
self .assertTrue (2 in values )
144
144
return
145
145
146
-
147
146
def testResidual (self ):
148
147
"""Test the residual and everything that can change it."""
149
148
@@ -156,13 +155,13 @@ def testResidual(self):
156
155
y = sin (x + 1 )
157
156
self .recipe .cont .c .setValue (1 )
158
157
res = self .recipe .residual ()
159
- self .assertTrue ( array_equal (y - self .profile .y , res ) )
158
+ self .assertTrue (array_equal (y - self .profile .y , res ))
160
159
161
160
# Try some constraints
162
161
# Make c = 2*A, A = Avar
163
162
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 })
166
165
self .assertEqual (2 , self .fitcontribution .c .value )
167
166
self .recipe .constrain (self .fitcontribution .A , var )
168
167
self .assertEqual (1 , var .getValue ())
@@ -173,39 +172,39 @@ def testResidual(self):
173
172
x = self .profile .x
174
173
y = sin (x + 2 )
175
174
res = self .recipe .residual ()
176
- self .assertTrue ( array_equal (y - self .profile .y , res ) )
175
+ self .assertTrue (array_equal (y - self .profile .y , res ))
177
176
178
177
# Now try some restraints. We want c to be exactly zero. It should give
179
178
# a penalty of (c-0)**2, which is 4 in this case
180
179
r1 = self .recipe .restrain (self .fitcontribution .c , 0 , 0 , 1 )
181
180
self .recipe ._ready = False
182
181
res = self .recipe .residual ()
183
182
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 ))
185
184
186
185
# Clear the constraint and restore the value of c to 0. This should
187
186
# give us chi2 = 0 again.
188
187
self .recipe .unconstrain (self .fitcontribution .c )
189
188
self .fitcontribution .c .setValue (0 )
190
189
res = self .recipe .residual ([self .recipe .cont .A .getValue ()])
191
190
chi2 = 0
192
- self .assertAlmostEqual (chi2 , dot (res , res ) )
191
+ self .assertAlmostEqual (chi2 , dot (res , res ))
193
192
194
193
# Remove the restraint and variable
195
194
self .recipe .unrestrain (r1 )
196
195
self .recipe .delVar (self .recipe .Avar )
197
196
self .recipe ._ready = False
198
197
res = self .recipe .residual ()
199
198
chi2 = 0
200
- self .assertAlmostEqual (chi2 , dot (res , res ) )
199
+ self .assertAlmostEqual (chi2 , dot (res , res ))
201
200
202
201
# Add constraints at the fitcontribution level.
203
202
self .fitcontribution .constrain (self .fitcontribution .c , "2*A" )
204
203
# This should evaluate to sin(x+2)
205
204
x = self .profile .x
206
205
y = sin (x + 2 )
207
206
res = self .recipe .residual ()
208
- self .assertTrue ( array_equal (y - self .profile .y , res ) )
207
+ self .assertTrue (array_equal (y - self .profile .y , res ))
209
208
210
209
# Add a restraint at the fitcontribution level.
211
210
r1 = self .fitcontribution .restrain (self .fitcontribution .c , 0 , 0 , 1 )
@@ -215,7 +214,7 @@ def testResidual(self):
215
214
x = self .profile .x
216
215
y = sin (x + 2 )
217
216
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 ))
219
218
220
219
# Remove those
221
220
self .fitcontribution .unrestrain (r1 )
@@ -224,7 +223,7 @@ def testResidual(self):
224
223
self .fitcontribution .c .setValue (0 )
225
224
res = self .recipe .residual ()
226
225
chi2 = 0
227
- self .assertAlmostEqual (chi2 , dot (res , res ) )
226
+ self .assertAlmostEqual (chi2 , dot (res , res ))
228
227
229
228
# Now try to use the observed profile inside of the equation
230
229
# Set the equation equal to the data
@@ -239,7 +238,6 @@ def testResidual(self):
239
238
240
239
return
241
240
242
-
243
241
def testPrintFitHook (self ):
244
242
"check output from default PrintFitHook."
245
243
self .recipe .addVar (self .fitcontribution .c )
@@ -266,5 +264,6 @@ def testPrintFitHook(self):
266
264
267
265
# ----------------------------------------------------------------------------
268
266
267
+
269
268
if __name__ == "__main__" :
270
269
unittest .main ()
0 commit comments