Home | Develop | Download | Contact
example_load_training_save_test.c

Programa para el testeo de algunas funciones de la biblioteca.

Autor
Fernando Pujaico Rivera
Fecha
01-01-2012

Este programa solo hace una prueba simple de las funciones que hice mas al tun tun.
/*
* example_load_training_save_test.c
*
* Copyright 2011 Fernando Pujaico Rivera <fernando.pujaico.rivera@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*/
// ./test/example_load_training_save_test ../test/data.mlayer
#include <stdlib.h>
#include <math.h>
#include <pds/pdsra.h>
#include <pds/pdsnn.h>
#include "octplot.h"
int main(int argc, char** argv)
{
PdsNeuronML *MLayer=NULL;
PdsNnNatural i,id=0,itera,iterb;
PdsNnNatural Ntraining=100;
PdsNnNatural Ntests=4;
if(argc==1) return EXIT_FAILURE;
/******************** Cargando la red neuronal ********************/
MLayer=pds_neuronml_new_load_data(argv[1]);
if(MLayer==NULL) return EXIT_FAILURE;
// Creo el vector de entrada X.
PdsVector *X=pds_vector_new(Nin);
// Creo el vector de entrada Y.
PdsVector *Y=pds_vector_new(Nout);
/******************** Treinando la red neuronal ********************/
for(i=0;id<Ntraining;i++)
{
printf("\nEntrenando %d: id %d\n",i,id);
// Entrenando de forma negativa.
pds_generate_data_output_negative(Y); // Loading randomly a negative data vectors {X,Y}
pds_neuronml_training(MLayer,X,Y);
// Entrenando de forma positiva.
pds_generate_data_output_positive(Y); // Loading randomly a positive data vectors {X,Y}
pds_neuronml_training(MLayer,X,Y);
if( (itera==0)&&(iterb==0) ) id++;
else id=0;
}
/******************** Salvando la red neuronal ********************/
pds_neuronml_save_data(MLayer,argv[1]);
printf("\n\n");
/******************** Testando la red neuronal ********************/
char filename[128];
// Testando de forma negativa.
for(i=0;i<Ntests;i++)
{
pds_neuronml_iterate(MLayer,X,Y);
sprintf(filename,"xbad%d.png",i);
function_octplot_vector_in_png(X,"n","X[n]","octfilebad.m",filename);
}
printf("\n");
// Testando de forma positiva.
for(i=0;i<Ntests;i++)
{
pds_neuronml_iterate(MLayer,X,Y);
sprintf(filename,"xgood%d.png",i);
function_octplot_vector_in_png(X,"n","X[n]","octfilegood.m",filename);
}
/******************************************************************/
pds_vector_free(X);
pds_vector_free(Y);
return EXIT_SUCCESS;
}

Enlaces de interés

HomePage Bazaar Download Bug report Ayuda Developer Feed