Esempio n. 1
0
/* Creates a fully recurrent network, where a
     single layer contains all neurons. The
     input layer maps directly to the first
     'num_inputs' of the neurons, and the 
     output layer is the last 'num_outputs' 
     neurons.
   THE WEIGHTS MATRIX:
     + rank <- current neuron
     + file <- neuron which current connects TO
     + The first 'num_inputs' are inputs
     + The last 'num_outputs' are outputs */
FANN_EXTERNAL struct fann *FANN_API fann_create_fully_recurrent(
	unsigned int num_neurons, 
	unsigned int num_inputs, 
	unsigned int num_outputs)
{
    struct fann *ann = NULL;
    
    struct fann_descr descr;
    unsigned int j = 0;
    int exit_error=0;

	assert(num_outputs <= num_neurons);

	/* Create and setup the layers the n-1 hidden layer descriptors*/
	if(fann_setup_descr(&descr, 1, num_inputs) != 0)
	{
		fann_error(NULL, FANN_E_CANT_ALLOCATE_MEM);
		return NULL;
	}

    /* Create single layer with 'num_neurons' MIMO neurons*/
	exit_error = fann_setup_layer_descr(
				descr.layers_descr,
				"fully_recurrent",
				num_neurons,
				NULL
				);

	/* Number of outputs from output layer are the number*/
	/*   of MIMO neurons in it, each MIMO neuron having*/
	/*   a single output*/
	for (j=0; j<descr.layers_descr->num_neurons && ! exit_error; j++)
	{
		exit_error = fann_setup_neuron_descr(
				descr.layers_descr->neurons_descr + j,
				1,
				"fully_recurrent",
				NULL);

		if (exit_error)
		{
			/*FIXME: cleanup neurons*/
			break;
		}
	}

	if (exit_error)
	{
		fann_error(NULL, FANN_E_CANT_ALLOCATE_MEM);
		/*FIXME: cleanup layers*/
		return NULL;
	}

	ann = fann_create_from_descr(&descr);

	ann->network_type = FANN_NETTYPE_FULLY_RECURRENT;
	ann->num_neurons  = num_neurons;
	ann->num_input    = num_inputs;
	ann->num_output   = num_outputs;
	ann->output = ann->first_layer->outputs + ann->first_layer->num_outputs - ann->num_output;
	
    return ann;
}
Esempio n. 2
0
struct fann * setup_net(struct fann_train_data * data)
{
	struct fann *ann;
#if MIMO_FANN
#if OPTIMIZE == 0
	ann = fann_create_standard( 3, data->num_input, H_DIM, data->num_output);
	fann_set_activation_function_hidden(ann, FANN_SIGMOID_SYMMETRIC);
	fann_set_activation_function_output(ann, FANN_SIGMOID_SYMMETRIC);
#endif

#if OPTIMIZE == 1
	unsigned int i, j;
	struct fann_descr *descr=(struct fann_descr*) calloc(1, sizeof(struct fann_descr));
	fann_setup_descr(descr, 2, data->num_input);


	i=0;

	fann_setup_layer_descr(
					&(descr->layers_descr[i]),
					"connected_any_any",
					1,
					NULL
					);

		for (j=0; j< descr->layers_descr[i].num_neurons; j++)
		{
						fann_setup_neuron_descr(
							descr->layers_descr[i].neurons_descr+j,
							H_DIM,
							"scalar_rprop_sigmoid_symmetric",
							NULL
							);
		}

	i=1;

	fann_setup_layer_descr(
					&(descr->layers_descr[i]),
					"connected_any_any",
					1,
					NULL
					);

		for (j=0; j< descr->layers_descr[i].num_neurons; j++)
		{
						fann_setup_neuron_descr(
							descr->layers_descr[i].neurons_descr+j,
							data->num_output,
							"scalar_rprop_sigmoid_symmetric",
							NULL
							);
		}
	ann = fann_create_from_descr( descr );
#endif

#if OPTIMIZE >= 2
	{
		unsigned int layers[] = { data->num_input, H_DIM, data->num_output };
		/*char *type;
		asprintf(&type, "%s_%s_%s", vals(implementation), vals(algorithm), vals(activation));*/

		ann = fann_create_standard_array_typed(layer_type, neuron_type, 3,  layers);

	}
#endif
#else /*MIMO_FANN*/

#ifdef SPARSE
	ann = fann_create_sparse( SPARSE, 3, data->num_input, H_DIM, data->num_output);
#else
	ann = fann_create_standard( 3, data->num_input, H_DIM, data->num_output);
#endif
	fann_set_activation_function_hidden(ann, FANN_SIGMOID_SYMMETRIC);
	fann_set_activation_function_output(ann, FANN_SIGMOID_SYMMETRIC);

#endif /*MIMO_FANN*/ 

	fann_set_train_stop_function(ann, FANN_STOPFUNC_BIT);
	fann_set_bit_fail_limit(ann, 0.01f);
	fann_set_activation_steepness_hidden(ann, 1);
	fann_set_activation_steepness_output(ann, 1);

#if INIT_WEIGHTS == 1
	fann_randomize_weights(ann,0,1);
#endif
#if INIT_WEIGHTS == 2
	fann_init_weights(ann, data);
#endif

#ifdef USE_RPROP
	fann_set_training_algorithm(ann, FANN_TRAIN_RPROP);
#else
	fann_set_training_algorithm(ann, FANN_TRAIN_BATCH);
#endif

	return ann;
}