<commit_before>#!/usr/bin/env python

"""
Train ISA model on natural images patches with noise added.
"""

import sys

sys.path.append('./code')

from numpy import *
from numpy.random import randn
from models import ISA, GSM
from tools import preprocess, Experiment

# PS, SS, OC, ND, MI, NS
parameters = [
	['8x8',   1, 1, 100, 200, 32.],
	['10x10', 1, 1, 100, 200, 32.],
	['12x12', 1, 1, 100, 200, 32.],
	['14x14', 1, 1, 100, 200, 32.],
	['16x16', 1, 1, 100, 200, 32.],
]

def main(argv):
	if len(argv) < 2:
		print 'Usage:', argv[0], '<params_id>'
		print
		print '  {0:>3} {1:>5} {2:>3} {3:>3} {4:>5} {5:>4} {6:>4}'.format('ID', 'PS', 'SS', 'OC', 'ND', 'MI', 'NS')

		for id, params in enumerate(parameters):
			print '  {0:>3} {1:>5} {2:>3} {3:>3} {4:>4}k {5:>4} {6:>4.0f}'.format(id, *params)

		print
		print '  ID = parameter set'
		print '  PS = patch size'
		print '  SS = subspace size'
		print '  OC = overcompleteness'
		print '  ND = number of training points'
		print '  MI = maximum number of training epochs'
		print '  NS = inverse noise level'

		return 0

	seterr(invalid='raise', over='raise', divide='raise')

	# some hyperparameters
	patch_size, ssize, overcompleteness, num_data, max_iter, noise_factor = parameters[int(argv[1])]
	num_data *= 1000

	experiment = Experiment()

	# load and whiten data
	data = load('data/vanhateren.{0}.1.npz'.format(patch_size))['data']
	data = asarray(data, dtype='float64')

	# normalize data and add noise
	data -= mean(data)
	data /= std(data)
	data += randn(*data.shape) / float(noise_factor)

	# create and train model
	model = ISA(data.shape[0], data.shape[0] * overcompleteness, ssize=ssize)
	model.train(data[:, :num_data], max_iter=max_iter)

	# save results
	experiment['model'] = model
	experiment['parameters'] = parameters[int(argv[1])]
	experiment.save('results/experiment01b/experiment01b.{0}.{1}.xpck')

	return 0



if __name__ == '__main__':
	sys.exit(main(sys.argv))
<commit_msg>Forgot to log-transform data.<commit_after>#!/usr/bin/env python

"""
Train ISA model on natural images patches with noise added.
"""

import sys

sys.path.append('./code')

from numpy import *
from numpy.random import randn
from models import ISA, GSM
from tools import preprocess, Experiment

# PS, SS, OC, ND, MI, NS
parameters = [
	['8x8',   1, 1, 100, 150, 32.],
	['10x10', 1, 1, 100, 150, 32.],
	['12x12', 1, 1, 100, 150, 32.],
	['14x14', 1, 1, 100, 150, 32.],
	['16x16', 1, 1, 100, 150, 32.],
]

def main(argv):
	if len(argv) < 2:
		print 'Usage:', argv[0], '<params_id>'
		print
		print '  {0:>3} {1:>5} {2:>3} {3:>3} {4:>5} {5:>4} {6:>4}'.format('ID', 'PS', 'SS', 'OC', 'ND', 'MI', 'NS')

		for id, params in enumerate(parameters):
			print '  {0:>3} {1:>5} {2:>3} {3:>3} {4:>4}k {5:>4} {6:>4.0f}'.format(id, *params)

		print
		print '  ID = parameter set'
		print '  PS = patch size'
		print '  SS = subspace size'
		print '  OC = overcompleteness'
		print '  ND = number of training points'
		print '  MI = maximum number of training epochs'
		print '  NS = inverse noise level'

		return 0

	seterr(invalid='raise', over='raise', divide='raise')

	# some hyperparameters
	patch_size, ssize, overcompleteness, num_data, max_iter, noise_level = parameters[int(argv[1])]
	num_data *= 1000

	experiment = Experiment()

	# load and whiten data
	data = load('data/vanhateren.{0}.1.npz'.format(patch_size))['data']

	# log-transform data
	data[data == 0] = 1
	data = log(asarray(data, dtype='float64'))

	# normalize data and add noise
	data -= mean(data)
	data /= std(data)
	data += randn(*data.shape) / float(noise_level)

	# create model
	model = ISA(data.shape[0], data.shape[0] * overcompleteness, ssize=ssize)

	# initialize, train and finetune model
	model.train(data[:, :10000], max_iter=15)
	model.train(data[:, :num_data], max_iter=max_iter)
	model.train(data[:, :num_data], max_iter=5, method=('sgd', {'step_width': 1E-4}))

	# save results
	experiment['model'] = model
	experiment['parameters'] = parameters[int(argv[1])]
	experiment.save('results/experiment01b/experiment01b.{0}.{1}.xpck')

	return 0



if __name__ == '__main__':
	sys.exit(main(sys.argv))

{'fraction_non_alphanumeric': 0.18731848983543078, 'fraction_numerical': 0.060503388189738626, 'mean_word_length': 4.2851662404092075, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 33, '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': '1343827', 'n_tokens_mistral': 1850, 'n_tokens_neox': 1620, 'n_words': 430}