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,
                                                                 coarse_scores,
                                                                 classifier.window[1])
     all_positives.extend(positives)
     all_negatives.extend(negatives)
     all_positives_adapt_bg.extend(positives_adapt_bg)
     all_negatives_adapt_bg.extend(negatives_adapt_bg)
     all_positives_coarse.extend(positives_coarse)
     all_negatives_coarse.extend(negatives_coarse)
 else:
            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)

                esp.threshold_edgemap(E_segment_mel,.30,e_breaks_mel,report_level=False,abst_threshold=abst_threshold)
                esp.spread_edgemap(E_segment_mel,e_breaks_mel,e_orientations_mel,spread_length=3)
                bg = np.minimum(.4,
                                 np.maximum(np.mean(E_segment,axis=1),
                                            .1))
                scores_adapt_bg[d] = classifier.score(E_segment,bg)
                scores_mel[d] = classifier.score_no_bg(E_segment_mel)
            # now we get the indices sorted
            indices_adapt_bg = cl.remove_overlapping_examples(np.argsort(scores_adapt_bg)[::-1],
                                                              classifier.window[1],
                                                              int(allowed_overlap*classifier.window[1]))
            indices_mel = cl.remove_overlapping_examples(np.argsort(scores_mel)[::-1],
                                                            classifier.window[1],
                                                            int(allowed_overlap*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_mel, negatives_mel =  cl.get_pos_neg_scores(indices_mel,
                                                                        pattern_times,
                                                                        scores_mel,
                                                                        classifier.window[1])
            all_positives_adapt_bg.extend(positives_adapt_bg)
            all_negatives_adapt_bg.extend(negatives_adapt_bg)
            all_positives_mel.extend(positives_mel)
            all_negatives_mel.extend(negatives_mel)
        else:
            break

aar_roc_adapt_bg,aar_roc_vals_adapt_bg = cl.get_roc(np.sort(all_positives_adapt_bg)[::-1],
                                                    np.sort(all_negatives_adapt_bg)[::-1],num_frames)
aar_roc_coarse,aar_roc_vals_coarse = cl.get_roc(np.sort(all_positives_coarse)[::-1],