commit 308a0754d966734c2528ca45abdb7a77fc17078c
Author: Marcos Assuncao <assuncao@acm.org>
Date:   Mon Sep 1 10:07:07 2014 +0200

    distribution fitting for deployment time

diff --git a/papers/2014/reservation/experiments/src/python/lib/kadeploy.py b/papers/2014/reservation/experiments/src/python/lib/kadeploy.py
index e41c399..f4a18b7 100644
--- a/papers/2014/reservation/experiments/src/python/lib/kadeploy.py
+++ b/papers/2014/reservation/experiments/src/python/lib/kadeploy.py
@@ -7,7 +7,8 @@ import matplotlib.pyplot as plt; plt.rcdefaults()
 import numpy as np
 from matplotlib import rc
 from pylab import *
-from scipy.stats import gaussian_kde
+from scipy.stats import gaussian_kde, lognorm, rayleigh, norm
+import scipy.stats as stats
 rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']})
 rc('text', usetex=True)
 plt.rcParams.update({'font.size': 14})
@@ -20,9 +21,9 @@ class DeploymentStat:
     def __init__(self, host, start, step1_dur, step2_dur, step3_dur, success):
         self._host = host
         self._start = start
-        self._step1_dur = step1_dur
-        self._step2_dur = step2_dur
-        self._step3_dur = step3_dur
+        self._step1_dur = int(step1_dur)
+        self._step2_dur = int(step2_dur)
+        self._step3_dur = int(step3_dur)
         self._success = success
         self._retry_1 = 0
         self._retry_2 = 0
@@ -49,6 +50,10 @@ class DeploymentStat:
         return self._step3_dur
 
     @property
+    def deployment_duration(self):
+        return self.step_1_duration + self.step_2_duration + self.step_3_duration
+
+    @property
     def success(self):
         return self._success
 
@@ -133,12 +138,18 @@ def plot_deployment_time(deployments, cluster, year, out_dir):
     values = []
     for d in deployments:
         if d.success and not d.has_retries:
-            values.append(int(d.step_1_duration + d.step_2_duration + d.step_3_duration))
+            value = d.deployment_duration
+            if d.step_1_duration > 5 and d.step_2_duration > 10 and d.step_3_duration > 10:
+                values.append(value)
+
+            # values.append(value)
             # values.append(int(d.step_3_duration))
             # values.append(int(d.step_1_duration))
 
     title = 'Deployment on Cluster %s (%d)' % (cluster, year)
+    # title = 'Deployment on Cluster %s' % (cluster)
     out_file = out_dir + ("/deployment_%s_%d.pdf" % (cluster, year))
+    # out_file = out_dir + ("/deployment_%s.pdf" % (cluster))
     hist_graph(values, title, 'Deployment Time (seconds)', '', out_file)
 
 
@@ -146,17 +157,17 @@ def hist_graph(values, title, x_label, y_label, out_file):
     ar1 = np.array(values)
     fig, ax = plt.subplots()
 
-    num_bins = 20
+    num_bins = 50
     n, bins, patches = plt.hist(ar1, bins=num_bins, histtype='bar',
                                 normed=True, facecolor='#708090', alpha=0.5, rwidth=0.8)
     plt.subplots_adjust(left=0.15)
 
     max = round(bins[len(bins) - 1])
     density = gaussian_kde(ar1)
-    xs = np.linspace(0,max,300)
+    xs = np.linspace(0, max, 300)
     density.covariance_factor = lambda : .25
     density._compute_covariance()
-    plt.plot(xs,density(xs), 'r--')
+    # plt.plot(xs, density(xs), 'r--')
 
     ax.set_xlabel(x_label)
     ax.set_ylabel(y_label)
@@ -165,9 +176,44 @@ def hist_graph(values, title, x_label, y_label, out_file):
     ax.get_xaxis().tick_bottom()
     ax.get_yaxis().tick_left()
 
+    # # original distribution
+    # pdf = rayleigh.pdf(xs, loc=120, scale=230)
+    # plt.plot(xs, pdf, 'r-')
+    #
+    # param = rayleigh.fit(ar1)
+    # pdf_fitted = rayleigh.pdf(xs, loc=param[0], scale=param[1])
+    # plt.plot(xs, pdf_fitted, 'b')
+
+    # original distribution
+    # pdf = lognorm.pdf(xs, 0.4, loc=10, scale=370)
+    # plt.plot(xs, pdf, 'r-')
+
+    dist_names = ['lognorm', 'beta', 'betaprime', 'gamma', 'rayleigh']
+
+    for dist_name in dist_names:
+        dist = getattr(stats, dist_name)
+        param = dist.fit(ar1)
+        pdf_fitted = dist.pdf(xs, *param[:-2], loc=param[-2], scale=param[-1])
+        plt.plot(xs, pdf_fitted, label=dist_name)
+        plt.xlim(0, max)
+    plt.legend(loc='upper right')
+
+    # param = lognorm.fit(ar1)
+    # pdf_fitted = lognorm.pdf(xs, param[0], loc=param[1], scale=param[2])
+    # plt.plot(xs, pdf_fitted, 'b')
+
+    # param = norm.fit(ar1)
+    # pdf_fitted = norm.pdf(xs, loc=param[0], scale=param[1])
+    # plt.plot(xs, pdf_fitted, 'b')
+
+    #print param
+
     plt.show()
     # plt.savefig(out_file)
 
+
+
+
 def plot_graphs():
     opts = parse_kdeploy_opt()
     deployments = parse_log(opts.input, opts.cluster)
