示例#1
0
def bees_data():
    dtmc_filepath = 'data/prism/bee_multiparam_synchronous_3.pm'
    bscc_filepath = 'data/prism/bee_multiparam_synchronous_3.txt'
    model = BeesModel.from_files(dtmc_filepath, bscc_filepath)
    p_true = [0.2, 0.5, 0.7]
    m, d = model.sample(chain_params=p_true, trials_count=10000)
    return (m, d)
示例#2
0
def mcmc():
    dtmc_filepath = 'data/prism/bee_multiparam_synchronous_3.pm'
    bscc_filepath = 'data/prism/bee_multiparam_synchronous_3.txt'
    model = BeesModel.from_files(dtmc_filepath, bscc_filepath)
    mcmc = BayesianMcmc(model)
    assert model.bscc_eval_mode == BeesModel.BSCC_MODE_CHAIN_RUN
    return mcmc
示例#3
0
def small_batch():
    logging.info('SMALL BATCH, TEST FOR CORRECT MODEL PROCESSING')
    model_files = [
        # 3 bees
        ('models/prism/bee_multiparam_synchronous_3.pm',
         'models/prism/bee_multiparam_synchronous_3.txt'),
        # 5 bees
        ('models/prism/bee_multiparam_synchronous_5.pm',
         'models/prism/bee_multiparam_synchronous_5.txt')
    ]
    mh_chain_length = [100, 200]
    mh_chain_run_factor = [100, 200]
    synthetic_data_trials = [100, 200]
    for setting in itertools.product(model_files, synthetic_data_trials, mh_chain_length):
        files, trials_count, mh_chainLength = setting
        logging.info('{}'.format('-' * 80))
        logging.info('MODEL INFO')
        logging.info('Model DTMC file {}'.format(files[0]))
        logging.info('Model BSCC file {}'.format(files[1]))
        model = BeesModel.from_files(*files)
        logging.info('#params {}, # BSCCs{}'.format(
            model.get_params_count(), model.get_bscc_count()))
        p_true = rand_increasing_sequence(model.get_params_count())
        logging.info('True parameters: {}'.format(p_true))
        (s, m, f) = model.sample(params=p_true, trials_count=trials_count)
        summarize_data((s, m, f))
        do_experiment_rational(model, m, mh_chainLength)
        for chain_run_factor in mh_chain_run_factor:
            do_experiment_chainrun(model, m, mh_chainLength, chain_run_factor)
示例#4
0
def test_mm10params():
    logging.info('SINGLE TEST, 15 BEES')
    dtmc_filepath = 'models/prism/bee_multiparam_synchronous_10.pm'
    bscc_filepath = 'models/prism/bee_multiparam_synchronous_10.txt'
    model = BeesModel.from_files(dtmc_filepath, bscc_filepath)
    p_true = rand_increasing_sequence(model.get_params_count())
    do_experiment(model, p_true, 1000, 500, 100)
示例#5
0
def test_chain_run():
    print('Sampling with chain run')
    dtmc_filepath = 'models/prism/bee_multiparam_synchronous_3.pm'
    bscc_filepath = 'models/prism/bee_multiparam_synchronous_3.txt'
    bees_model = BeesModel.from_files(dtmc_filepath, bscc_filepath)
    r = [0.1, 0.2, 0.3]
    start_time = timeit.default_timer()
    h = bees_model.sample_run_chain(r, max_trials=1000)
    stop_time = timeit.default_timer()
    print('Finished in {} seconds, chain length {}'.format(
        stop_time - start_time, 1000))
    assert (sum(h) - 1.0 < 1e-5)
    print('\tSample frequency:', h)
示例#6
0
def synthesize_data():
    logging.info('DATA SYNTHESIZING')
    logging.info('Note that this will run only once')
    """
    ('models/prism/bee_multiparam_synchronous_3.pm',
    'models/prism/bee_multiparam_synchronous_3.txt'),
    ('models/prism/bee_multiparam_synchronous_5.pm',
    'models/prism/bee_multiparam_synchronous_5.txt'),
    ('models/prism/bee_multiparam_synchronous_10.pm',
    'models/prism/bee_multiparam_synchronous_10.txt'),
    ('models/prism/bee_multiparam_synchronous_15.pm',
    'models/prism/bee_multiparam_synchronous_15.txt')
    """
    bscc_file  = 'models/prism/bee_multiparam_synchronous_10.pm'
    model_file = 'models/prism/bee_multiparam_synchronous_10.txt'
    bees_model = BeesModel.from_files(model_file, bscc_file)
示例#7
0
def evaluation_time():
    logging.info('LARGE BATCH, SETTINGS TEST')
    model_files = [
        # 3 bees
        ('models/prism/bee_multiparam_synchronous_3.pm',
         'models/prism/bee_multiparam_synchronous_3.txt'),
        # 5 bees
        ('models/prism/bee_multiparam_synchronous_5.pm',
         'models/prism/bee_multiparam_synchronous_5.txt'),
        # 10 bees
        ('models/prism/bee_multiparam_synchronous_10.pm',
         'models/prism/bee_multiparam_synchronous_10.txt'),
        # 15 bees
        ('models/prism/bee_multiparam_synchronous_15.pm',
         'models/prism/bee_multiparam_synchronous_15.txt')
    ]
    mh_chain_run_factor = [100, 500, 1000]
    max_trials = [100, 500, 1000, 10000]
    for file in model_files:
        logging.info('{}'.format('-' * 80))
        logging.info('EVALUATION TIME')
        logging.info('Model DTMC file {}'.format(file[0]))
        logging.info('Model BSCC file {}'.format(file[1]))
        model = BeesModel.from_files(*file)
        logging.info('#params={}, #BSCCs={}'.format(
            model.get_params_count(), model.get_bscc_count()))
        p_true = rand_increasing_sequence(model.get_params_count())
        logging.info('True parameters: {}'.format(p_true))


        logging.info('Sample with BSCC Evaluation')
        start_time = timeit.default_timer()
        (s, m, f) = model.sample(params=p_true, trials_count=1)
        stop_time = timeit.default_timer()
        elapsed_time = stop_time - start_time
        logging.info('Finished in {} seconds'.format(elapsed_time))

        logging.info('...')

        for factor in mh_chain_run_factor:
            trials_count = factor * model.get_bscc_count()
            logging.info('Sample with {} chain run'.format(trials_count))
            start_time = timeit.default_timer()
            h = model.sample_run_chain(p_true, max_trials=trials_count)
            stop_time = timeit.default_timer()
            elapsed_time = stop_time - start_time
            logging.info('Finished in {} seconds'.format(elapsed_time))
示例#8
0
def bees_model():
    dtmc_filepath = 'models/prism/bee_multiparam_synchronous_3.pm'
    bscc_filepath = 'models/prism/bee_multiparam_synchronous_3.txt'
    bees_model = BeesModel.from_files(dtmc_filepath, bscc_filepath)
    return bees_model
示例#9
0
 def load_files(self, ):
     self.data_model = BeesModel.from_files(self.model_file, self.bscc_file)
     assert self.data_model.bscc_eval_mode == BeesModel.BSCC_MODE_CHAIN_RUN
     self.print_log("Loaded model file: {}".format(self.model_file))
     self.print_log('Loaded BSCCs file: {}'.format(self.bscc_file))
示例#10
0
 def load_files(self, ):
     self.data_model = BeesModel.from_model_file(self.model_file)
     assert self.data_model.bscc_eval_mode == BeesModel.BSCC_MODE_CHAIN_RUN
     self.print_log("Loaded model file: {}".format(self.model_file))
     self.print_log(len(self.data_model.state_labels))
     self.print_log(len(self.data_model.bscc_labels))