def submit_ranking(): # get the username and their dataset username = request.form['username'] user_dataset = utils_users.get_gp_dataset( username, 'ranking', num_objectives=specs_jobs.NUM_OBJECTIVES) # get the ranking the user submitted ranking = np.fromstring(request.form['rankingResult'], sep=',', dtype=np.int) # save it utils_users.save_ranking(username, ranking) # get the actual jobs (ranking returned the indiced in the dataset) jobs_ranked = user_dataset.datapoints[ranking] # add the ranking to the dataset user_dataset.add_ranked_preferences(jobs_ranked) # save utils_users.update_gp_dataset(username, user_dataset, 'ranking') # get the start time for this user start_time = utils_users.get_experiment_start_time(username, 'ranking') if time.time() - start_time < specs_jobs.TIME_EXPERIMENT_SEC: return redirect(url_for('.start', username=username)) else: utils_users.update_experiment_status(username=username, query_type='ranking') return redirect('start_experiment/{}'.format(username))
def submit_clustering_jobs(): # get the username and their dataset username = request.form['username'] user_dataset = utils_users.get_gp_dataset(username, 'clustering', num_objectives=specs_jobs.NUM_OBJECTIVES) # get the clusters the user submitted top_job = [int(request.form['top-cluster'])] good_jobs = np.fromstring(request.form['good-cluster'], sep=',', dtype=np.int) bad_jobs = np.fromstring(request.form['bad-cluster'], sep=',', dtype=np.int) clustering = [top_job, good_jobs, bad_jobs] # save it utils_users.save_clustering(username, clustering) # get the actual jobs (ranking returned the indiced in the dataset) top_job = user_dataset.datapoints[top_job] good_jobs = user_dataset.datapoints[good_jobs] bad_jobs = user_dataset.datapoints[bad_jobs] clustering = [top_job, good_jobs, bad_jobs] # add the ranking to the dataset user_dataset.add_clustered_preferences(clustering) # save utils_users.update_gp_dataset(username, user_dataset, 'clustering') # get the start time for this user start_time = utils_users.get_experiment_start_time(username, 'clustering') if time.time()-start_time < specs_jobs.TIME_EXPERIMENT_SEC: return redirect(url_for('.start', username=username)) else: utils_users.update_experiment_status(username=username, query_type='clustering') return redirect('start_experiment/{}'.format(username))
def continue_pairwise(username, side_clicked): # get the dataset for this user dataset_user = utils_users.get_gp_dataset( username, 'pairwise', num_objectives=specs_jobs.NUM_OBJECTIVES) # initialise the acquirer which picks new datapoints acquirer = DiscreteAcquirer(input_domain=utils_jobs.get_jobs(), query_type='pairwise', seed=specs_jobs.SEED) # intialise the GP gp = GPPairwise(num_objectives=specs_jobs.NUM_OBJECTIVES, seed=specs_jobs.SEED) # add collected datapoints to acquirer acquirer.history = dataset_user.datapoints # add collected datapoints to GP gp.update(dataset_user) # get the best job so far job_best_idx = dataset_user.comparisons[-1, 0] job_best = dataset_user.datapoints[job_best_idx] # let acquirer pick new point job_new = acquirer.get_next_point(gp, dataset_user) # sort according to what user did last round if side_clicked == "1": job1 = job_best job2 = job_new else: job1 = job_new job2 = job_best # transform the two jobs into dictionaries job1 = utils_jobs.job_array_to_job_dict(job1) job2 = utils_jobs.job_array_to_job_dict(job2) # get the start time for this user start_time = utils_users.get_experiment_start_time(username, 'pairwise') if time.time() - start_time < specs_jobs.TIME_EXPERIMENT_SEC: return render_template("query_pairwise_jobs.html", username=username, job1=job1, job2=job2, side_clicked=side_clicked) else: utils_users.update_experiment_status(username=username, query_type='pairwise') return redirect('start_experiment/{}'.format(username))
def submit_ranking(): # get the username and their dataset username = request.form['username'] user_dataset = utils_users.get_gp_dataset(username, 'ranking', num_objectives=specs_traffic.NUM_OBJECTIVES) # get the ranking the user submitted ranking = np.fromstring(request.form['rankingResult'], sep=',', dtype=np.int) # save it utils_users.save_ranking(username, ranking) # get the actual traffic (ranking returned the indiced in the dataset) traffic_ranked = user_dataset.datapoints[ranking] # add the ranking to the dataset user_dataset.add_ranked_preferences(traffic_ranked) print("comparisons from curr ranking", user_dataset.comparisons) # save utils_users.update_gp_dataset(username, user_dataset, 'ranking') # get the start time for this user utils_users.get_experiment_start_time(username, 'ranking') button_type = request.form['buttonType'] if button_type == 'next': return redirect(url_for('.start', username=username)) elif button_type == 'end': # save end time utils_users.save_experiment_end_time(username, 'ranking') # register that this experiment was done utils_users.update_experiment_status(username=username, query_type='ranking') return redirect('start_experiment/{}'.format(username)) else: raise NotImplementedError('Button type not defined')
def continue_pairwise(username, side_clicked, button_type): # get the dataset for this user dataset_user = utils_users.get_gp_dataset( username, 'pairwise', num_objectives=specs_traffic.NUM_OBJECTIVES) # initialise the acquirer which picks new datapoints acquirer = DiscreteAcquirer( input_domain=data_traffic.get_traffic_results(), query_type='pairwise', seed=specs_traffic.SEED) # add collected datapoints to acquirer acquirer.history = dataset_user.datapoints # add virtual comparisons in first few queries for i in range(np.min([dataset_user.datapoints.shape[0], 6])): dataset_user.add_single_comparison(dataset_user.datapoints[i], data_traffic.get_traffic_min()) dataset_user.add_single_comparison(data_traffic.get_traffic_max(), dataset_user.datapoints[i]) # add linear prior in first few queries if acquirer.history.shape[0] < 6: prior_mean_type = 'linear' else: prior_mean_type = 'zero' # intialise the GP gp = GPPairwise(num_objectives=specs_traffic.NUM_OBJECTIVES, seed=specs_traffic.SEED, prior_mean_type=prior_mean_type) # add collected datapoints to GP gp.update(dataset_user) # get the best job so far job_best_idx = dataset_user.comparisons[-1, 0] job_best = dataset_user.datapoints[job_best_idx] # let acquirer pick new point job_new = acquirer.get_next_point(gp, dataset_user) # sort according to what user did last round if side_clicked == "1": item1 = job_best item2 = job_new else: item1 = job_new item2 = job_best # get the names of the objectives obj_names = data_traffic.get_objective_names() obj_abbrev = data_traffic.get_objective_abbrev() if button_type == 'next': return render_template("query_pairwise_traffic.html", username=username, item1=-item1, item2=-item2, side_clicked=side_clicked, obj_names=obj_names, obj_abbrev=obj_abbrev) elif button_type == 'end': # save end time utils_users.save_experiment_end_time(username, 'pairwise') # register that this experiment was done utils_users.update_experiment_status(username=username, query_type='pairwise') return redirect('start_experiment/{}'.format(username)) else: raise NotImplementedError('Button type unknown.')