def compute_features(self, activations, agreement_threshold=0.3, analyze=False):
        self.num_images = len(activations)
        self.agreement_threshold = agreement_threshold

        self.total_img_cxns = 0
        self.image_activations = {}
        for i, act in enumerate(activations):
            asum = act.sum()
            self.total_img_cxns += asum
            self.image_activations[i] = (act, asum)

        self.compute_feature_proposals()

        print "Num proposals:", self.feature_idx
        #    print "Image features:", self.image_features
        #    print "Feature images:", self.feature_images
        print "Compressions:\n", numpy.array(self.compressions)
        #    print "Fewer cxns:\n", numpy.array(self.feat_num_fewer_cxns)

        num_sampling_attempts = 100
        min_compression = 1.0
        best_assignment = None

        compressions = []

        for i in xrange(num_sampling_attempts):
            features, image_assignments, total_compression = self.sample_assignments()
            if total_compression < min_compression:
                min_compression = total_compression
                best_assignment = image_assignments
                best_features = features
            compressions.append(total_compression)

        histogram(compressions).show()

        greedy_features, greedy_assignments, greedy_compression = self.get_greedy_assignment()

        print "Best compression:", min_compression
        print "Greedy compression:", greedy_compression
        print best_assignment

        coverages = []
        for i, val in self.image_activations.items():
            act, asum = val
            feat_sum = greedy_features[greedy_assignments[i]].sum()
            coverages.append(float(feat_sum) / asum)

        print "Coverages:", coverages

        return best_features, best_assignment
 def randomly_sample_particle(self, num_samples):
   """ Picks the best feature assignment from num_samples random attempts. """
   
   num_sampling_attempts = 100
   min_compression = 1.0
   best_assignment = None
   
   compressions = []
   
   for i in xrange(num_sampling_attempts):
     features, image_assignments, total_compression = \
                                           self.randomly_condense_particles()
     if total_compression < min_compression:
       min_compression = total_compression
       best_assignment = image_assignments
       best_features = features
     compressions.append(total_compression)
   
   histogram(compressions).show()