Ejemplo n.º 1
0
void MainWindow::onLearnMyocardial()
{
    QString trainFileName = QFileDialog::getOpenFileName(this, tr("Open training file"),
                                                    "", tr("Training file (*.data)"));

    if(trainFileName.isEmpty())
        return;

    if(mAnn != 0)
         fann_destroy(mAnn);

    const unsigned int num_input = 3;
    const unsigned int num_output = 1;
    const unsigned int num_layers = 3;
    const unsigned int num_neurons_hidden = 5;
    const float desired_error = 0.001f;
    const unsigned int max_epochs = 50000;
    const unsigned int epochs_between_reports = 0;

     mAnn= fann_create_standard(num_layers, num_input,
        num_neurons_hidden, num_output);

     fann_set_activation_function_hidden(mAnn, FANN_SIGMOID_SYMMETRIC);
     fann_set_activation_function_output(mAnn, FANN_SIGMOID_SYMMETRIC);

     QByteArray ba = trainFileName.toLocal8Bit();

    fann_train_on_file(mAnn, ba.data(), max_epochs,
        epochs_between_reports, desired_error);

    QMessageBox::information(this, "Training Complete", QString("Training error = ") + QString::number(fann_get_MSE(mAnn)));

    ui->tabWidget->setTabEnabled(1, true);
}
int main() {
    //unsigned int layers[] = {17, 500, 400, 300, 200, 1};
    //unsigned int layerCount = sizeof(layers) / sizeof(unsigned int);
    const char* netLoadFile =
        "data/AAPL_ADBE_ATVI_COKE_EBAY_EXPE_NFLX_VA.300.250.200_100.net";
    const char* netSaveFile =
        "data/AAPL_ADBE_ATVI_COKE_EBAY_EXPE_NFLX_VA.300.250.200_200.net";

    const float desired_error = (const float) 0.10;
    const unsigned int max_epochs = 100;
    const unsigned int epochs_between_reports = 1;

    //struct fann *ann = fann_create_standard_array(layerCount, layers);
    struct fann *ann = fann_create_from_file(netLoadFile);

    fann_set_activation_function_hidden(ann, FANN_SIGMOID_SYMMETRIC);
    fann_set_activation_function_output(ann, FANN_SIGMOID_SYMMETRIC);

    printf("%s\n", netSaveFile);

    fann_train_on_file(ann,
                       "data/AAPL_ADBE_ATVI_COKE_EBAY_EXPE_NFLX_VA.train.fann", max_epochs,
                       epochs_between_reports, desired_error);

    fann_save(ann, netSaveFile);

    fann_destroy(ann);

    printf("%s\n", netSaveFile);

    return 0;
}
Ejemplo n.º 3
0
int main()
{
    const unsigned int num_input = 2;
    const unsigned int num_output = 1;
    const unsigned int num_layers = 3;
    const unsigned int num_neurons_hidden = 3;
    const float desired_error = (const float) 0.001;
    const unsigned int max_epochs = 500000;
    const unsigned int epochs_between_reports = 1000;

    struct fann *ann = fann_create_standard(num_layers, num_input,
        num_neurons_hidden, num_output);

    fann_set_activation_function_hidden(ann, FANN_SIGMOID_SYMMETRIC);
    fann_set_activation_function_output(ann, FANN_SIGMOID_SYMMETRIC);

    fann_train_on_file(ann, "xor.data", max_epochs,
        epochs_between_reports, desired_error);

    fann_save(ann, "xor_float.net");

    fann_destroy(ann);

    return 0;
}
Ejemplo n.º 4
0
/*! ann:train_on_file(file, max_epochs, epochs_between_reports, desired_error)
 *# Trains the neural network on the data in the file {{file}}, for up to
 *# {{max_epochs}} epochs, reporting every {{epochs_between_reports}}.
 *# Training stops when the error reaches {{desired_error}}
 *x ann:train_on_file("xor.data", 500000, 1000, 0.001)
 *-
 */
