Exemple #1
0
        logging.info("Beginning summary csv generation")
        
        with open(os.path.join(experiment_directory, "summary.csv"), 'wb') as summary_stream:
            writer = csv.writer(summary_stream)
            writerow = writer.writerow
            format_num = lambda n: n if n is None else "%.3f" % n
            
            if latex_encode:
                str_encoder = lambda s: s.encode('latex')
            else:
                str_encoder = lambda s: s
            
            highlight = lambda x: x
            
            # Get all the union of all the variations names. 
            variations = uniqueify(itertools.chain(*[r.keys() for r in summary_results.values()]))
            data_names = summary_results.keys()
            
            top_results = [max(r.values()) for r in (summary_results[dn] for dn in data_names)]
            
            #None at start to leave column for variation names
            writerow([None] + map(str_encoder, data_names))
            
            for variation in variations:
                variation_results = [r.get(variation, None) for r in (summary_results[dn] for dn in data_names)]
                variation_results_highlighted = [highlight(format_num(v)) if v == t else format_num(v) for (v, t) in zip(variation_results, top_results)]
                row = [str_encoder(variation)] + variation_results_highlighted
                writerow(row)
        logging.info("Ending summary csv generation")

if __name__ == "__main__":
 
 dsn_to_results_dict = OrderedDict()
 
 dataset_names = rows[0][1:]
 for dsn in dataset_names:
     dsn_to_results_dict[dsn] = []
 
 strats = []
 for r in rows[1:]:
     strats.append(r[0])
     for (v, (dsn, results)) in  izip(r[1:], dsn_to_results_dict.iteritems()):
         results.append(Result(v, None))
 
 for (dsn, results) in dsn_to_results_dict.iteritems():
     result_scores = [r.score for r in results]
     result_scores_for_indexing = sorted(uniqueify(result_scores), reverse=True)
     for r in results:
         score = result_scores_for_indexing.index(r.score) + 1
         r.rank = score
 
 with open(output_f, 'wb') as output_s:
     writer = csv.writer(output_s)
     writer.writerow([""] + dsn_to_results_dict.keys() 
                     + [options.avg_rank_col_name] if options.add_avg_rank_col else [] )
     strats_results = zip(*dsn_to_results_dict.values())
     names_to_strats_results = zip(strats, strats_results)
     for (strat_name, strat_results) in names_to_strats_results:
         if options.include_ranks:
             formatter = lambda res: "%.03f (%d)" % (res.score, res.rank) 
         else:
             formatter = lambda res: "%.03f" % res.score
from all_experiments import experiment as all_experiment
from utils import sub_pairs, uniqueify
import baselines, baseline_sparsity, competence_counting, competence_hybrids, competence_with_similarity, competence_with_sparsity

names = (baselines.names + baseline_sparsity.names + competence_counting.names + competence_hybrids.names 
         + competence_with_similarity.names + competence_with_sparsity.names)

names = uniqueify(names)

experiment = all_experiment.create_sub_experiment(names)