# -*- coding: utf-8 -*- """ Created on Wed Mar 4 12:56:56 2020 @author: Johan Rene van Dorp """ import numpy as np from scipy.stats import binom import Dist_Library as dl import matplotlib.pyplot as plt from matplotlib.lines import Line2D m = 222743 tau = 0.342 # Binomial Distribution Different Eyes prob = 0.456 n = 766 Diff_Eye_Sample = np.random.binomial(n,prob,m)/n k = 150 boundaries_diff = np.arange(k+1)/k Emp_pdf_Diff_Eye = dl.Estimate_empirical_histogram(boundaries_diff,Diff_Eye_Sample) Prob_Tau_Diff = binom.cdf(tau*n, n, prob) mu_diff = np.mean(Diff_Eye_Sample) sigma_diff = np.std(Diff_Eye_Sample) print(tau*n) print(Prob_Tau_Diff) print(mu_diff) print(sigma_diff) # Sampling Binomial Distribution Same Eyes prob = 0.089 n = 46 Same_Eye_Sample = np.random.binomial(n,prob,m)/n k = 50 boundaries_same = np.arange(k+1)/k Emp_pdf_Same_Eye = dl.Estimate_empirical_histogram(boundaries_same,Same_Eye_Sample) Prob_Tau_Same = 1-binom.cdf(tau*n, n, prob) mu_same = np.mean(Same_Eye_Sample) sigma_same = np.std(Same_Eye_Sample) print(Prob_Tau_Same) print(mu_same) print(sigma_same) plt.rc('font', family='serif', size='10') Iris_figure = plt.figure() Iris_figure.set_figwidth(9) Iris_figure.set_figheight(4.5) Iris_figure.subplots_adjust(left=0.05, bottom=0.15, right=0.95, top=0.9, hspace=0.1, wspace=0.3) The_Figure_Panel = Iris_figure.add_subplot(1,1,1) dl.add_pmf_prob_hist_to_figure_panel(The_Figure_Panel,boundaries_diff,Emp_pdf_Diff_Eye,'indianred',1) dl.add_pmf_prob_hist_to_figure_panel(The_Figure_Panel,boundaries_same,Emp_pdf_Same_Eye,'skyblue',1) x_lims = (0,1) y_lims = (0,27) plt.xlim(x_lims) plt.ylim(y_lims) plt.xlabel('Hamming Distance') plt.ylabel('Density') legend_elements = [Line2D([0], [0], color='indianred', lw=4, label='Different Eye'), Line2D([0], [0], color='skyblue', lw=4, label='Same Eye')] plt.legend(handles = legend_elements, loc = 'upper left') plt.axvline(tau, lw=1, ls = ':',color = 'black') plt.text(tau+0.015,25,r'$\tau$ = ' + str(tau),color = 'black',size='9') plt.text(tau+0.015,23.5,'Sample Size = 222,743',color = 'black',size='9') plt.text(0.015,19.5,'p = 0.089',size='9') plt.text(0.015,18,'n = 46',size='9') plt.text(0.015,16.5,'Mean = ' + f'{mu_same:5.4f}',size='9') plt.text(0.015,15,'St.dev = ' + f'{sigma_same:5.4f}',size='9') plt.text(0.015,13.5,r'$Pr(HD>\tau|$ Same Eye) = ',size='9') plt.text(0.015,12,f'{Prob_Tau_Same:5.4g}',size='9') plt.text(0.5 + 0.015,19.5,'p = 0.456',size='9') plt.text(0.5 + 0.015,18,'n = 766',size='9') plt.text(0.5 + 0.015,16.5,'Mean = ' + f'{mu_diff:5.4f}',size='9') plt.text(0.5 + 0.015,15,'St.dev = ' + f'{sigma_diff:5.4f}',size='9') plt.text(0.5 + 0.015,13.5,r'$Pr(HD<\tau|$ Different Eye) = ',size='9') plt.text(0.5 + 0.015,12,f'{Prob_Tau_Diff:5.4g}',size='9') plt.text(0.55 + 0.015,9,'Sampled from Theoretical') plt.text(0.55 + 0.015,7.5,'Binomial distribution') Iris_figure.suptitle('Hamming Distance Analysis for Same and Different Eye',size='14') plt.savefig('Figure3.png', dpi=300)