Beispiel #1
0
def main():
    # The coefficients that will be used to generate the random data
    coefs = parseCoefs(args.coefs_file)

    # Select and run the chosen algorithm
    if args.method == 'h-dbn':
        func = test_h_dbn  # Uncomment for testing the second algo on a network
    elif args.method == 'nh-dbn':
        func = testPwBlrWithCpsParentMoves  # Test the fourth algorithm
    elif args.method == 'seq-dbn':
        func = testSeqCoupPwBlrWithCpsParentMoves  # test the fifth algorithm
    elif args.method == 'glob-dbn':
        func = testGlobCoupPwBlrWithCpsParentMoves  # test the sixth algorithm
    elif args.method == 'var-glob-dbn':
        func = testVvGlobCoup

    with concurrent.futures.ThreadPoolExecutor() as executor:
        # Generate data to test our algo
        network, _, adjMatrix = generateNetwork(args.num_features,
                                                args.num_indep, coefs,
                                                args.num_samples,
                                                args.change_points.copy(),
                                                args.verbose,
                                                args.generated_noise_var)

        chain_number = [x + 1 for x in range(args.number_chains)]
        networks_vec = [
            copy.deepcopy(network) for _ in range(args.number_chains)
        ]
        adjMatrix_vec = [
            copy.deepcopy(adjMatrix) for _ in range(args.number_chains)
        ]

        results = [
            executor.submit(func, args)
            for args in zip(chain_number, networks_vec, adjMatrix_vec)
        ]

        for f in concurrent.futures.as_completed(results):
            print(f.result())  # debug to check if the result was computed

            baNet, file_name, flattened_true, flattened_scores = f.result(
            )  # deconstruct future output
            adjMatrixRoc(
                flattened_scores, flattened_true,
                args.verbose)  # cannot display or save on a non-main thread

            # save the chain into the output folder
            save_chain(file_name, baNet)
Beispiel #2
0
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)
Beispiel #3
0
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)
Beispiel #4
0
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)
Beispiel #5
0
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)
Beispiel #6
0
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)