static int ann_train_on_file(lua_State *L)
{
	struct fann **ann;
	const char *fname;
	int max_epochs, epochs_between_reports;
	float desired_error;

	ann = luaL_checkudata(L, 1, FANN_METATABLE);
	luaL_argcheck(L, ann != NULL, 1, "'neural net' expected");

	if(lua_gettop(L) < 5)
		luaL_error(L, "insufficient parameters");

	fname = lua_tostring(L, 2);
	max_epochs = lua_tointeger(L, 3);
	epochs_between_reports = lua_tointeger(L, 4);
	desired_error = lua_tonumber(L, 5);

#ifdef FANN_VERBOSE
	printf("Training on file \"%s\" for up to %d epochs...\n", fname, max_epochs);
#endif

	fann_train_on_file(*ann, fname, max_epochs, epochs_between_reports, desired_error);
	return 0;
}
int main()
{
struct fann *ann = fann_create(1,0.7,5,72,60,30,10,3);
fann_train_on_file(ann, "training.data",200,10,0.1);
fann_save(ann, "gesture_classify.net");
fann_destroy(ann);
return 0;
}
Ejemplo n.º 6
0
int main(int argc, char *argv[])
{
	unsigned int layers[3] = {38, 17, 9};
	struct fann *ann = fann_create_standard_array(3, layers);
	fann_set_activation_function_hidden(ann, FANN_SIGMOID_SYMMETRIC);
    	fann_set_activation_function_output(ann, FANN_LINEAR);
	fann_train_on_file(ann, "scotland.data", 100000, 100, 0.00001);
	fann_save(ann, "scotland_test.net");
	fann_destroy(ann);
	return 0;
} 
int main()
{
struct fann *ann ;
ann = fann_create_from_file("gesture_classify.net");

if(ann==NULL){
	ROS_INFO("Creating an ANN....");
	ann = fann_create(1,0.7,3,16,18,20);
	ROS_INFO("Done....");
	}
fann_train_on_file(ann, "training.data",2000,100,0.1);
fann_save(ann, "gesture_classify.net");
fann_destroy(ann);
return 0;
}
Ejemplo n.º 8
0
int main(int argc, char* argv[]) {
    bool iflag, oflag, tflag, nflag, gflag;
    int flag;
    struct fann *nNetwork;
    char* inputFileName;
    char* dataFileName;
    char* outputFileName;

    srand(time(NULL));

    while((flag = getopt(argc,argv,"i:o:t:")) != -1) {
        switch(flag) {
            case 'i':
                inputFileName = optarg;
                iflag = true;
            break;
            case 'o':
                outputFileName = optarg;
                oflag = true;
            break;
            case 't':
                dataFileName = optarg;
                tflag = true;
            break;
        }
    }

    if(iflag) {
        nNetwork = fann_create_from_file(inputFileName);
    }
    else {
        nNetwork = fann_create_standard(3,NUM_IN_OUT,NUM_IN_OUT,NUM_IN_OUT);
    }

    fann_set_activation_function_hidden(nNetwork, FANN_SIGMOID_SYMMETRIC);
    fann_set_activation_function_output(nNetwork, FANN_SIGMOID_SYMMETRIC);

    if(tflag) {
        fann_train_on_file(nNetwork,dataFileName,MAX_ITERATIONS,50,ERROR);
    }

    if(oflag) {
        fann_save(nNetwork,outputFileName);
    }

    fann_destroy(nNetwork);
return 0;
}
Ejemplo n.º 9
0
int main()
{
	//FANN TRAINING:
    	const unsigned int num_input = 4;
    	const unsigned int num_output = 3;
	const unsigned int num_layers = 3;
	const unsigned int num_neurons_hidden = 4;
	const float desired_error = (const float) 0.001;
	const unsigned int max_epochs = 200000;
	const unsigned int epochs_between_reports = 1000;

	struct fann *ann = fann_create_standard(num_layers, num_input,
	num_neurons_hidden, num_output);

	fann_set_activation_function_hidden(ann, FANN_SIGMOID_SYMMETRIC);
	fann_set_activation_function_output(ann, FANN_SIGMOID_SYMMETRIC);

	fann_train_on_file(ann, "irisDataSet.data", max_epochs,
	epochs_between_reports, desired_error);

	fann_save(ann, "irisFANN_float.net");

	fann_destroy(ann);

	//FANN TESTING
	fann_type *calc_out;
	fann_type input[4];

	struct fann *annR = fann_create_from_file("irisFANN_float.net");

	input[0] = 5.1;
	input[1] = 3.5;
	input[2] = 1.4;
	input[3] = 0.2;

	calc_out = fann_run(annR, input);

	std::cout << "Testing irisFANN, with data: " << input[0] << ", " << input[1] << ", " << input[2] << ", " << input[3] << ", "
	<< ", output: " << calc_out[0] << ", " << calc_out[1] << ", " << calc_out[2] << "\n"; 

	fann_destroy(annR);
	return 0;

}
Ejemplo n.º 10
0
int main(int argc, char *argv[])
{
	int i = 0;
	const unsigned int width = 10;
	const unsigned int height = 10;
	const unsigned int num_dimensions = 3;
	
	const float desired_error = (const float) 0.001;
	const unsigned int max_epochs = 500000;
	const unsigned int epochs_between_reports = 1000;

	struct fann *ann = fann_create_som(width, height, num_dimensions);

	ann->som_params->som_topology = FANN_SOM_TOPOLOGY_HEXAGONAL;
	ann->som_params->som_neighborhood = FANN_SOM_NEIGHBORHOOD_DISTANCE;
	ann->som_params->som_learning_decay	= FANN_SOM_LEARNING_DECAY_LINEAR;
	ann->som_params->som_learning_rate = 0.01;
	ann->som_params->som_learning_rate_constant = 0.01;

	/* Example using init_weights */
	struct fann_train_data *data = fann_read_train_from_file("som_train.data");

	for (i = 1; i < argc; i++) {
		if (strcmp(argv[i], "-init") == 0)
			fann_init_weights_som(ann, data);
		else if (strcmp(argv[i], "-epoch") == 0) {
			fann_train_epoch(ann, data);
			return EXIT_SUCCESS;
		}
	}

	/* Example without init_weights (random initialization)*/
	fann_train_on_file(ann, "som_train.data", max_epochs, epochs_between_reports, desired_error);

	/*fann_save(ann, "som_train.net"); */

	fann_destroy(ann);

	printf("\n");
	return 0;
}
Ejemplo n.º 11
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.º 12
0
int main_sample()
{
	const unsigned int num_input = 2;
	const unsigned int num_output = 1;
	const unsigned int num_layers = 3;
	const unsigned int num_neurons_hidden = 3;
	const float desired_error = (const float) 0.001;
	const unsigned int max_epochs = 500000;
	const unsigned int epochs_between_reports = 1000;

	struct fann *ann = fann_create_standard(num_layers, num_input,
		num_neurons_hidden, num_output);

	fann_set_activation_function_hidden(ann, FANN_SIGMOID_SYMMETRIC);
	fann_set_activation_function_output(ann, FANN_SIGMOID_SYMMETRIC);

	fann_train_on_file(ann, "xor.data", max_epochs,
		epochs_between_reports, desired_error);

	fann_save(ann, "xor_float.net");

	fann_type *calc_out;
	fann_type input[2];

	//ann = fann_create_from_file("xor_float.net");

	input[0] = -1;
	input[1] = 1;
	calc_out = fann_run(ann, input);

	printf("xor test (%f,%f) -> %f\n", input[0], input[1], calc_out[0]);

	fann_destroy(ann);

	getchar();
	return 0;
}
Ejemplo n.º 13
0
 void Classifier::trainFromFile(const std::string &filename) {
     fann_train_on_file(neuralNetwork, filename.c_str(), maxEpochs,
                        printEpochs, reqError);
 }
