Beispiel #1
0
// Callback function that simply prints the information to cout
int print_callback(FANN::neural_net &net, FANN::training_data &train,
    unsigned int max_epochs, unsigned int epochs_between_reports,
    float desired_error, unsigned int epochs, void *user_data)
{
    cout << "Epochs     " << setw(8) << epochs << ". "
         << "Current Error: " << left << net.get_MSE() << right << endl;
    return 0;
}
Beispiel #2
0
// Callback function that simply prints the information to cout
int printCallback(FANN::neural_net &net, FANN::training_data &train,
	unsigned int max_epochs, unsigned int epochs_between_reports,
	float desired_error, unsigned int epochs, void *user_data)
{
	qDebug() << "epoka: " << epochs << " " << "blad: " << net.get_MSE();
	//zapisac do pliku
	return 0;
}
Beispiel #3
0
// Callback function that simply prints the information to cout
int print_callback(FANN::neural_net &net, FANN::training_data &train,
	unsigned int max_epochs, unsigned int epochs_between_reports,
	float desired_error, unsigned int epochs, void *user_data)
{
	ofstream &eh = *(static_cast<ofstream*>(user_data));
	eh << net.get_MSE() << " ";
	return 0;
}
Beispiel #4
0
int trainingThread::print_callback(FANN::neural_net &net, FANN::training_data &train,
                                   unsigned int max_epochs, unsigned int epochs_between_reports,
                                   float desired_error, unsigned int epochs, void *user_data)
{
    static int i_old = 0;
    std::stringstream log;
    log << "Epochs     " << std::setw(8) << epochs << ". "
        << "Current Error: " << std::left << net.get_MSE() << std::right << std::endl;

    //

    int i = (epochs * 100 )/ max_epochs;
    if (i != i_old )
    {
        qDebug() << "i ma : " << i << " max_epochs " << max_epochs;
        //emit updateProgressBar(i);
        static_this->updateProgressBar(i);
        static_this->updateLog(QString::fromStdString(log.str()));
        i_old = i;
    }
    return 0;

}
Beispiel #5
0
int callback_html(FANN::neural_net &rede_neural,
	 training_data &dados,
	 unsigned int turnos_max,
	 unsigned int turnos_por_amostra,
	 float margem_de_erro,
	 unsigned int turnos,
	 void *_cerebro){

	 static FILE *plot = NULL;

 	 static float total = 0;
 	 static float last_MSE = 0;
 	 static float last_bit_fail = 0;

	 static int loops = 0;
	 static int MSE_counter = 0;
	 static int bit_fail_counter = 0;
	 static float steepness = 0;
	 static float aprendizagem = 0;
	 static float last_aprendizagem = 0;
	 static float aprendizagem_inicial = 0;

	 static bool set_steepness = false;
	 static bool set_aprendizagem = false;

	 static training_data *dados_teste = NULL;

	 char buffer[20000];
	 char MSE_buffer[64];
	 char bit_fail_buffer[64];
	 float diferenca_MSE;
	 float MSE;
	 int bit_fail = 0;
	 int diferenca_bit_fail = 0;

	 CCerebro *cerebro = (CCerebro*)_cerebro;

	 if(dados_teste){
		//rede_neural.reset_MSE();
		//printf("%f ", rede_neural.get_MSE());
		MSE = rede_neural.test_data(*dados_teste);
		//printf("%f\n", MSE);
	 }
	MSE = rede_neural.get_MSE();

	 bit_fail = rede_neural.get_bit_fail();

	//rede_neural.reset_MSE();

	//printf("%f %f %d\n", MSE, last_MSE, (MSE - last_MSE) > 0.000001);
	if(last_MSE)
		diferenca_MSE = (last_MSE - MSE);
	else
		diferenca_MSE = 0;

	if(last_bit_fail)
		diferenca_bit_fail = last_bit_fail - bit_fail;
	else
		diferenca_bit_fail = 0;

	if(last_bit_fail == bit_fail){
		if(bit_fail_counter < BIT_FAIL_COUNTER)
		bit_fail_counter++;
	}else if(bit_fail_counter > 0)
		bit_fail_counter--;// = bit_fail_counter * 0.85;

	if(fabs(diferenca_MSE) < margem_de_erro){
		if(MSE_counter < MSE_COUNTER)
			MSE_counter++;
	}else if(MSE_counter > 0)
			MSE_counter--;// = MSE_counter * 0.9;

	//printf("%d\n", bit_fail_counter);
	//printf("%f %f\n",last_MSE, diferenca_MSE);
	if(last_MSE){
		fprintf(plot, "%d %f %f %d %d\n",turnos, MSE, diferenca_MSE, bit_fail_counter, MSE_counter);
		fflush(plot);
		total = total + diferenca_MSE;
	}

	last_MSE = MSE;
	last_bit_fail = bit_fail;

	if(set_aprendizagem){
		if(!aprendizagem_inicial)
			aprendizagem_inicial = cerebro->rede_neural->get_learning_rate();

		aprendizagem = (1-((float)(MSE_counter + bit_fail_counter) / 200)) * aprendizagem_inicial;
		if(!last_aprendizagem)
			last_aprendizagem = aprendizagem;

		if(last_aprendizagem > aprendizagem && !((MSE_counter + bit_fail_counter)%2)){
			rede_neural.set_learning_rate(aprendizagem);
			last_aprendizagem = aprendizagem;
		}
	}

	if(set_steepness){
		if(!steepness)
			steepness = rede_neural.get_activation_steepness(1,0);

		rede_neural.set_activation_steepness_layer(
			(1-((float)(MSE_counter + bit_fail_counter) / 100))*steepness
			,1);
			//set_sneepness = true;
	}

	loops++;
	if(turnos > 1){
		if(loops < LOOPS && (bit_fail_counter < BIT_FAIL_COUNTER || MSE_counter < MSE_COUNTER) )
			return 0;
	}else{
		bit_fail_counter = 0;
		MSE_counter = 0;
		last_aprendizagem = 0;

		if(dados_teste)
			free(dados_teste);

		if(plot)
			fclose(plot);
/*
		dados_teste = new training_data();
		if(cerebro->getDadosIdentificadosEscalados()){
			dados_teste->set_train_data(cerebro->num_dados_identificados,
					cerebro->num_caracteristicas, cerebro->dados_identificados_escalados,
					cerebro->num_caracteristicas, cerebro->dados_identificados_escalados);
			printf("Utilizando massa de testes identificada com %d casos.\n",cerebro->num_dados_identificados );
		}else if(cerebro->getDadosEscalados()){
			dados_teste->set_train_data(cerebro->num_dados,
						cerebro->num_caracteristicas, cerebro->dados_escalados,
						cerebro->num_caracteristicas, cerebro->dados_escalados);
			printf("Utilizando massa de testes não identificada com %d casos.\n",cerebro->num_dados );
		}else{
			printf("Sem dados para treinar.\n");
			delete dados_teste;

			return -1;
		}
*/
		printf("Plotando em %s.\n",cerebro->plot_file);
		plot = fopen(cerebro->plot_file, "w");
	}
	loops = 0;

	memset(buffer,0,20000);

	//clear_screen();

	cor_nivel(bit_fail_counter,bit_fail_buffer);
    cor_nivel(MSE_counter,MSE_buffer);

	//printf("%f\n",round((float)bit_fail_counter/10));
	sprintf((char*)(buffer + strlen(buffer)), "%08d turnos, precisão %1.8f(%-1.8f)(%s%%), nivel de adaptacao %d(%d)(%s%%)",
											  turnos, MSE, diferenca_MSE, MSE_buffer, bit_fail, diferenca_bit_fail, bit_fail_buffer);
	sprintf((char*)(buffer + strlen(buffer)),", depuracao %-1.6f, aprendizagem %f, passo %f", total,last_aprendizagem,steepness);
	sprintf((char*)(buffer + strlen(buffer)),"\n");
	printf(buffer);
	//textcolor(RESET, WHITE, BLACK);
	//rede_neural.print_connections(buffer);
	//printf(buffer);


	if(bit_fail_counter == BIT_FAIL_COUNTER && MSE_counter == MSE_COUNTER){
			printf("Treino completado em %08d, adaptacao %d, MSE %f\n",turnos, bit_fail, MSE);
			return -1;
		}

	return 0;
}