void Player_neural::train(FANN::training_data &data)
{
	net.set_learning_rate(LEARNING_RATE);
	for (unsigned int i = 0; i < NB_EPOCHS; ++i)
	{
		data.shuffle_train_data();
		net.train_epoch(data);
		net.set_learning_rate(net.get_learning_rate() * LEARNING_RATE_DECAY);
	}
	net.print_connections();
}
示例#2
0
void train(Configuration *cfg)
{
	QString fileName(QDir::homePath() + "/" + QCoreApplication::applicationName() + ".ini");
	qDebug() << "using config file:" << fileName;
	QSettings settings(fileName, QSettings::IniFormat);
	const float learningRate = settings.value("learningRate", 0.8).toFloat();
	const unsigned int numLayers = settings.value("numLayers", 3).toInt();
	const unsigned int numInput = settings.value("numInput", 1024).toInt();
	const unsigned int numHidden = settings.value("numHidden", 32).toInt();
	const unsigned int numOutput = settings.value("numOutput", 1).toInt();
	const float desiredError = settings.value("desiredError", 0.0001f).toFloat();
	const unsigned int maxIterations = settings.value("maxIterations", 3000).toInt();
	const unsigned int iterationsBetweenReports = settings.value("iterationsBetweenReports", 100).toInt();

	FANN::neural_net net;
	net.create_standard(numLayers, numInput, numHidden, numOutput);
	net.set_learning_rate(learningRate);
	net.set_activation_steepness_hidden(0.5);
	net.set_activation_steepness_output(0.5);
	net.set_learning_momentum(0.6);
	net.set_activation_function_hidden(FANN::SIGMOID_SYMMETRIC);
	net.set_activation_function_output(FANN::SIGMOID_SYMMETRIC);
	net.set_training_algorithm(FANN::TRAIN_RPROP);
	net.print_parameters();

	FANN::training_data data;
	if (data.read_train_from_file(cfg->getDataSavePath().toStdString()))
	{
		qDebug() << "Wczytano dane";
		//inicjalizacja wag
		net.init_weights(data);
		data.shuffle_train_data();
		net.set_callback(printCallback, NULL);
		net.train_on_data(data, maxIterations,
			iterationsBetweenReports, desiredError);
		net.save(cfg->getNetSavePath().toStdString());
		qDebug() << "Nauczono i zapisano siec";
	}
}