<jupyter_start><jupyter_text>Calculate the average speedup over all instances<jupyter_code>gmean(optimal_df['speedup'])<jupyter_output><empty_output><jupyter_text>Calculate the average speedup over the barthel instances<jupyter_code>df1 = optimal_df[optimal_df['type'] == 'barthel']
gmean(df1['speedup'])<jupyter_output><empty_output><jupyter_text>Calculate the average speedup over the komb instances<jupyter_code>df1 = optimal_df[optimal_df['type'] == 'komb']
gmean(df1['speedup'])<jupyter_output><empty_output><jupyter_text>Calculate the average speedup over the qhid instances<jupyter_code>df1 = optimal_df[optimal_df['type'] == 'qhid']
gmean(df1['speedup'])<jupyter_output><empty_output><jupyter_text>Calculate the average speedup over the qhid and komb instances<jupyter_code>df1 = optimal_df[(optimal_df['type'] == 'qhid') | (optimal_df['type'] == 'komb')]
gmean(df1['speedup'])<jupyter_output><empty_output><jupyter_text>Calculate the average speedup on instances with two components<jupyter_code>fits = pd.read_csv('../fits/expon_mix_2comp_fits_mod_name.txt', index_col=0)
df1 = optimal_df[fits['p1']<1.0]
gmean(df1['speedup'])<jupyter_output><empty_output><jupyter_text>Add the number of variables to the fit<jupyter_code>features = pd.read_csv('../calculate_features/features_train_mod_name.csv')
features.set_index('instance', inplace=True)
fits['n'] = features[['nvarsOrig']]
fits.head()<jupyter_output><empty_output><jupyter_text>Setup functions for numerical optimization<jupyter_code>def condition(t, rv, b):
    if t <= 0:
        return -np.inf
    F = rv.cdf(t)
    result = (F - 1.0)*t
    result += F*(1-F)/(rv.pdf(t))
    result -= rv.partial_exp(t)
    return result - b
def find_restart_time(p1, lambda1, lambda2, n, c=1.5):
    ps = [p1, 1.0-p1]
    scales = [lambda1, lambda2]
    rv = ExponMixture(ps, scales)
    b = c*n
    solution = root_scalar(condition, args=(rv, b), x0=10.0*b, x1=b, method='secant', xtol=1.0)
    return np.ceil(solution.root + b)
def evaluate_restart_time(data, t):
    mean = np.mean(data) # For the computation of the speedup, the mean is needed
    cumsum = 0.0 # This is used for the conditional expectation
    i = 0
    while data[i] <= t:
        cumsum += data[i]
        i += 1
    if i == 0:
        return 0
    ecdf = i/300.0 # We measured 300 runs
    geom_part = (1.0 - ecdf)/ecdf * t # This part describes the geometric part of the expectation with restarts
    cond_exp = cumsum/float(i) # partial expectation -> conditional expectation
    speedup = mean/(geom_part + cond_exp)
    return speedup<jupyter_output><empty_output><jupyter_text>Calculate speedups<jupyter_code>mixed_fits = fits[fits['p1']<1.0]
underestimate = 0
speedups = []
for index, row in mixed_fits.iterrows():
    restart_time = find_restart_time(row[0], row[2], row[3], row[4], c=1.5)
    speedup = evaluate_restart_time(np.asarray(df.loc[index])[1:],  restart_time)
    if speedup == 0:
        underestimate += 1
#         print(index, "lamba1", row[2], "lambda2", row[3], "restart time:", restart_time)
    else:
        print(speedup)
        speedups.append(speedup)<jupyter_output>1.0297045668398577
1.002513935390249
1.1278374866172416
1.0080260263871315
1.0550916283813656
1.6240404654365284
1.0362653738363266
1.0170228369960141
4.079519536707226
1.0606755259057308
1.0406679110189865
1.049926997029503
0.8865885610633896
1.030593615177877
1.0793516449802116
107900.79292023435
9382.815243725503
1855847.2119447782
8.071205669328503
16.92435188949622
5289.386835150405
245.78003383143852
9.414259079976077
148.03102840415906
55933.505160439556
46245.8475305699
13.615590216334116
6.45254851517665
11299.055871820661
12.73735212925223
12.256130910229713
63512.927006238875
6.850333991365335
1.7890328657100358
173.94327216746223
379.0299943901607
107.99765368177644
327.412648520895
67.75177254225619
81.59516780205298
1705.4925838536305
12.877389872852262
1110.0546750681647
110.58047715392301
6249.48651547729
78.1799300563144
25.45336185931454
188.82925010489376
34949.53244293309
96.11912721442204
1.9810373934837182
3.954793197740398
1046.4821621232607
17.118582964806194
16[...]<jupyter_text>Calculate average speedup<jupyter_code>gmean(speedups)
print(underestimate)<jupyter_output>4<jupyter_text>Average speedup on all instances<jupyter_code>underestimate = 0
speedups = []
for index, row in fits.iterrows():
    if row[0] < 1.0:
        restart_time = find_restart_time(row[0], row[2], row[3], row[4], c=1.5)
        speedup = evaluate_restart_time(np.asarray(df.loc[index])[1:],  restart_time)
        if speedup == 0:
            underestimate += 1
        else:
            speedups.append(speedup)
    else:
        speedups.append(1.0) # In this case restarts are not performed, therefore no speedup or slowdown can be observed
print(speedups)
gmean(speedups)
underestimate<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11921891058581706, 'fraction_numerical': 0.20082219938335047, 'mean_word_length': 5.3858267716535435, 'pattern_counts': {'":': 0, '<': 48, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '194469', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 2457, 'n_tokens_neox': 1906, 'n_words': 341, 'path': 'jupyter/get_speedup/.ipynb_checkpoints/Calculate speedup-checkpoint.ipynb', 'repo_name': 'jahehalo/potential_of_restarts_hidden', 'size': '4865'}