print "working on example", datum_id
        if data_iter.next(
                          compute_pattern_times=True,
                            max_template_length=classifier.window[1]):
            pattern_times = data_iter.pattern_times
            num_detections = data_iter.E.shape[1] - classifier.window[1]
            num_frames += data_iter.E.shape[1]
            scores = -np.inf * np.ones(num_detections)
            for d in xrange(num_detections):
                E_segment = data_iter.E[:,d:d+classifier.window[1]].copy()                
                esp.threshold_edgemap(E_segment,.30,edge_feature_row_breaks,report_level=False,abst_threshold=abst_threshold)
                esp.spread_edgemap(E_segment,edge_feature_row_breaks,edge_orientations,spread_length=3)
                if classifier_flat.score_no_bg(E_segment[:,:classifier_flat.window[1]]) > flat_threshold:
                    scores[d] = classifier.score_no_bg(E_segment)
            # now we get the indices sorted
            indices = cl.remove_overlapping_examples(np.argsort(scores)[::-1],
                                                     classifier.window[1],
                                                     int(allowed_overlap*classifier.window[1]))
            positives, negatives =  cl.get_pos_neg_scores(indices,pattern_times,
                                                          scores,classifier.window[1])
            all_positives.extend(positives)
            all_negatives.extend(negatives)
        else:
            break

aar_def_roc,aar_def_roc_vals = cl.get_roc(np.sort(all_positives)[::-1],
                                  np.sort(all_negatives)[::-1],num_frames)

np.save('aar_def_roc_vals052112',aar_def_roc_vals)

                           coarse_count_scores[d] and\
                           coarse_count_scores[d-1]>\
                           coarse_count_scores[d-2]) ):
                 coarse_scores[d] = classifier.score_no_bg(E_segment)
     # get the positive and negative scores removed out
     pos_counts =[]
     pos_scores = []
     neg_indices = np.empty(scores.shape[0],dtype=bool)
     neg_indices[:]=True
     for pt in xrange(len(pattern_times)):
         pos_scores.append(np.max(scores[pattern_times[pt][0]-int(np.ceil(classifier.window[1]/3.)):pattern_times[pt][0]+int(np.ceil(classifier.window[1]/3.))]))
         pos_counts.append(np.max(coarse_scores[pattern_times[pt][0]-int(np.ceil(classifier.window[1]/3.)):pattern_times[pt][0]+int(np.ceil(classifier.window[1]/3.))]))
         neg_indices[pattern_times[pt][0]-int(np.ceil(classifier.window[1]/3.)):pattern_times[pt][1]] = False
     # get rid of overlapping instances
     neg_indices_counts_non_overlap = cl.remove_overlapping_examples(np.argsort(coarse_scores),
                                                 classifier.coarse_length,
                                                 int(allowed_overlap*classifier.coarse_length))
     neg_indices_non_overlap = cl.remove_overlapping_examples(np.argsort(scores),
                                                 classifier.window[1],
                                                 int(allowed_overlap*classifier.window[1]))
     neg_idx2 = np.empty(scores.shape[0],dtype=bool)
     neg_idx2[neg_indices_non_overlap] =True
     neg_indices_full = np.logical_and(neg_indices,neg_idx2)
     neg_idx2 = np.empty(scores.shape[0],dtype=bool)
     neg_idx2[neg_indices_counts_non_overlap] =True
     neg_indices_coarse = np.logical_and(neg_indices,neg_idx2)
     all_positive_scores.extend(pos_scores)
     all_positive_counts.extend(pos_counts)
     all_negative_scores.extend(scores[neg_indices_full])
     all_negative_counts.extend(coarse_scores[neg_indices_coarse])            
 else:
 coarse_scores = -np.inf * np.ones(num_detections)
 bg = mean_background.copy()
 for d in xrange(num_detections):
     E_segment = data_iter.E[:,d:d+classifier.window[1]].copy()                
     esp.threshold_edgemap(E_segment,.30,edge_feature_row_breaks,report_level=False,abst_threshold=abst_threshold)
     esp.spread_edgemap(E_segment,edge_feature_row_breaks,edge_orientations,spread_length=3)
     
     scores[d] = classifier.score_no_bg(E_segment)
     scores_adapt_bg[d] = classifier.score(E_segment,bg)
     coarse_scores[d] = classifier.coarse_score_count(E_segment)
     bg = np.minimum(.1,
                      np.maximum(np.mean(E_segment,axis=1),
                                 .4))
 # now we get the indices sorted
 indices = cl.remove_overlapping_examples(np.argsort(scores)[::-1],
                                          classifier.window[1],
                                          int(allowed_overlap*classifier.window[1]))
 indices_adapt_bg = cl.remove_overlapping_examples(np.argsort(scores_adapt_bg)[::-1],
                                                   classifier.window[1],
                                                   int(allowed_overlap*classifier.window[1]))
 indices_coarse = cl.remove_overlapping_examples(np.argsort(coarse_scores)[::-1],
                                                 classifier.window[1],
                                                 int(allowed_overlap*classifier.window[1]))
 positives, negatives =  cl.get_pos_neg_scores(indices,pattern_times,
                                               scores,classifier.window[1])
 positives_adapt_bg, negatives_adapt_bg =  cl.get_pos_neg_scores(indices_adapt_bg,
                                                                 pattern_times,
                                                                 scores_adapt_bg,
                                                                 classifier.window[1])
 positives_coarse, negatives_coarse =  cl.get_pos_neg_scores(indices_coarse,
                                                             pattern_times,