Comparing PLG/SPLICE/ASPLICE Data


In [1]:
# Load modules
import sys
from __future__ import print_function
from collections import defaultdict

import helper_functions as hf
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

import time
import cPickle as pickle


from pqt import PQTDecomposition

from splice import splice_alg
from asplice import asplice_alg
from plg import plg_alg

Setup experiments


In [21]:
def run_experiments(gen_pd_edges, n_pairs_confs, p_hat_confs, n_reps_conf, verbose=False):
    results = []
    for n_pairs in n_pairs_confs:
        for rep in xrange(n_reps_conf):
            if verbose:
                print("Number of pairs: {} Rep: {} at ({})".format(n_pairs, 
                      rep, time.strftime("%H:%M %S", time.gmtime())))
                sys.stdout.flush()
        
            # Generate from uniform distribution
            pd_edges = gen_pd_edges(n_pairs=n_pairs)
            # Store timestamp to uniquely identify pd_edges
            timestamp = time.time()
        
            # Run SPLICE
            start_time = time.clock()
            _,cost = splice_alg(pd_edges)
            splice_time = time.clock() - start_time
            
            # Store result
            results.append({'timestamp': timestamp,
                            'alg': splice_alg.__name__,
                            'cost': cost,
                            'num_pairs': n_pairs,
                            'alg_time': splice_time})
            
            for p_hat in p_hat_confs:
                # Generate PQT
                start_time = time.clock()
                pqt = PQTDecomposition().from_points(pd_edges.keys(), p_hat=p_hat)
                pqt_time = time.clock() - start_time
            
                # Run ASPLICE
                start_time = time.clock()
                _,cost = asplice_alg(pd_edges, pqt=pqt)
                asplice_time = time.clock() - start_time
                
                # Store result
                results.append({'timestamp': timestamp,
                                'alg': asplice_alg.__name__,
                                'cost': cost,
                                'num_pairs': n_pairs,
                                'alg_time': asplice_time,
                                'pqt_time': pqt_time,
                                'p_hat': p_hat})
                
                # Run PLG
                start_time = time.clock()
                _,cost = plg_alg(pd_edges, pqt=pqt)
                plg_time = time.clock() - start_time
                
                # Store result
                results.append({'timestamp': timestamp,
                                'alg': plg_alg.__name__,
                                'cost': cost,
                                'num_pairs': n_pairs,
                                'alg_time': asplice_time,
                                'pqt_time': pqt_time,
                                'p_hat': p_hat})
    return results

Generate Data


In [29]:
n_pairs_confs = [10, 50]
p_hat_confs = [0.1, 0.05, 0.01]
n_reps_conf = 5
gen_pd_edges = hf.gen_pd_edges

results = run_experiments(gen_pd_edges, n_pairs_confs,
                            p_hat_confs, n_reps_conf,
                            verbose=False)

Plot Runtime vs Num Pairs


In [45]:
# Extract data
splice_data = filter(lambda result: result['alg']==splice_alg.__name__, results)
asplice_data = filter(lambda result: result['alg']==asplice_alg.__name__, results)

plg_data = filter(lambda result: result['alg']==plg_alg.__name__, results)
plg_data = {}

splice_cost = [entry['cost'] for entry in splice_data]
splice_n_pairs = [entry['num_pairs'] for entry in splice_data]

fig, ax = plt.subplots()
ax.scatter(splice_n_pairs, splice_cost)



plt.show()



In [31]:
unique([1,2,3,1])


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-31-6a6c9554143a> in <module>()
----> 1 unique([1,2,3,1])

NameError: name 'unique' is not defined

In [ ]: