<commit_before>"""Spearmint for the DBN module in pydeeplearn."""

__author__ = "<NAME>"
__contact__ = "<EMAIL>"

import argparse

from lib import deepbelief as db
from lib.common import *

from read import readmnist

parser = argparse.ArgumentParser(description='digit recognition')
parser.add_argument('--path',dest='path', type = "string", default="MNIST",
                    help="the path to the MNIST files")
arser.add_argument('--trainSize', type=int, default=100,
                    help='the number of tranining cases to be considered')
parser.add_argument('--testSize', type=int, default=10,
                    help='the number of testing cases to be considered')

args = parser.parse_args()

def trainDBN(unsupervisedLearningRate,
             supervisedLearningRate,
             visibleDropout,
             hiddenDropout,
             miniBatchSize,
             momentumMax,
             maxEpochs):
  trainVectors, trainLabels =\
    readmnist.read(0, args.trainSize, digits=None, bTrain=True, path=args.path)

  testVectors, testLabels =\
      readmnist.read(args.trainSize,  args.trainSize + args.testSize,
                     digits=None, bTrain=True, path=args.path)

  trainVectors, trainLabels = shuffle(trainVectors, trainLabels)

  trainVectors = np.array(trainVectors, dtype='float')
  trainingScaledVectors = scale(trainVectors)

  testVectors = np.array(testVectors, dtype='float')
  testingScaledVectors = scale(testVectors)

  trainVectorLabels = labelsToVectors(trainLabels, 10)

  net = db.DBN(5, [784, 1000, 1000, 1000, 10],
                  binary=False,
                  unsupervisedLearningRate=unsupervisedLearningRate,
                  supervisedLearningRate=supervisedLearningRate,
                  momentumMax=momentumMax,
                  nesterovMomentum=True,
                  rbmNesterovMomentum=True,
                  activationFunction=Rectified(),
                  rbmActivationFunctionVisible=Identity(),
                  rbmActivationFunctionHidden=RectifiedNoisy(),
                  rmsprop=True,
                  visibleDropout=0.8,
                  hiddenDropout=0.5,
                  weightDecayL1=0,
                  weightDecayL2=0,
                  rbmHiddenDropout=1.0,
                  rbmVisibleDropout=1.0,
                  miniBatchSize=miniBatchSize,
                  # TODO: make this a learned param
                  preTrainEpochs=100,
                  sparsityConstraintRbm=False,
                  sparsityTragetRbm=0.01,
                  sparsityRegularizationRbm=None)

  net.train(trainingScaledVectors, trainVectorLabels,
            maxEpochs=maxEpochs, validation=args.validation)

  proabilities, predicted = net.classify(testingScaledVectors)
  error = getClassificationError(predicted, testLabels)
  print "error", error
  return error


# Write a function like this called 'main'
def main(job_id, params):
  print 'params', params
  return trainDBN(unsupervisedLearningRate=params['unsupervisedLearningRate'][0],
                  supervisedLearningRate=params['supervisedLearningRate'][0],
                  visibleDropout=params['visibleDropout'][0],
                  hiddenDropout=params['hiddenDropout'][0],
                  miniBatchSize=params['miniBatchSize'][0],
                  momentumMax=params['momentumMax'][0],
                  maxEpochs=params['maxEpochs'][0])<commit_msg>fix the path to mnist in the python file<commit_after>"""Spearmint for the DBN module in pydeeplearn."""

__author__ = "<NAME>"
__contact__ = "<EMAIL>"

import argparse

from lib import deepbelief as db
from lib.common import *

from read import readmnist

parser = argparse.ArgumentParser(description='digit recognition')
parser.add_argument('--path',dest='path', type = str, default="/data/mcr10/project/pydeeplearn/code/MNIST",
                    help="the path to the MNIST files")
arser.add_argument('--trainSize', type=int, default=100,
                    help='the number of tranining cases to be considered')
parser.add_argument('--testSize', type=int, default=10,
                    help='the number of testing cases to be considered')

args = parser.parse_args()

def trainDBN(unsupervisedLearningRate,
             supervisedLearningRate,
             visibleDropout,
             hiddenDropout,
             miniBatchSize,
             momentumMax,
             maxEpochs):
  trainVectors, trainLabels =\
    readmnist.read(0, args.trainSize, digits=None, bTrain=True, path=args.path)

  testVectors, testLabels =\
      readmnist.read(args.trainSize,  args.trainSize + args.testSize,
                     digits=None, bTrain=True, path=args.path)

  trainVectors, trainLabels = shuffle(trainVectors, trainLabels)

  trainVectors = np.array(trainVectors, dtype='float')
  trainingScaledVectors = scale(trainVectors)

  testVectors = np.array(testVectors, dtype='float')
  testingScaledVectors = scale(testVectors)

  trainVectorLabels = labelsToVectors(trainLabels, 10)

  net = db.DBN(5, [784, 1000, 1000, 1000, 10],
                  binary=False,
                  unsupervisedLearningRate=unsupervisedLearningRate,
                  supervisedLearningRate=supervisedLearningRate,
                  momentumMax=momentumMax,
                  nesterovMomentum=True,
                  rbmNesterovMomentum=True,
                  activationFunction=Rectified(),
                  rbmActivationFunctionVisible=Identity(),
                  rbmActivationFunctionHidden=RectifiedNoisy(),
                  rmsprop=True,
                  visibleDropout=0.8,
                  hiddenDropout=0.5,
                  weightDecayL1=0,
                  weightDecayL2=0,
                  rbmHiddenDropout=1.0,
                  rbmVisibleDropout=1.0,
                  miniBatchSize=miniBatchSize,
                  # TODO: make this a learned param
                  preTrainEpochs=100,
                  sparsityConstraintRbm=False,
                  sparsityTragetRbm=0.01,
                  sparsityRegularizationRbm=None)

  net.train(trainingScaledVectors, trainVectorLabels,
            maxEpochs=maxEpochs, validation=args.validation)

  proabilities, predicted = net.classify(testingScaledVectors)
  error = getClassificationError(predicted, testLabels)
  print "error", error
  return error


# Write a function like this called 'main'
def main(job_id, params):
  print 'params', params
  return trainDBN(unsupervisedLearningRate=params['unsupervisedLearningRate'][0],
                  supervisedLearningRate=params['supervisedLearningRate'][0],
                  visibleDropout=params['visibleDropout'][0],
                  hiddenDropout=params['hiddenDropout'][0],
                  miniBatchSize=params['miniBatchSize'][0],
                  momentumMax=params['momentumMax'][0],
                  maxEpochs=params['maxEpochs'][0])
{'fraction_non_alphanumeric': 0.09201109975171608, 'fraction_numerical': 0.015189133927267416, 'mean_word_length': 2.535363964894166, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '3389629', 'n_tokens_mistral': 2073, 'n_tokens_neox': 1865, 'n_words': 353}