def individual_experiments(n, p, event): """ Print graphs with aproximated probabilities and its coutes Input: list N, list P, int k Output: - """ I = intervalo(0, n + 1, 1) density = [0] * (len(I)) bundle = [0] * (len(I)) for i in I: if event == 1: density[i] = probability_last(n, p, i) bundle[i] = bundle_last(n, p, i) scatter_color = '#FF851B' line_color = '#001f3f' elif event == 2: density[i] = probability_anyone(n, p, i) scatter_color = '#FF851B' bundle[i] = bundle_anyone(n, p, i) line_color = '#FF4136' else: density[i] = probability_rigid_expansion(n, p, i) scatter_color = '#eb7ab1' bundle[i] = bundle_expansion(n, p, i) line_color = '#85144b' plt.plot(I, density, 'o', markersize=5, alpha=0.8, color=scatter_color, label="Experimentation") plt.plot(I, bundle, linewidth=1.5, linestyle='-', color=line_color, label="Expected value") plt.legend(bbox_to_anchor=(1.05, 1), loc='upper left', borderaxespad=0.) if event == 1: plt.savefig('Figures/Single-uniquely-determinated-fixed-vertex.png', bbox_inches="tight") elif event == 2: plt.savefig('Figures/Single-uniquely-determinated-any-vertex.png', bbox_inches="tight") else: plt.savefig('Figures/Single-expansion-probability.png', bbox_inches="tight") plt.show()
def time_execution_performance(n, p, samples_size, log_scale=False): """ Plots a mean time rigid expansions experiments varing n, p and k. Input: n (max graph size), p (list), samples_size(int) Output: Mean time, float """ n_interval = intervalo(3,n+2,2) k_proportion = [0.25, 0.5, 0.75] # For the plotting rows = len(k_proportion) cols = len(p) fig, axarr = plt.subplots(rows, cols, figsize=(3*cols+3,3*rows),dpi=80) colors = color_template_3() styles = plot_lines_styles() cases = [ {"name":"Whitout optimizations", "optimizations":'none'}, {"name":"Fully optimized", "optimizations":"all"}] for r in range(len(k_proportion)): _proportion = k_proportion[r] for c in range(len(p)): _p = p[c] for case in cases: case_index = cases.index(case) t = np.zeros(len(n_interval)) for i in range(len(n_interval)): _n = n_interval[i] _k = floor(_n * _proportion) t[i] = calculate_mean_expansion_time(_n, _p, _k, case, sample_size) if log_scale: t = log(t) axarr[r,c].plot(n_interval, t, label=case['name'], linestyle=styles[case_index%len(cases)], color=colors[case_index]) # Set labels for plot in row r and col c print('Just finished', r,c) axarr[r, c].spines['top'].set_color('white') axarr[r, c].spines['right'].set_color('white') axarr[r, c].set_title('p = ' + str(_p) + ', k_prop = ' + str(_proportion), backgroundcolor='silver') axarr[r, c].set_ylabel('Time (ms)' + (' (log scale)' if log_scale else '')) axarr[r, c].set_xlabel('Number of vertices') if r == 0 and c == len(p)-1: axarr[r,c].legend(bbox_to_anchor=(1.05, 1), loc='upper left', borderaxespad=0.) fig.subplots_adjust(bottom=0.2) plt.tight_layout() plt.savefig('Figures/Time-execution-rigid-expansions'+('-log-scale' if log_scale else '')+'.png', bbox_inches='tight') plt.show()
def graph_curves(): """ Print bundles Input: - Output: - """ I = intervalo(5, 100, 1) curve = [0] * (len(I)) properties = [{ 'bundle': bundle_locally_infinite, 'color': '#ebc844', 'label': 'Locally infinite' }, { 'bundle': bundle_connectivity, 'color': '#f16c20', 'label': 'Connected' }, { 'bundle': bundle_diameter, 'color': '#0d3c55', 'label': 'Diameter 2' }] for prop in properties: for i in range(0, I.size): curve[i] = prop['bundle'](I[i]) plt.plot(I, curve, linewidth=1.5, linestyle='-', color=prop['color'], label=prop['label']) plt.legend(bbox_to_anchor=(1.05, 1), loc='upper left', borderaxespad=0.) plt.fill_between(I, curve, 0.5, facecolor=prop['color'], alpha=0.4) plt.savefig('Figures/ER-thresholds.png') plt.show()
fig.colorbar(surf, shrink=0.5, aspect=5) ax.w_xaxis.set_pane_color((1.0, 1.0, 1.0, 1.0)) ax.w_yaxis.set_pane_color((1.0, 1.0, 1.0, 1.0)) ax.w_zaxis.set_pane_color((1.0, 1.0, 1.0, 1.0)) plt.savefig( 'Figures/3D-Transition-matrix-secuence-of-rigid-expansions.png') plt.show() k = 50 sample = sampleJump(n, p, k, 1000) m = mean(sample) v = var(sample) print(m / v) n_est = m**2 / (m - v) p_est = (m - v) / m print(n_est) print(p_est) I = intervalo(min(sample), max(sample) + 1, 1) density = [binomial(n_est, p_est, k) for k in I] plt.hist(sample, alpha=0.5, facecolor='#cc0000', edgecolor='#800000', linewidth=1, normed=1) plt.plot(I, density, color="#800000", linewidth=1.5, label="densidad") plt.title("Histogram") plt.show()
def set_of_experiments(N, P, event): """ Print curves with aproximated probabilities and its cuotes Input: list N, list P, int k Output: - """ r, c = len(N), len(P) goodness_of_fit = [[0] * c] * r f, axarr = plt.subplots(r, c, figsize=(9, 6), dpi=100) k = l = 0 for n in N: I = intervalo(0, n + 1, 1) density = [0] * (len(I)) bundle = [0] * (len(I)) for p in P: for i in I: if event == 1: density[i] = probability_last(n, p, i) bundle[i] = bundle_last(n, p, i) scatter_color = '#0074d9' line_color = '#001f3f' elif event == 2: density[i] = probability_anyone(n, p, i) bundle[i] = bundle_anyone(n, p, i) line_color = '#FF4136' scatter_color = '#FF851B' else: density[i] = probability_rigid_expansion(n, p, i) bundle[i] = bundle_expansion(n, p, i) line_color = '#85144b' scatter_color = '#eb7ab1' goodness_of_fit[N.index(n)][P.index(p)] = '%.2E' % Decimal( max([abs(x - y) for x, y in zip(density, bundle)])) axarr[k, l].plot(I, density, 'o', markersize=5, alpha=0.8, color=scatter_color, label="Experimentation") axarr[k, l].plot(I, bundle, linewidth=1.5, linestyle='-', color=line_color, label="Expected value") #Boxes if (k == 0 and l == 2): axarr[k, l].legend(bbox_to_anchor=(1.05, 1), loc='upper left', borderaxespad=0.) axarr[k, l].set_title('n=' + str(n) + ', p=' + str(p), backgroundcolor='silver') l = l + 1 l = 0 k = k + 1 #Pretty f.subplots_adjust(hspace=0.4) for i in range(0, r): for j in range(0, c): axarr[i, j].spines['top'].set_color('white') axarr[i, j].spines['right'].set_color('white') print("GOF", goodness_of_fit) if event == 1: plt.savefig('Figures/Uniquely-determinated-fixed-vertex.png', bbox_inches="tight") write_table("Uniquely-determinated-fixed-vertex-table-errors", caption_goodness_of_fit, "gofExp1", N, P, goodness_of_fit) plt.show() elif event == 2: plt.savefig('Figures/Uniquely-determinated-any-vertex.png', bbox_inches="tight") write_table("Uniquely-det-any-table-errors", caption_goodness_of_fit, "gofExp2", N, P, goodness_of_fit) plt.show() else: plt.savefig('Figures/Expansion-probability.png', bbox_inches="tight") write_table("Expansion-probability-table-errors", caption_goodness_of_fit, "gofExp3", N, P, goodness_of_fit) plt.show() plt.tight_layout() return goodness_of_fit