Ejemplo n.º 14
0
int main()
{
    const unsigned int max_epochs = 1000;
    const unsigned int epochs_between_reports = 10;
    
    const unsigned int num_input = 48*48;
    const unsigned int num_output = 30;
    const unsigned int num_layers = 2;
    const unsigned int num_neurons_hidden = 25;
    
    const float desired_error = (const float) 0.0000;
   
    fann_type *calc_out;
    unsigned int i;
    int incorrect,ret = 0;
    int orig,pred; float max =0 ;
    float learning_rate = 0.01;
    
    
    struct fann *ann = fann_create_standard(num_layers, num_input, num_output);

    fann_set_activation_function_hidden(ann, FANN_SIGMOID);
    fann_set_activation_function_output(ann, FANN_LINEAR);
    fann_set_learning_rate(ann, learning_rate);
    
    fann_train_on_file(ann, "facial-train.txt", max_epochs,
        epochs_between_reports, desired_error);

    fann_reset_MSE(ann);
    
    
    
    struct fann_train_data *data = fann_read_train_from_file("facial-test.txt");
    
    printf("Testing network..\n");
    
    for(i = 0; i < fann_length_train_data(data); i++) {
        
        calc_out = fann_test(ann, data->input[i], data->output[i] );
        
        printf ("%i ", i );
       
        max = calc_out[0];
        int maxo = data->output[i][0];
        
        for (int n=0; n<30; n++) {
            printf (" %.2f/%.2f(%.2f) ",calc_out[n]*(2*96), data->output[i][n]*(2*96), data->output[i][n]*(2*96) - calc_out[n]*(2*96)  );
           
            
            
        }
        
        printf ("\n");
        
       
    }
    
    printf("Mean Square Error: %f\n", fann_get_MSE(ann));
    //printf ("Incorrect %i\n", incorrect);
    
    fann_save(ann, "facial.net");

	fann_destroy_train(data);
	fann_destroy(ann);


	
    return 0;
}