struct fann *nn_fann_NeuralNet2Fann(NeuralNet *NN) { struct fann_connection *ConnectionsANN; struct fann_connection *ConnectionsNN; PGM_Vetor_Int Neurons; struct fann *ANN; MemoryContext contextoAnterior = MemoryContextSwitchTo( CurTransactionContext ); Neurons.n_elems = NN->NLayers; Neurons.valor = (int*) NN->NNeurons; ANN = nn_fann_train_create_standard_array(&Neurons,NN->Steepness,NN->FunctionActivation); nn_fann_parse_fann_set_scaling_default(ANN); MemoryContextSwitchTo( contextoAnterior ); ConnectionsANN = (struct fann_connection*) pgm_malloc(sizeof(struct fann_connection) * ANN->total_connections); ConnectionsNN = (struct fann_connection*) pgm_malloc(sizeof(struct fann_connection) * ANN->total_connections); fann_get_connection_array(ANN,ConnectionsANN); nn_fann_parse_nn_get_connection2(NN->NLayers,(int*)NN->NNeurons,ConnectionsNN); nn_fann_parse_adjust_get_weightByNeuralNet(NN, ANN, ConnectionsANN,ConnectionsNN); nn_fann_parse_fann_set_scaling(ANN,NN->InputMin,NN->InputMax,NN->OutputMin,NN->OutputMax); nn_fann_parse_setBihiperbolicParam(ANN,NN->BihiperbolicLambda,NN->BihiperbolicT1,NN->BihiperbolicT2); return ANN; }
void fann_save_matrices(struct fann *network, char *fname){ unsigned int layers; unsigned int layer[100]; unsigned int bias[100]; unsigned int total_weights; unsigned int neuron_inputs; unsigned int writes_counter; DATA_TYPE weight; struct fann_connection *connections; FILE *array; char array_name[255]; int i, j; writes_counter = 0; layers = fann_get_num_layers(network); fann_get_layer_array(network, layer); fann_get_bias_array(network, bias); total_weights = fann_get_total_connections(network); printf("Total weights: %i\n", total_weights); connections = (struct fann_connection *) malloc(total_weights * sizeof(struct fann_connection)); fann_get_connection_array(network, connections); for(i = 1; i < layers; i++){ sprintf(array_name, "%s_W%i.net", fname, i); array = fopen(array_name, "wb"); for (j = 0; j < layer[i]*(layer[i-1] + 1); j++){ weight = connections[writes_counter].weight; #ifdef DEBUG mexPrintf("Number:\t%i\n", writes_counter); mexPrintf("Weight:\t%e\n", connections[writes_counter].weight); mexPrintf("From:\t%i\n", connections[writes_counter].from_neuron); mexPrintf("To:\t%i\n", connections[writes_counter].to_neuron); mexEvalString("drawnow;"); #endif fwrite(&weight, sizeof(DATA_TYPE) , 1, array); writes_counter++; } fclose(array); } return; }