From 4e9b4a8145b74f26b2b44e07f58d41a1524582bf Mon Sep 17 00:00:00 2001
From: "valentin.emiya" <valentin.emiya@lif.univ-mrs.fr>
Date: Thu, 26 Nov 2020 11:30:33 +0100
Subject: [PATCH] add linear regression

---
 python/tffpy/experiments/exp_solve_tff.py | 28 ++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/python/tffpy/experiments/exp_solve_tff.py b/python/tffpy/experiments/exp_solve_tff.py
index 2ca6e21..188c0c0 100644
--- a/python/tffpy/experiments/exp_solve_tff.py
+++ b/python/tffpy/experiments/exp_solve_tff.py
@@ -64,6 +64,7 @@ import matplotlib.pyplot as plt
 import matplotlib
 import pandas as pd
 from pathlib import Path
+from scipy.stats import linregress
 
 from yafe import Experiment
 from madarrays import Waveform
@@ -114,7 +115,7 @@ class SolveTffExperiment(Experiment):
         -------
         int
         """
-        return len(list((self.xp_path / 'tasks').glob('*')))
+        return len(list((self.xp_path / 'tasks').glob('0*')))
 
     @staticmethod
     def get_experiment(setting='full', force_reset=False):
@@ -262,6 +263,8 @@ class SolveTffExperiment(Experiment):
 
         # Scatter plot for running times : tff-1 vs. tff-P
         plt.figure()
+        x = []
+        y = []
         for win_type in coords_dict['problem_win_choice']['data']:
             t_tff1 = results.sel(measure=['t_lambda_tff', 't_arrf', 't_evdn'],
                                  problem_win_choice=win_type,
@@ -281,9 +284,32 @@ class SolveTffExperiment(Experiment):
                 win_type_label = 'Gauss'
             else:
                 win_type_label = 'Hann'
+            slope, intercept, r_value, p_value, std_err = \
+                linregress(t_tff1.values.reshape(-1), t_tffp.values.reshape(-1))
+            print('Running times ({}): slope={}, intercept={}, 1/slope={},'
+                  .format(win_type, slope, intercept, 1 / slope))
             plt.plot(t_tff1.values.reshape(-1),
                      t_tffp.values.reshape(-1),
                      '+', label=win_type_label)
+            # plt.plot(t_tff1.values.reshape(-1),
+            #          slope * t_tff1.values.reshape(-1) + intercept)
+            x.append(t_tff1.values.reshape(-1).copy())
+            y.append(t_tffp.values.reshape(-1).copy())
+
+        x = np.array(x)
+        y = np.array(y)
+        # for i in range(x.shape[1]):
+        #     plt.plot(x[:, i], y[:, i], ':k')
+
+        x = x.reshape(-1)
+        y = y.reshape(-1)
+        slope, intercept, r_value, p_value, std_err = linregress(x, y)
+        print('Running times (all): slope={}, intercept={}, 1/slope={},'
+              .format(slope, intercept, 1 / slope))
+        print('Linear slope (not affine):')
+        print(np.vdot(x, y) / np.vdot(x, x), np.vdot(x, x) / np.vdot(x, y))
+
+        # plt.plot(x, slope * x + intercept)
         plt.xlabel(r'Running time for TFF-1 (s)')
         plt.ylabel(r'Running time for TFF-P (s)')
         plt.legend()
-- 
GitLab