예제 #1
0
파일: main.cpp 프로젝트: NDobrev/NNGA
		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))  ;
			}
		}
예제 #2
0
파일: main.cpp 프로젝트: NDobrev/NNGA
		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;
		}