Example #1
0
		void NextEpoch(vector<dna>& dnas)
		{
			size_t cnt = dnas.size();
			#pragma omp parallel
			#pragma omp for
			for (short it = 0; it < cnt; ++it)
			{
				
				FANN::neural_net net;
				net.create_standard(3, data.num_input_train_data(), dnas[it].numberOfHidden, data.num_output_train_data());
				net.set_learning_rate(dnas[it].learningRate);
				net.set_learning_momentum(dnas[it].momentum);

				net.set_activation_steepness_hidden(1.0);
				net.set_activation_steepness_output(1.0);

				net.set_activation_function_hidden(FANN::LINEAR);
				net.set_activation_function_output(FANN::LINEAR);
				net.set_callback(print_fake, NULL);
				net.set_error_log(NULL);
				net.train_on_data(data, dnas[it].maxIteration,
					-1, dnas[it].desiredError);

				
				dnas[it].fitness = (1. - net.test_data(testdata))  ;
			}
		}
Example #2
0
		void PrintBest(vector<dna>& dnas, int gen)
		{
			cout << "Best gen : "<< gen << "----------" << endl;
			for (int i = 0; i < gen; ++i)
			{
				cout << endl;
				cout << "-********************-" << endl;
				cout << "fitness" << dnas[i].fitness << endl;
				cout << "learningRate" << dnas[i].learningRate << endl;
				cout << "momentum" << dnas[i].momentum << endl;
				cout << "numberOfHidden" << dnas[i].numberOfHidden << endl;
				cout << "maxIteration" << dnas[i].maxIteration << endl;
				cout << "desiredError" << dnas[i].desiredError<< endl;
				cout << "-********************-" << endl;
				cout << endl;
			}
			FANN::neural_net net;
			net.create_standard(3, data.num_input_train_data(), dnas[0].numberOfHidden, data.num_output_train_data());
			net.set_learning_rate(dnas[0].learningRate);
			net.set_learning_momentum(dnas[0].momentum);

			net.set_activation_steepness_hidden(1.0);
			net.set_activation_steepness_output(1.0);

			net.set_activation_function_hidden(FANN::SIGMOID);
			net.set_activation_function_output(FANN::SIGMOID);
			ofstream file("ErrorHistory/" + file + ".csv");
			net.set_callback(print_callback, &file);
			net.set_error_log(NULL);
			net.train_on_data(data, dnas[0].maxIteration,
				1, dnas[0].desiredError);


			cout << "----------------------" << endl;
		}
Example #3
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";
	}
}