<commit_before>#!/usr/bin/python
# Perform Monte Carlo cross-validation (repeated random sub-sampling)
# on the face recognition system with a dataset. The dataset should
# have a script of the form "./scripts/create-[dataset].py" that
# can partition the dataset into training and test sets.
import argparse
import os
import shutil
import subprocess
import sys
import datasets

# parse command-line arguments
parser = argparse.ArgumentParser(epilog="Arguments for C code should be separated by a '--'.")
parser.add_argument("-d", "--dataset", choices=["feret", "mnist", "orl"], required=True, help="name of dataset", dest="DATASET")
parser.add_argument("-t", "--train", type=int, choices=range(1, 100), required=True, help="percentage of training set", metavar="N", dest="TRAIN")
parser.add_argument("-r", "--test", type=int, choices=range(1, 100), required=True, help="percentage of test set", metavar="N", dest="TEST")
parser.add_argument("-i", "--num-iter", type=int, required=True, help="number of iterations", metavar="N", dest="NUM_ITER")
parser.add_argument("ARGS", nargs=argparse.REMAINDER, help="arguments for C code")

args = parser.parse_args()

# perform some custom validation
if args.TRAIN + args.TEST != 100:
	print "error: --train and --test must sum to 100%"
	sys.exit(1)

# check for face-rec executable
if not os.path.isfile("./face-rec"):
	print "error: ./face-rec not found"
	sys.exit(1)

# determine parameters of dataset
if args.DATASET == "feret":
	dataset = datasets.FERETDataset()
elif args.DATASET == "mnist":
	dataset = datasets.MNISTDataset()
elif args.DATASET == "orl":
	dataset = datasets.ORLDataset()

# remove '--' from ARGS
args.ARGS.remove("--")

# construct subprocess args
args_dataset = ["python", "scripts/create-sets.py", "-d", args.DATASET, "-t", str(args.TRAIN), "-r", str(args.TEST)]

args_c = ["./face-rec", "--train", "train_data", "--test", "test_data"]
args_c.extend(args.ARGS);<commit_msg>Added fctl dataset to cross-validate.py<commit_after>#!/usr/bin/python
# Perform Monte Carlo cross-validation (repeated random sub-sampling)
# on the face recognition system with a dataset. The dataset should
# have a script of the form "./scripts/create-[dataset].py" that
# can partition the dataset into training and test sets.
import argparse
import os
import shutil
import subprocess
import sys
import datasets

# parse command-line arguments
parser = argparse.ArgumentParser(epilog="Arguments for C code should be separated by a '--'.")
parser.add_argument("-d", "--dataset", choices=["feret", "mnist", "orl", "fctl"], required=True, help="name of dataset", dest="DATASET")
parser.add_argument("-t", "--train", type=int, choices=range(1, 100), required=True, help="percentage of training set", metavar="N", dest="TRAIN")
parser.add_argument("-r", "--test", type=int, choices=range(1, 100), required=True, help="percentage of test set", metavar="N", dest="TEST")
parser.add_argument("-i", "--num-iter", type=int, required=True, help="number of iterations", metavar="N", dest="NUM_ITER")
parser.add_argument("ARGS", nargs=argparse.REMAINDER, help="arguments for C code")

args = parser.parse_args()

def get_sub_dirs(dir):
    return [name for name in os.listdir(dir)
            if os.path.isdir(os.path.join(dir, name))]

# perform some custom validation
if args.TRAIN + args.TEST != 100:
	print "error: --train and --test must sum to 100%"
	sys.exit(1)

# check for face-rec executable
if not os.path.isfile("./face-rec"):
	print "error: ./face-rec not found"
	sys.exit(1)

# determine parameters of dataset
if args.DATASET == "feret":
	dataset = datasets.FERETDataset()
elif args.DATASET == "mnist":
	dataset = datasets.MNISTDataset()
elif args.DATASET == "orl":
	dataset = datasets.ORLDataset()
elif args.DATASET == "fctl":
	subs = get_sub_dirs('datasets/fctl')
	dataset = datasets.LABDataset(subs)

# remove '--' from ARGS
args.ARGS.remove("--")

# construct subprocess args
args_dataset = ["python", "scripts/create-sets.py", "-d", args.DATASET, "-t", str(args.TRAIN), "-r", str(args.TEST)]

args_c = ["./face-rec", "--train", "train_data", "--test", "test_data"]
args_c.extend(args.ARGS);
{'fraction_non_alphanumeric': 0.1677138714354761, 'fraction_numerical': 0.007733204446592557, 'mean_word_length': 5.177611940298507, 'pattern_counts': {'":': 7, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4480067', 'n_tokens_mistral': 1363, 'n_tokens_neox': 1352, 'n_words': 392}