Beispiel #1
0
    b.set_baseline_response_prob(baseline)
    b.add_random_user_attrs(num_user_atts, min_user_att_levels,
                            max_user_att_levels)
    b.add_random_inter_attrs(num_msg_atts, min_msg_att_levels,
                             max_msg_att_levels)
    templates = b.set_random_propensities(
        num_propensity_groups, min_group_user_atts, max_group_user_atts,
        min_group_msg_atts, max_group_msg_atts, min_group_pos_prob,
        max_group_pos_prob)
    # -> Returns: a pair (user templates, interaction templates)
    logr.log('Generating data...', 'standard')
    messages = b.gen_random_inters(num_test_messages)
    rows = ut.unzip(b.gen_crossprod_rows(b.unique_users(), messages))
    logr.log('Number of rows: ' + str(len(rows)), 'standard')
    # Split data into train, calibration, and test.
    train, calibrate, test = ut.split_data(rows, 0.5, 0.25, 0.25)
    calibration_users = map(lambda (u, m, r): u, calibrate)
    test_users = map(lambda (u, m, r): u, test)
    controls = su.build_std_control_solvers(calibrate, b, messages, 15)
    treatments = su.build_std_knn_optims(train, calibrate, b, recorder, 1, 15)
    solvers = controls + treatments
    return (train, test_users, b, solvers)


logger = su.BasicLogger()
recorder = su.ScenarioRecorder()

su.run_trials(trial_init, su.standard_analyzer_f, num_trials, recorder, logger)
if output_file != None:
    logger.write(output_file)
rows = []
rows += ut.unzip(b.gen_random_rows_from_template(ut1, mt1, 100))
rows += ut.unzip(b.gen_random_rows_from_template(ut2, mt2, 100))
rows += ut.unzip(b.gen_random_rows_from_template(ut3, mt3, 100))
rows += ut.unzip(b.gen_random_rows_from_template(ut4, mt4, 100))
rows += ut.unzip(b.gen_random_rows_from_template(ut5, mt5, 100))
rows += ut.unzip(b.gen_random_rows(2000))


# A trial_initializer_f is a function which takes a recorder as input and returns a tuple:
# (train_data, calibration_users, test_users, data_generator, [(solver_f, name)], recorder, logger)
# An analyzer_f is a procedure which takes these args (in order):
# 1) a recorder, and 2) a logger_f

def trial_init(recdr, logr):
	# Split data into train, calibration, and test.
	train, calibrate, test = ut.split_data(rows, 0.5, 0.25, 0.25)
	calibration_users = map(lambda (u, m, r): u, calibrate)
	test_users = map(lambda (u, m, r): u, test)
	controls = su.build_std_control_solvers(calibrate, b, 100, 15)
	treatments = su.build_std_knn_optims(train, calibrate, b, recorder, 1, 15)
	solvers = controls + treatments
	return (train, test_users, b, solvers)

logger = su.BasicLogger()
recorder = su.ScenarioRecorder()
	
su.run_trials(trial_init, su.standard_analyzer_f, 2, recorder, logger)
logger.write('../output/sk5.txt')