def testVvGlobCoup(f_args): thread_id, network, adjMatrix = f_args # deconstruct the f_arguments start = time.perf_counter() # for timing the algorithm output_line = ( 'Varying Variances Globally Coupled Bayesian Piece-Wise Linear Regression with moves on ' + 'change-points and parent sets on Yeast Data.') print(output_line) logger.info(output_line) # Print and write output baNet = Network([network], args.chain_length, args.burn_in, args.lag) baNet.infer_network('var_glob_coup_nh_dbn') true_inc = adjMatrix[ 0] # For the moment we just get the adj matrix of the first cp flattened_true, flattened_scores = transformResults( true_inc, baNet.proposed_adj_matrix) finish = time.perf_counter() print('My thread id is: ', thread_id, ' and I took: ', round(finish - start, 2), ' to run.') file_name = 'sim_seg_glob_coup_dbn_' + str( thread_id) + '.pckl' # set filename that is based on thread id return baNet, file_name, flattened_true, flattened_scores
def test_h_dbn(f_args): thread_id, network, adjMatrix = f_args # deconstruct the f_arguments start = time.perf_counter() # for timing the algorithm output_line = ('Bayesian Linear Regression with moves on' + 'the parent set only. \n') print(output_line) logger.info(output_line) # Print and write output change_points = [ ] # set the cps empty list because this is the homegeneous version baNet = Network([network], args.chain_length, args.burn_in, args.lag, change_points) # Create theh BN obj baNet.infer_network( 'h_dbn') # Do the fixed parents version of the DBN algo true_inc = adjMatrix[ 0] # For the moment we just get the adj matrix of the first cp flattened_true, flattened_scores = transformResults( true_inc, baNet.proposed_adj_matrix) finish = time.perf_counter() print('My thread id is: ', thread_id, ' and I took: ', round(finish - start, 2), ' to run.') file_name = 'sim_h_dbn_' + str( thread_id) + '.pckl' # set filename that is based on thread id return baNet, file_name, flattened_true, flattened_scores
def testGlobCoupPwBlrWithCpsParentMoves(data, true_inc): output_line = ( 'Full Parents Credible Intervals Globally Coupled Bayesian Piece-Wise Linear Regression' + 'with moves on change-points only Yeast Data.' ) print(output_line) ; logger.info(output_line) # Print and write output baNet = Network(data, args.chain_length, args.burn_in, args.lag) baNet.infer_network('fp_glob_coup_nh_dbn') flattened_true, flattened_scores = transformResults(true_inc, baNet.proposed_adj_matrix) adjMatrixRoc(flattened_scores, flattened_true, args.verbose) # save the chain into the output folder save_chain('fp_glob_coup_dbn.pckl', baNet)
def testVvGlobCoup(data, true_inc): output_line = ( 'Varying Variances Globally Coupled Bayesian Piece-Wise Linear Regression with moves on ' + 'change-points and parent sets on Yeast Data.') print(output_line) logger.info(output_line) # Print and write output baNet = Network(data, args.chain_length, args.burn_in, args.lag) baNet.infer_network('var_glob_coup_nh_dbn') flattened_true, flattened_scores = transformResults( true_inc, baNet.proposed_adj_matrix) adjMatrixRoc(flattened_scores, flattened_true, args.verbose) # save the chain into the output folder save_chain('vv_glob_coup_dbn.pckl', baNet)
def main(): # true incidence for yeast data # true_inc = [ # [0, 0, 1, 0, 1], # [1, 0, 0, 1, 0], # [0, 1, 0, 0 ,0], # [0, 1, 1, 0, 0], # [0, 0, 1, 0, 0] # ] # true incidence for simulated data true_inc = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 0, 1, 0, 0, 0], [1, 1, 0, 0, 0, 0], [1, 1, 1, 0, 0, 0]] nmbr_chains = 5 model_name = 'sim_glob_coup_dbn' chains = [] for idx in range(nmbr_chains): file_name = model_name + '_' + str(idx + 1) + '.pckl' curr_chain = load_chain(file_name) _, flattened_scores = transformResults(true_inc, curr_chain.proposed_adj_matrix) chains.append(flattened_scores) colors = ['tab:blue', 'tab:orange', 'tab:green', 'tab:red', 'tab:blue'] labels = ['chain_1', 'chain_2', 'chain_3', 'chain_4', 'chain_5'] fig, ax = plt.subplots() for idx, edge_scores in enumerate(chains): _x = [x + 1 for x in range(len(edge_scores))] color = colors[idx] label = labels[idx] ax.scatter(_x, edge_scores, c=color, label=label, alpha=0.3, edgecolors='none') ax.xaxis.set_major_locator( MaxNLocator(integer=True)) # force x ticks as integers ax.legend() ax.grid(True) plt.xlabel('Edge Number') plt.ylabel('Edge Score') plt.show()
def testPwBlrWithParentMoves(data, true_inc): output_line = ( 'Bayesian Piece-Wise Linear Regression with moves on ' + 'the parent set only with fixed changepoints for the Yeast Data. \n') print(output_line) logger.info(output_line) # Print and write output if args.change_points == 0: args.change_points = [] args.change_points.append(data.shape[0] + 1) # append the len data + 1 so the algo works baNet = Network(data, args.chain_length, args.burn_in, args.lag, args.change_points) # Create theh BN obj baNet.infer_network( 'fixed_nh_dbn') # Do the fixed changepoints version of the DBN algo flattened_true, flattened_scores = transformResults( true_inc, baNet.proposed_adj_matrix) adjMatrixRoc(flattened_scores, flattened_true, args.verbose)
def test_h_dbn(data, true_inc): output_line = ( 'Homogeneous Dinamic Bayesian Linear Regression with full parents ' + 'for the Yeast data. \n' ) print(output_line) ; logger.info(output_line) # Print and write output change_points = [] # set the cps empty list because this is the homegeneous version # Create/Call the Network objects/methods baNet = Network(data, args.chain_length, args.burn_in, args.lag, args.change_points) # Create theh BN obj baNet.infer_network('fp_h_dbn') # Do the fixed parents version of the DBN algo # trueAdjMatrix = adjMatrix[0] # For the moment we just get the adj matrix of the first cp flattened_true, flattened_scores = transformResults(true_inc, baNet.proposed_adj_matrix) adjMatrixRoc(flattened_scores, flattened_true, args.verbose) # save the chain into the output folder save_chain('fp_h_dbn.pckl', baNet)
def testPwBlrWithCpsParentMoves(data, true_inc): output_line = ('Bayesian Piece-Wise Linear Regression with moves on ' + 'change-points and parent sets for the Yeast data.') print(output_line) logger.info(output_line) # Print and write output if args.change_points == 0: args.change_points = [] # to get the total length of the data over the segments # data_len = 0 # for segment in data: # data_len = data_len + segment.shape[0] # args.change_points.append(data_len + 1) # append the len data + 1 so the algo works baNet = Network(data, args.chain_length, args.burn_in, args.lag) baNet.infer_network('varying_nh_dbn') flattened_true, flattened_scores = transformResults( true_inc, baNet.proposed_adj_matrix) adjMatrixRoc(flattened_scores, flattened_true, args.verbose) # save the chain into the output folder save_chain('nh_dbn.pckl', baNet)