Ejemplo n.º 1
0
int main()
{
    const float desired_error = (const float) 0.01;
    const unsigned int max_epochs = 50000;
    const unsigned int epochs_between_reports = 10;

    unsigned int layers []= {6, 200, 200, 4};
    struct fann * ann = fann_create_standard_array(4, layers);

    fann_set_activation_function_layer(ann, FANN_SIGMOID_SYMMETRIC, 1);
    fann_set_activation_function_layer(ann, FANN_SIGMOID_SYMMETRIC, 2);
    fann_set_activation_function_layer(ann, FANN_SIGMOID_SYMMETRIC, 3);
    fann_train_on_file(ann, "../training_file", max_epochs,
                       epochs_between_reports, desired_error);

    fann_save(ann, "wii.net");

    fann_destroy(ann);

    return 0;
}
Ejemplo n.º 2
0
bool ViFann::setActivation(const Activation &activation, const int &layer)
{
	if(mNetwork == NULL) return false;

	fann_activationfunc_enum function;
	if(activation == Sigmoid) function = FANN_SIGMOID_SYMMETRIC;
	else if(activation == Elliot) function = FANN_ELLIOT_SYMMETRIC;
	else if(activation == Gaussian) function = FANN_GAUSSIAN_SYMMETRIC;
	else if(activation == Linear) function = FANN_LINEAR_PIECE_SYMMETRIC;
	else if(activation == Cosine) function = FANN_COS_SYMMETRIC;
	else if(activation == Sine) function = FANN_SIN_SYMMETRIC;
	else return false;

	fann_set_activation_function_layer(mNetwork, function, layer);
	return true;
}
Ejemplo n.º 3
0
int ftest_data(void)
{
    //	sar_start_epoch=0;
    //  printf("\r\n\r\n--------------------------------------------------------------------------------");

    double val_2[10];
    fann_type *calc_out2;
    unsigned calc2;
    int curi=0;
    unsigned fails=0,success=0;
    double perc=0;
    double minv=9,maxv=-1;
    int i;
    int minat=0,maxat=0;

    test_mse=fann_test_data(ann,test_data);

    for (curi=0;curi<fann_length_train_data(train_data);curi++)
    {

        calc2=curi;//rand()%(fann_length_train_data(train_data)-1);
        //printf("\r\ntesting %u %u ",calc1,calc2);
        //fann_scale_input(ann, test_data->input[calc1]);
        //fann_scale_input(ann, train_data->input[calc2]);
        //	fann_scale_output(ann, test_data->input[calc1]);

        //fann_scale_input(ann, train_data->input[calc2]);
        calc_out2 = fann_run(ann, train_data->input[calc2]);
        //	fann_descale_output(ann,calc_out2);

        memcpy(&val_2,  calc_out2, sizeof(double)*3);





        minv=9;
        maxv=-1;
        for (i=0;i<train_data->num_output;i++)
        {
            if ((double)calc_out2[i]<minv)
            {
                minv=val_2[i];
                minat=i;
            }
            if ((double)calc_out2[i]>maxv)
            {
                maxv=val_2[i];
                maxat=i;
            }
        }

        int ok=0;
        ok=0;
        for (i=0;i<train_data->num_output;i++)
            if (train_data->output[calc2][i]==1&&maxat==i)
                ok=1;

        if (ok)success++;
        else
            fails++;

    }
    train_perc=((double)success/(double)fann_length_train_data(train_data))*100.0f;
    /*   printf(" fails %5u success %5u (%5.2f%%) ",
             fails,success,train_perc
            ); */

    fails=0;
    success=0;
    unsigned failed_classes[10];

    for (curi=0;curi<test_data->num_output;curi++)
        failed_classes[curi]=0;

    int nfunc=0;
    double train_thr_mse=0;


    nfunc=fann_get_activation_function(ann, 3, 0);
    int stpns;
    stpns=fann_get_activation_steepness(ann,1,0);
    //	printf("\r\n%f",diff_mse*0.1f);
    //fann_set_activation_steepness_layer(ann, 0.3f, 1);
    //fann_set_activation_function_layer(ann,FANN_THRESHOLD_SYMMETRIC,3);




    for (curi=0;curi<fann_length_train_data(test_data);curi++)
    {

        calc2=curi;//rand()%(fann_length_train_data(train_data)-1);
        //printf("\r\ntesting %u %u ",calc1,calc2);
        //fann_scale_input(ann, test_data->input[calc1]);
        //fann_scale_input(ann, train_data->input[calc2]);
        //	fann_scale_output(ann, test_data->input[calc1]);

        //fann_scale_input(ann, train_data->input[calc2]);
        calc_out2 = fann_run(ann, test_data->input[calc2]);
        //	fann_descale_output(ann,calc_out2);

        memcpy(&val_2,  calc_out2, sizeof(double)*3);





        minv=9;
        maxv=-1;
        for (i=0;i<test_data->num_output;i++)
        {
            if (val_2[i]<minv)
            {
                minv=val_2[i];
                minat=i;
            }
            if (val_2[i]>maxv)
            {
                maxv=val_2[i];
                maxat=i;
            }
        }

        int ok=0;
        ok=0;
        for (i=0;i<test_data->num_output;i++)
        {
            if (test_data->output[calc2][i]==1&&maxat==i)
                ok=1;
            else if (test_data->output[calc2][i]==1&&maxat!=i)
                failed_classes[i]++;
        }

        if (ok)success++;
        else
            fails++;

    }
    test_perc=((double)success/(double)fann_length_train_data(test_data))*100.0f;
    /*   printf(" fails %5u success %5u (%5.2f%%) [fails: ",
             fails,success,test_perc
            );
      for (curi=0;curi<test_data->num_output;curi++)
          printf("%4u ",failed_classes[curi]);
      printf("] "); */
    // fann_set_activation_function_hidden ( ann,  rand()*0.81);
    // printf("\r\n rpropfact dec/inc r %.5f %.5f lr %.5f mom %.5f",fann_get_rprop_decrease_factor(ann),fann_get_rprop_increase_factor(ann), fann_get_learning_rate ( ann),
    //       fann_get_learning_momentum(ann));

    //	rebuild_functions();

    fann_set_activation_function_layer(ann,nfunc,3);
    fann_set_activation_steepness_layer(ann,stpns, 1);
}