<commit_before>from argparse import ArgumentParser
from ipdb import set_trace as pause
import numpy as np
import os

from base import Minibatch, Patternset
from rbm import create_mnist_patternset, RbmNetwork
from utils.dt import dt_str
from utils.stopwatch import Stopwatch
from utils.utils import HashableDict

"""
USAGE: e.g.

  python benchmark.py -h

  python benchmark.py -s 3 --lrate 0.001 --lrate 0.01 --momentum 0.1 --momentum 0.2 --nhidden 1000
  ->
    {'nhidden': 1000, 'wcost': 0.0002, 'momentum': 0.1, 'lrate': 0.001}
    {'nhidden': 1000, 'wcost': 0.0002, 'momentum': 0.2, 'lrate': 0.001}
    {'nhidden': 1000, 'wcost': 0.0002, 'momentum': 0.1, 'lrate': 0.01}
    {'nhidden': 1000, 'wcost': 0.0002, 'momentum': 0.2, 'lrate': 0.01}
"""

# TODO
#
# - test on withheld data
# - write out to sqlite, pickle
# - plot on graph
# - run on c3.large

def print_best(attempts, keys):
    attempts = sorted_attempts(attempts)
    print 'rank\terror\t' + '\t'.join(keys)
    for rank, attempt in enumerate(attempts):
        print ('%i\t%.2f\t' % (rank+1, attempt['test_error'])) +'\t'.join([str(attempt[k]) for k in keys])

def sorted_attempts(attempts):
    attempts = sorted(attempts, key=lambda x: x['test_error'])
    return attempts

def gridsearch(nhidden, lrate, wcost, momentum, n_in_train_minibatch, max_time_secs):
    npatterns = 1000
    pset = create_mnist_patternset(npatterns=npatterns)
    # xxx - this isn't a proper test since we're using the training data, rather than withheld...
    n_in_test_minibatch = 1000
    test_minibatch = Minibatch(pset, n_in_test_minibatch)<commit_msg>Default gridsearch over 10000 MNIST patterns<commit_after>from argparse import ArgumentParser
from ipdb import set_trace as pause
import numpy as np
import os

from base import Minibatch, Patternset
from rbm import create_mnist_patternset, RbmNetwork
from utils.dt import dt_str
from utils.stopwatch import Stopwatch
from utils.utils import HashableDict

"""
USAGE: e.g.

  python benchmark.py -h

  python benchmark.py -s 3 --lrate 0.001 --lrate 0.01 --momentum 0.1 --momentum 0.2 --nhidden 1000
  ->
    {'nhidden': 1000, 'wcost': 0.0002, 'momentum': 0.1, 'lrate': 0.001}
    {'nhidden': 1000, 'wcost': 0.0002, 'momentum': 0.2, 'lrate': 0.001}
    {'nhidden': 1000, 'wcost': 0.0002, 'momentum': 0.1, 'lrate': 0.01}
    {'nhidden': 1000, 'wcost': 0.0002, 'momentum': 0.2, 'lrate': 0.01}
"""

# TODO
#
# - test on withheld data
# - write out to sqlite, pickle
# - plot on graph
# - run on c3.large

def print_best(attempts, keys):
    attempts = sorted_attempts(attempts)
    print 'rank\terror\t' + '\t'.join(keys)
    for rank, attempt in enumerate(attempts):
        print ('%i\t%.2f\t' % (rank+1, attempt['test_error'])) +'\t'.join([str(attempt[k]) for k in keys])

def sorted_attempts(attempts):
    attempts = sorted(attempts, key=lambda x: x['test_error'])
    return attempts

def gridsearch(nhidden, lrate, wcost, momentum, n_in_train_minibatch, max_time_secs):
    npatterns = 10000
    pset = create_mnist_patternset(npatterns=npatterns)
    # xxx - this isn't a proper test since we're using the training data, rather than withheld...
    n_in_test_minibatch = 1000
    test_minibatch = Minibatch(pset, n_in_test_minibatch)
{'fraction_non_alphanumeric': 0.1365040148239654, 'fraction_numerical': 0.054354539839407044, 'mean_word_length': 3.998456790123457, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4513005', 'n_tokens_mistral': 1323, 'n_tokens_neox': 1140, 'n_words': 338}