Index: trunk/fundraiser-statistics/fundraiser-scripts/compute_confidence.py |
— | — | @@ -202,18 +202,23 @@ |
203 | 203 | pylab.title(title) |
204 | 204 | pylab.savefig(fname, format='png') |
205 | 205 | |
| 206 | + |
| 207 | + """ |
| 208 | + ConfidenceTesting :: run_test |
206 | 209 | |
| 210 | + Executes the confidence test - prints and plots the results |
| 211 | + """ |
207 | 212 | def run_test(self, test_name, query_name, metric_name, campaign, item_1, item_2, start_time, end_time, interval, num_samples): |
208 | 213 | |
209 | 214 | query_obj = qs.query_store() |
210 | 215 | |
211 | | - # Retrieve values from database |
| 216 | + """ Retrieve values from database """ |
212 | 217 | ret = self.query_tables(query_name, metric_name, campaign, item_1, item_2, start_time, end_time, interval, num_samples) |
213 | 218 | metrics_1 = ret[0] |
214 | 219 | metrics_2 = ret[1] |
215 | 220 | times_indices = ret[2] |
216 | 221 | |
217 | | - # run the confidence test |
| 222 | + """ run the confidence test """ |
218 | 223 | ret = self.confidence_test(metrics_1, metrics_2, num_samples) |
219 | 224 | means_1 = ret[0] |
220 | 225 | means_2 = ret[1] |
— | — | @@ -221,22 +226,22 @@ |
222 | 227 | std_devs_2 = ret[3] |
223 | 228 | confidence = ret[4] |
224 | 229 | |
225 | | - # Pad data with beginning and end points |
226 | | - times_indices.insert(len(times_indices), math.ceil(times_indices[-1])) |
227 | | - times_indices.insert(0, 0) |
| 230 | + """ Pad data with beginning and end points """ |
| 231 | + # times_indices.insert(len(times_indices), math.ceil(times_indices[-1])) |
| 232 | + # times_indices.insert(0, 0) |
228 | 233 | |
229 | | - means_1.insert(len(means_1),means_1[-1]) |
230 | | - means_2.insert(len(means_2),means_2[-1]) |
231 | | - means_1.insert(0,means_1[0]) |
232 | | - means_2.insert(0,means_2[0]) |
| 234 | + # means_1.insert(len(means_1),means_1[-1]) |
| 235 | + # means_2.insert(len(means_2),means_2[-1]) |
| 236 | + # means_1.insert(0,means_1[0]) |
| 237 | + # means_2.insert(0,means_2[0]) |
233 | 238 | |
234 | | - std_devs_1.insert(len(std_devs_1),0) |
235 | | - std_devs_2.insert(len(std_devs_2),0) |
236 | | - std_devs_1.insert(0,0) |
237 | | - std_devs_2.insert(0,0) |
| 239 | + # std_devs_1.insert(len(std_devs_1),0) |
| 240 | + # std_devs_2.insert(len(std_devs_2),0) |
| 241 | + # std_devs_1.insert(0,0) |
| 242 | + # std_devs_2.insert(0,0) |
238 | 243 | |
239 | 244 | |
240 | | - # plot the results |
| 245 | + """ plot the results """ |
241 | 246 | xlabel = 'Hours' |
242 | 247 | subplot_index = 111 |
243 | 248 | fname = test_name + '.png' |
— | — | @@ -344,7 +349,8 @@ |
345 | 350 | file.write('\n\ninterval\tmean1\t\tmean2\t\tstddev1\t\tstddev2\n\n') |
346 | 351 | file.write(win_str) |
347 | 352 | |
348 | | - for i in range(1,len(times_indices) - 1): |
| 353 | + # for i in range(1,len(times_indices) - 1): -- REMOVED with the |
| 354 | + for i in range(len(times_indices)): |
349 | 355 | line_args = str(i) + '\t\t' + '%.5f\t\t' + '%.5f\t\t' + '%.5f\t\t' + '%.5f\n' |
350 | 356 | line_str = line_args % (means_1[i], means_2[i], std_devs_1[i], std_devs_2[i]) |
351 | 357 | print line_str |
— | — | @@ -456,7 +462,7 @@ |
457 | 463 | |
458 | 464 | def confidence_test(self, metrics_1, metrics_2, num_samples): |
459 | 465 | |
460 | | - # retrieve means and variances |
| 466 | + """ retrieve means and variances """ |
461 | 467 | ret = self.compute_parameters(metrics_1, metrics_2, num_samples) |
462 | 468 | num_trials = ret[0] |
463 | 469 | means_1 = ret[1] |
— | — | @@ -475,9 +481,9 @@ |
476 | 482 | var_1_tot = 0 |
477 | 483 | var_2_tot = 0 |
478 | 484 | |
479 | | - # Compute the parameters for the Wald test |
480 | | - # The difference of the means and the sum of the variances is used to compose the random variable W = X1 - X2 for each trial |
481 | | - # where X{1,2} is the random variable corresponding to the group {1,2} |
| 485 | + """ Compute the parameters for the student's t-test |
| 486 | + The difference of the means and the sum of the variances is used to compose the random variable W = X1 - X2 for each trial |
| 487 | + where X{1,2} is the random variable corresponding to the group {1,2} """ |
482 | 488 | for i in range(num_trials): |
483 | 489 | |
484 | 490 | m_tot = m_tot + math.fabs(means_1[i] - means_2[i]) |
— | — | @@ -496,10 +502,6 @@ |
497 | 503 | |
498 | 504 | """ lookup confidence """ |
499 | 505 | |
500 | | - #print '' |
501 | | - #print t |
502 | | - #print degrees_of_freedom |
503 | | - |
504 | 506 | # get t and df |
505 | 507 | degrees_of_freedom = math.ceil(degrees_of_freedom) |
506 | 508 | if degrees_of_freedom > 30: |