示例#1
0
文件: dnn.py 项目: jwlin/mlds-mp1
		)

for t in xrange(epoch_cycle):
	print 'epoch', t
	current_cost = 0
	#validate_cost = 0
	x_batch, y_hat_batch, batch_num = DataParser.make_batch(batch_size)
	#x_batch = [[[-2.50, -1.39], [-2.50, 0.92]], [[-2.50, -1.39], [-2.49, 0.93]], [[-2.50, -1.39], [-2.48, 0.94]]]
	#y_hat_batch = [[[0,1]], [[0,1]], [[0,1]]]
	for i in xrange(batch_num):
		c_cost = train(x_batch[i], y_hat_batch[i])
		#print 'c_cost', c_cost
		current_cost += c_cost
	current_cost /= batch_num
	print 'current_cost', current_cost
	DataParser.save_parameters(parameters)
	#current_validate_cost = validate(validation_set)
	#print 'validate cost', current_validate_cost
	#if current_validate_cost < validate_cost:
	#	validate_cost = current_validate_cost
	#else:
	#	break

test_data, test_id = DataParser.load_test_data(sample_file)
result = test(test_data)
result = list(result)
result = map(list, zip(*result))  # transpose
with open('result.txt', 'w') as f:
	for i in xrange(len(result)):
		f.write(test_id[i] + ',')
		max_value = 0
示例#2
0
		)

for t in xrange(epoch_cycle):
	print 'epoch', t
	current_cost = 0
	#validate_cost = 0
	x_batch, y_hat_batch, batch_num = DataParser.make_batch(batch_size)
	#x_batch = [[[-2.50, -1.39], [-2.50, 0.92]], [[-2.50, -1.39], [-2.49, 0.93]], [[-2.50, -1.39], [-2.48, 0.94]]]
	#y_hat_batch = [[[0,1]], [[0,1]], [[0,1]]]
	for i in xrange(batch_num):
		c_cost = train(x_batch[i], y_hat_batch[i])
		#print 'c_cost', c_cost
		current_cost += c_cost
	current_cost /= batch_num
	print 'current_cost', current_cost
	DataParser.save_parameters(parameters, 'parameter.txt')
	DataParser.save_parameters(grad_hists, 'parameter-g.txt')
	#current_validate_cost = validate(validation_set)
	#print 'validate cost', current_validate_cost
	#if current_validate_cost < validate_cost:
	#	validate_cost = current_validate_cost
	#else:
	#	break

test_data, test_id = DataParser.load_test_data(sample_file)
result = test(test_data)
result = list(result)
result = map(list, zip(*result))  # transpose
with open('result.txt', 'w') as f:
	for i in xrange(len(result)):
		f.write(test_id[i] + ',')