def good_sigma_evaluator_1(nodes=20, observations=10, numObservations=10, trials=10000, size=10): results = numpy.zeros(size); for i in range(0, size): G, sig, D = mcmc.generate_graph_and_paths(nodes, observations, numObservations); sigmas, sig_ind_prob, samples = mcmc.sig_mcmc(G, D, trials); bar1 = sig_ind_prob/samples; results[i] = mcmc.real_distribution_error(bar1, sig); return results, numpy.mean(results), numpy.var(results);
def good_sigma_evaluator_1(nodes=20, observations=10, numObservations=10, trials=10000, size=10): results = numpy.zeros(size) for i in range(0, size): G, sig, D = mcmc.generate_graph_and_paths(nodes, observations, numObservations) sigmas, sig_ind_prob, samples = mcmc.sig_mcmc(G, D, trials) bar1 = sig_ind_prob / samples results[i] = mcmc.real_distribution_error(bar1, sig) return results, numpy.mean(results), numpy.var(results)
def run_sigma_experiment_1(nodes=20, observations=10, numObservations=10, trials=10000, fileIndex=0): G, sig, D = mcmc.generate_graph_and_paths(nodes, observations, numObservations); sigmas, sig_ind_prob, samples = mcmc.sig_mcmc(G, D, trials); print(sig); bar1 = sig_ind_prob/samples; bar2 = numpy.ones(G.shape[0]) - bar1; ind = numpy.arange(G.shape[0]); p1 = plot.bar(ind, bar1, 0.35, color='r'); p2 = plot.bar(ind, bar2, 0.35, color='b', bottom=bar1); plot.ylabel('L/R') plot.title('Switch index') plot.legend((p1[0], p2[0]), ('L', 'R')) plot.show(); bar = numpy.zeros(len(sigmas)); label = numpy.zeros(len(sigmas)); ind = numpy.arange(len(sigmas)); i = 0; for sigma, n in sigmas.items(): bar[i] = n/float(samples); label[i] = mcmc.sigma_hash(sigma); i += 1; p1 = plot.bar(ind, bar, 0.1, color='black'); #plot.xticks(ind+0.1/2., tuple(label), rotation=90); plot.ylabel('Probability of sigma') plot.xlabel('Sigma index') plot.title('Joint probability of sigma') plot.axis([0, len(sigmas), 0, max(bar)+0.05]); plot.show(); true_sig_prob = 1; for i in range(0, nodes): if(sig[i] == 1): true_sig_prob *= bar1[i]; else: true_sig_prob *= bar2[i]; numpy.savetxt('test_results/sigma_experiment_1_ind_prob_L_{}_{}_{}_{}.{}.txt'.format(nodes,observations,numObservations,trials,fileIndex), bar1); numpy.savetxt('test_results/simga_experiment_1_search_space_index_{}_{}_{}_{}.{}.txt'.format(nodes,observations,numObservations,trials,fileIndex), label); numpy.savetxt('test_results/sigma_experiment_1_search_space_{}_{}_{}_{}.{}.txt'.format(nodes,observations,numObservations,trials,fileIndex), bar); print('Distribution error: {}'.format(mcmc.real_distribution_error(bar1, sig))); print('The probability of guessing the true sigma is {}'.format(true_sig_prob)); print('posterior/prior = {}'.format(true_sig_prob/pow(0.5, nodes)));
def run_sigma_experiment_1(nodes=20, observations=10, numObservations=10, trials=10000, fileIndex=0): G, sig, D = mcmc.generate_graph_and_paths(nodes, observations, numObservations) sigmas, sig_ind_prob, samples = mcmc.sig_mcmc(G, D, trials) print(sig) bar1 = sig_ind_prob / samples bar2 = numpy.ones(G.shape[0]) - bar1 ind = numpy.arange(G.shape[0]) p1 = plot.bar(ind, bar1, 0.35, color='r') p2 = plot.bar(ind, bar2, 0.35, color='b', bottom=bar1) plot.ylabel('L/R') plot.title('Switch index') plot.legend((p1[0], p2[0]), ('L', 'R')) plot.show() bar = numpy.zeros(len(sigmas)) label = numpy.zeros(len(sigmas)) ind = numpy.arange(len(sigmas)) i = 0 for sigma, n in sigmas.items(): bar[i] = n / float(samples) label[i] = mcmc.sigma_hash(sigma) i += 1 p1 = plot.bar(ind, bar, 0.1, color='black') #plot.xticks(ind+0.1/2., tuple(label), rotation=90); plot.ylabel('Probability of sigma') plot.xlabel('Sigma index') plot.title('Joint probability of sigma') plot.axis([0, len(sigmas), 0, max(bar) + 0.05]) plot.show() true_sig_prob = 1 for i in range(0, nodes): if (sig[i] == 1): true_sig_prob *= bar1[i] else: true_sig_prob *= bar2[i] numpy.savetxt( 'test_results/sigma_experiment_1_ind_prob_L_{}_{}_{}_{}.{}.txt'.format( nodes, observations, numObservations, trials, fileIndex), bar1) numpy.savetxt( 'test_results/simga_experiment_1_search_space_index_{}_{}_{}_{}.{}.txt' .format(nodes, observations, numObservations, trials, fileIndex), label) numpy.savetxt( 'test_results/sigma_experiment_1_search_space_{}_{}_{}_{}.{}.txt'. format(nodes, observations, numObservations, trials, fileIndex), bar) print('Distribution error: {}'.format( mcmc.real_distribution_error(bar1, sig))) print('The probability of guessing the true sigma is {}'.format( true_sig_prob)) print('posterior/prior = {}'.format(true_sig_prob / pow(0.5, nodes)))