Last active
March 14, 2019 12:35
-
-
Save pzp1997/895599b57c17e0d7bbc710a5c5dff6e6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import pandas as pd | |
# Build data for experiment | |
def make_experiment(batch_size, group_size): | |
imgs = list(range(454, 920)) | |
groups = [] | |
for i in range(group_size, len(imgs)): | |
group = imgs[i - group_size:i] | |
random.shuffle(group) | |
groups.append(group) | |
variables_df = pd.DataFrame(random.sample(groups, batch_size), columns=['image{}'.format(i + 1) for i in range(group_size)]) | |
variables_df.to_csv('variables-{}x{}.csv'.format(batch_size, group_size), index=False) | |
return variables_df | |
for gs in range(2, 5): | |
make_experiment(100, gs) | |
batch_df = pd.read_csv('batch-100x4.csv') | |
answers = batch_df['Answer.ordering'] | |
num_fully_in_order = 0 | |
num_pairs_in_order = 0 | |
num_pairs = 0 | |
# Assessing results | |
def evaluate(batch_file): | |
batch_df = pd.read_csv(batch_file) | |
answers = batch_df['Answer.ordering'] | |
num_samples_in_order = 0 | |
num_samples = 0 | |
num_pairs_in_order = 0 | |
num_pairs = 0 | |
for answer in answers: | |
ordering = [int(id_) for id_ in answer.split('tennis')[1:]] | |
if ordering == sorted(ordering): | |
num_samples_in_order += 1 | |
num_samples += 1 | |
num_pairs_in_order += sum( | |
1 for id1, id2 in zip(ordering, ordering[1:]) if id1 < id2) | |
num_pairs += len(ordering[1:]) | |
return { | |
'num_samples_correct': num_samples_in_order, | |
'num_samples': num_samples, | |
'num_pairs_correct': num_pairs_in_order, | |
'num_pairs': num_pairs, | |
} | |
evaluate('batch-100x4.csv') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment