на тему рефераты
 
Главная | Карта сайта
на тему рефераты
РАЗДЕЛЫ

на тему рефераты
ПАРТНЕРЫ

на тему рефераты
АЛФАВИТ
... А Б В Г Д Е Ж З И К Л М Н О П Р С Т У Ф Х Ц Ч Ш Щ Э Ю Я

на тему рефераты
ПОИСК
Введите фамилию автора:


Реферат: Классификация сейсмических сигналов на основе нейросетевых технологий


Debug=Yes

#

# Next parameters was define in result experiments and if you will

# change it, the any characteristics of Neural Net may be not optimal

# (since may be better then optimal).

#

# # # # # # # # # # #

# 'NetStructure' must be: [NDATA,NUNIT1,1]  (NOUT=1  always)

#  value 'AUTO'-'NetStructure' will be define the programm.(See help).

#        example : [18,9,1], or [18,18,1], or [9,9,5,1]

NetStructure=[18,12,1]

#  may be:  [Gauss] or [Random]

InitWeigthFunc=Gauss

Constant=3

Alfa=0

Sigma=1.5

Widrow=No

Shuffle=Yes

Scaling=Yes

LearnTolerance=0.1

Eta=1

MaxLearnCycles=50

Loop=3

#end of list

4.    Пример файла отчета.

NVCLASS report - Wed Jun 02 15:58:02 1999

    Type = 1_2

    Neural Net     - <18,12,1>

    PatternFile    - vect.txt

    Test Vector(s) - vector.tst

    ResNetFname    - 12.net

    LearnTolerance = 0.10

    InitialWeigthFunc = Gauss[ 0.0, 1.5]

     < Loop 1 >     

Learning cycle result:

   NumIter = 5

   NumLE   = 3

   Error vector(s): 58, 59, 63,

+-----+------+--------+------+

|  N  |  ID  | Result |Target|

+-----+------+--------+------+

|   1 |   24 | 0.1064 |   0  |

|   2 |   25 | 0.9158 |   1  |

|   3 |   26 | 0.0452 |   0  |

|   4 |   27 | 0.0602 |   0  |

|   5 |   28 | 0.0348 |   0  |

|   6 |   29 | 0.0844 |   0  |

|   7 |   30 | 0.1091 |   0  |

|   8 |   31 | 0.0821 |   0  |

|   9 |   32 | 0.0298 |   0  |

|  10 |   33 | 0.2210 |   0  |

+-----+------+--------+------+

     < Loop 2 >     

Learning cycle result:

   NumIter = 5

   NumLE   = 5

   Error vector(s): 33, 34, 55, 58, 63,

+-----+------+--------+------+

|  N  |  ID  | Result |Target|

+-----+------+--------+------+

|   1 |   24 | 0.1279 |   0  |

|   2 |   25 | 0.9929 |   1  |

|   3 |   26 | 0.0960 |   0  |

|   4 |   27 | 0.1463 |   0  |

|   5 |   28 | 0.1238 |   0  |

|   6 |   29 | 0.1320 |   0  |

|   7 |   30 | 0.1478 |   0  |

|   8 |   31 | 0.1235 |   0  |

|   9 |   32 | 0.0740 |   0  |

|  10 |   33 | 0.5140 |   1  |

+-----+------+--------+------+

5.    Файл описания функций, типов переменных и используемых библиотек “nvclass.h”.

/*

 *  ---  Neuro classificator---

 *

 *   Common defines

 */

#include <stdio.h>

#include <ctype.h>

#include <stdlib.h>

#include <string.h>

#include <stdarg.h>

#include <time.h>

#include <math.h>

//#include <unistd.h>

//#include <sys/file.h>

#include <fcntl.h>

#define DefName      "nvclass.inp"

#define MAXDEF       100

#define MAXLINE      256

#define NMAXPAT      100

#define NMXINP       20

#define NMXUNIT      20

#define CONT      0

#define EXIT_OK         1

#define EXIT_CNT     2

#define RESTART      911

#define MAXEXP       700   /*  Max arg  exp(arg) without error 'OVERFLOW' */

#define Random       10

#define Gauss        20

#define OK         0

#define Error        1

#define Yes          77

#define No         78

#define Min          0    /* Find_MinMax(...)   */

#define Max          1

#define TYPE_ONE     21

#define TYPE_TWO     22

#define TYPE_THREE   23

#define TYPE_FOUR    24

int    NDATA  =  0;

int       NUNIT1 =  0;

int         NUNIT2 =  0;

int   NUNIT3 =  0;

int         NOUT   =  1;

int   NPATTERN = 0;         /* Number of input pattern*/

int   NWORK    = 0;         /* Number of work pattern*/

int        NTEST= 0;         /* Number of test pattern*/

int   result;

int   STOP = 0;

int NumOut = 250; /* Number of itteration, after which show result in debugfile. */

int Num_Iter=10;/* The parameters requred in the procecc of  */

float Percent=0.25;   /* dinamic lerning with change 'eta' */

float     LearnTolerance = 0.10;

float     TestTolerance = 0.5;

float     MAX_ERR=0.00001;   /* min error */

float     eta = 1.0;         /* learning coefficient*/

float     MIN_ETA=0.000001;

float     **Array_MinMax;

int       *Cur_Number;

float     W1[NMXINP][NMXUNIT];

float     W2[NMXUNIT];

float     PromW1[NMXINP][NMXUNIT];

float     PromW2[NMXUNIT];

float     PromW1_OLD[NMXINP][NMXUNIT];

float     PromW2_OLD[NMXUNIT];

float     Err1[NMXUNIT];

float     Err2;

float     OLD_ERROR;

float     GL_Error=0.0;

float     Out1[NMXUNIT];

float     Out2;

char NetStr[20]="Auto"; /* String with pattern of Net Structure*/

int  Type = TYPE_THREE; /* Enter the mode of work of programm */

int InitFunc = Random; /* Random [=10] weigth will RandomDistribution  Gauss  [=20]  - ... GaussianDistributon  */

float      Constant = 1; /* RandomDistribution [-Constant,Constant]*/

float    Alfa = 0;    /* GaussianDistribution [Alfa,Sigma]*/

float      Sigma = 1; /* ...                              */

int        Widrow = No; /* Nguyen-Widrow initialization start weigth*/

int  Loop = 1;             /* Number repeat of Learning cycle */

char    *PatternFile;      /* File with input patterns*/

char    *TestVector;

char   *ReportFile="report.txt";    /* name of report file */

char       *NetworkFile;    /* Name of input NetConfig file */

char       *ResNetFname;    /* Name of output NetConfig file */

int        DEBUG = Yes; /* if 'Yes' then debug info in the DebugFile */

char       *DebugFile="Logfile.log";  /* Name of the debug file*/

int        NumberVector = 0;     /* Number of TEST vector */

int        Shuffle = Yes;        /* Flag - shuffle the input vectors*/

int        Scaling = Yes;         /* Scaling input vector */

int        MaxLearnCycles = 1999; /* Max number of learning iteration */

FILE      *Dfp;                  /* Debug file pointer */

FILE      *Rfp;                  /* Report file pointer*/

typedef struct Pattern {

     int ID;     /* ID number this vector in all set of pattern */

     float *A;   /* pattern (vector) A={a[0],a[1],...,a[NDATA]} */

     float Target;      /* class which this vector is present*/

} PAT;

PAT   *Input;

PAT   *Work;

PAT   *Test;

/* lines in defaults file are in the form "NAME=value" */

typedef struct Default {

     char *name;          /* name of the default */

     char *value;         /* value of the default */

} DEF;

/* structure of statistics info about one test vector */

typedef struct Statistic {

     int     ID;        /* Primery number from input file */

     float   Target;

     float   TotalRes;  /* Total propability */

     int     Flag;      /* Flag = 1, if vector was error and = 0

                          in over case */

     float   *result;  /* Result of testing vector on current

                          iteration */

     int     *TmpFlag;  /* analog 'Flag' on current itteration */

     int     *NumIter; /* Number iteration of learning on which

                          Learning cycle  STOPED */

     int     **NumLE;  /* Error vectors after cycle of learning

                          was test*/

} STAT;

/* structure of the some result of learning cycle */

typedef struct ResLearning {

     int    NumIter;

     int    LearnError[NMAXPAT+1];       /* A[0]-count of error,

                        A[1]-ID1,

                        A[2]-ID2,...

                        A[NMAXRL]-ID?.*/

} RL;

/* function prototypes */

void       OnlyTestVector(void);

void       TestAfterLearn (void);

void       CheckOneVector ( void );

void       CrossValidation ( void );

DEF        **defbuild(char *filename);

DEF        *defread(FILE *fp);

FILE    *defopen (char *filename);

char    *defvalue(DEF **deflist, const char *name);

int          defclose(FILE *fp);

void    defdestroy(DEF **, int);

void         getvalues(void);

void       Debug (char *fmt, ...);

void       Report (char *fmt, ...);

void       Widrow_Init(void);

int        Init_W( void );

float      RavnRaspr(float A, float B);

float      NormRaspr(float B,float A);

void       ShufflePat(int *INP,int Koll_El);

float      F_Act(float x);

float      Forward (PAT src);

int        LearnFunc (void);

int        Reset (float ResErr, int Cnt, int N_Err);

void       Update_Last (int n, float Total_Out);

void       Update_Prom1 (int n);

void       Prom_to_W (void);

void       Update_All_W (int num, float err_cur );

void       Init_PromW(void);

void       Prom_to_OLD(void);

int        CheckVector(float Res, PAT src);

int        *TestLearn(int *src);

RL         FurtherLearning(int   NumIteration,

                 float StartLearnTolerans,

                 float EndLearnTolerans,

                 RL    src);

STAT       *definestat (PAT src);

STAT       **DefineAllStat (PAT *src,int Num);

void       FillStatForm (STAT *st, int iteration, float res, RL lr);

void       FillSimpleStatForm (STAT *st, float res);

void       destroystat ( STAT *st, int   param);

void       DestroyAllStat (STAT **st, int Num);

void       PrintStatHeader(void);

void       printstat(STAT *st);

void       PrintStatLearn(RL src);

void       PrintTestStat(STAT **st, int len);

void       PrintErrorStat (STAT **st,int Len);

int        DefineNetStructure (char *ptr);

void       getStructure(char buf[20]);

PAT        patcpy (PAT dest, PAT src);

PAT*       LocPatMemory(int num);

void       ReadPattern (PAT *input, char *name,int Len);

void       FreePatMemory(PAT* src, int num);

void       ShowPattern (char *fname, PAT *src, int len);

void       ShowVector(char *fname,PAT src);

float      getPatTarget (float res);

PAT*  DataOrder (PAT* src,int Len, int Ubit, PAT* dest, PAT* test);

void FindMinMax (PAT *src,int Dimens, int Num_elem, float **Out_Array);

void       ConvX_AB_01(PAT src);

int        *DefineCN (int len);

int        getPosition (int Num, int *src, int Len);

void       DestroyCN (int *src);

void       ShowCurN (int LEN);

float      **LocateMemAMM(void);

void       FreeAMM (float **src);

void       WriteHeaderNet(char *fname, float **src);

void       WriteNet (char *fname,int It);

void       ReadHeaderNet(char *fname, float **src);

int        ReadNet (char *fname, int It);

FILE       *OpenFile(char *name);

int        CloseFile(FILE *fp);

/*  End of common file  */

6.    Файл автоматической компиляции программы под Unix -“Makefile”.

CC=    cc

LIBS= -lm

OBJ= nvclass.o

nvclass: $(OBJ)

      $(CC) -o nvclass $(LIBS) $(OBJ)

nvclass.o:  nvclass.c

7.     Основной модуль -  “nvclass.с”

/*

 *  Neuron Classificator ver 1.0

 */

#include "common.h"

/*  =========================

 *     MAIN MODULE

 *  =========================

 */

void main (int argc, char *argv[])

{ int i;

  char buf[MAXLINE], PrName[20], *ptr;

  time_t tim;

  time(&tim);

  /*  UNIX Module  */

  Dfp = OpenFile(DebugFile);

  strcpy(buf,argv[0]);

  ptr = strrchr(buf,'/');

  ptr++;

  strcpy(PrName,ptr);

  Debug ("\n\n'%s' - Started %s",PrName,ctime(&tim));

  getvalues();

  Rfp = OpenFile(ReportFile);

  DefineNetStructure(NetStr);  /* NetStr string from input file */

  getStructure(buf);

  Debug ("\nNeyral net %s",buf);

  Input = LocPatMemory(NPATTERN);

  Work  = LocPatMemory(NPATTERN);

  Array_MinMax = LocateMemAMM();

  Cur_Number   = DefineCN (NPATTERN);

  printf("\nMetka - 1");

  if (Type == TYPE_ONE)

      OnlyTestVector ();

  if (Type == TYPE_TWO)

      TestAfterLearn ();

  if (Type == TYPE_THREE)

      CheckOneVector ();

  if (Type == TYPE_FOUR)

      CrossValidation();

 time(&tim);

 Debug ("\n\n%s - Normal Stoped %s",PrName,ctime(&tim));

 CloseFile(Dfp);

 CloseFile(Rfp);

 FreeAMM (Array_MinMax);

 DestroyCN (Cur_Number);

 FreePatMemory(Input,NPATTERN);

 FreePatMemory(Work, NPATTERN);

}

/*

 * ^OnlyTestVectors - read net from (NetworkFile) and test the TestVector(s)

 */

void OnlyTestVector(void)

{  char buf[MAXLINE+1];

   STAT **st, *stat;

   int i,j;

   float Res;

  Debug ("\nOnlyTestVector proc start");

  Debug ("\n  NPATTERN = %d",NPATTERN);

  Debug ("\n NTEST    = %d",NTEST);

  Test = LocPatMemory(NTEST);

  ReadPattern(Test,TestVector, NTEST);

/*  ShowPattern ("1.tst",Test,NTEST);*/

  PrintStatHeader();

  st = DefineAllStat (Test,NTEST);

  ReadHeaderNet(NetworkFile,Array_MinMax);

  if (Scaling == Yes)

   { for (i=0;i<NTEST;i++)

       ConvX_AB_01(Test[i]);

   }

  for (i=0; i < Loop ; i++)

    { Debug("\n----/ STEP = %d /-----",i+1);

      Report("\n   < Loop %d >     ",i+1);

      ReadNet(NetworkFile,i+1);

      for (j=0;j<NTEST;j++)

       { Res=Forward(Test[j]);

      CheckVector(Res,Test[j]);

      FillSimpleStatForm(st[j],Res);

       }

      PrintTestStat(st,NTEST);

    }

   DestroyAllStat (st,1);

   FreePatMemory(Test,NTEST);

}

/* ---------------------------------

 *   Debug to LOG_FILE and to CONSOLE

 */

/* debug for UNIX */

void Debug (char *fmt, ...)

 { va_list argptr;

   int cnt=0;

 if  ((Dfp != NULL) && (DEBUG == Yes))

   {

     va_start(argptr, fmt);

     vfprintf(Dfp, fmt, argptr);

     fflush (Dfp);

     va_end(argptr);

   }

}

void Report (char *fmt, ...)

 { va_list argptr;

   int cnt=0;

 if  (Rfp != NULL)

   {

     va_start(argptr, fmt);

     vprintf (fmt,argptr);

     vfprintf(Rfp, fmt, argptr);

     fflush (Rfp);

     va_end(argptr);

   }

}

/* debug for DOS */

/*

void Debug (char *fmt, ...)

{  FILE *file;

   va_list argptr;

if  (DEBUG == Yes)

  { if ((file = fopen(DebugFile,"a+"))==NULL)

     { fprintf(stderr, "\nCannot open DEBUG file.\n");

       exit(1);

     }

    va_start(argptr, fmt);

    vfprintf(file, fmt, argptr);

    va_end(argptr);

    fclose (file);

  }

}

void Report (char *fmt, ...)

{  FILE *file;

   va_list argptr;

   if ((file = fopen(ReportFile,"a+"))==NULL)

     { fprintf(stderr, "Cannot open REPORT file.\n");

       exit(1);

     }

    va_start(argptr, fmt);

    vfprintf(file, fmt, argptr);

    vprintf(fmt,argptr);

    va_end(argptr);

    fclose (file);

}

*/

/*

 * ^ReadPattern

 */

void ReadPattern (PAT *input, char *name, int Len)

{ int i=0, j=0, id, TmpNp=0, TmpNd=0, Flag=0;

  char *buf1="NumOfPattern:";

  char *buf2="PatternDimens:";

  char str[40],str1[10];

  PAT   Ptr;

  FILE  *DataFile;

  float tmp;

  Debug ("\nReadPattern(%s,%d) - started",name,Len);

  Ptr.A =(float*) malloc (NDATA * sizeof(float));

  if ((DataFile = fopen(name,"r")) == NULL )

    { Debug("\nCan't read the data file (%s)",name);

      fclose(DataFile);

      exit (1);

    }

  if ((strcmp(name,TestVector)) == 0)  /* if read TestVector, then read */

    Flag = 1;                          /* only ID and A[i]. (NO Target) */

  fscanf(DataFile,"%s %s",str,str1);

  if ((strcmp(str,buf1))==0)

     TmpNp = atoi (str1);

  Debug("\nNumOfPattern = %d",TmpNp);

  fscanf(DataFile,"%s %s",str,str1);

  if ((strcmp(str,buf2))==0)

     TmpNd = atoi (str1);

  Debug("\nPatternDimens = %d",TmpNd);

  if (TmpNp != Len)

    Debug ("\n\tWARNING! - NumOfPattern NOT EQUAL Param (%d != %d)",TmpNp,Len);

  if (TmpNd != NDATA)

    Debug ("\n\tWARNING! - PatternDimens NOT EQUAL NDATA (%d != %d)",TmpNd,NDATA);

  for (i = 0; i < Len; i++)

    {fscanf(DataFile,"%d",&id);

     Ptr.ID = id;

     for (j=0; j < NDATA; j++)

     { fscanf (DataFile,"%f",&tmp);

       Ptr.A[j]=tmp;

     }

     if ( Flag )

       tmp = -1;

     else

       fscanf(DataFile,"%f",&tmp);

     Ptr.Target = tmp;

     input[i]=patcpy(input[i],Ptr);

    }

    fclose(DataFile);

}

/*

 * ^LocPatMemory - locate memory for (PAT *)

 */

PAT* LocPatMemory(int num)

{ int i;

  PAT *src;

  src = (PAT *) malloc (num * sizeof(PAT));

  for (i=0; i< num; i++)

   {src[i].ID = -1;

    src[i].A = (float*) malloc (NDATA * sizeof(float));

    src[i].Target = -1.0;

   }

  return (src);

}

void FreePatMemory( PAT* src, int num )

{ int i;

  for (i=0;i<num;i++)

    free (src[i].A);

  free (src);

}

/*

 *  Copies pattern src to dest.

 *  Return dest.

 */

PAT patcpy (PAT dest, PAT src)

{ int i;

  dest.ID = src.ID;

  for (i=0;i<NDATA;i++)

    dest.A[i] = src.A[i];

  dest.Target = src.Target;

  return dest;

}

…..

/*  Random distribution value

 *  rand() return x from [0,32767] -> x/32768

 *         -> x from [0,1]

 */

float RavnRaspr(float A, float B)

 {float x;

   x = (B-A)*rand()/(RAND_MAX+1.0) + A;

   return x;

 }

float NormRaspr(float A,float B)

 { float mat_ogidanie=A, Sigma=B;

   float Sumx=0.0, x;

   int i;

   for (i=0;i<12;i++)

    Sumx = Sumx + RavnRaspr(0,1);     /* from R[0,1] -> N[a,sigma]*/

   x = Sigma*(Sumx-6) + mat_ogidanie;

  return x;

 }

int Init_W ( void )

{ int i,j;

  float A, B;

  time_t t,t1;

  t = time(NULL);

   t1=t;

  /* restart random generator*/

  while (t==t1)

    srand((unsigned) time(&t));

  if (InitFunc == Random)

   { A = -Constant;

     B =  Constant;

     Debug ("\nInit_W ()  --- Start (%ld))",t);

     Debug ("\n   InitFunc=Random[%4.2f,%4.2f]",A,B);

     for(i=0; i<=NDATA; i++)

      for(j=0; j<NUNIT1; j++)

     W1[i][j]=RavnRaspr(A,B);

     for(j=0; j <= NUNIT1; j++)

       W2[j]=RavnRaspr(A,B);

   }

  if (InitFunc == Gauss)

   { A =  Alfa;

     B =  Sigma;

     Debug ("\nInit_W ()  --- Start (%ld))",t);

     Debug ("\n   InitFunc=Gauss[%4.2f,%4.2f]",A,B);

     for(i=0; i<=NDATA; i++)

      for(j=0; j<NUNIT1; j++)

     W1[i][j] = NormRaspr(A,B);

     for(j=0; j <= NUNIT1; j++)

       W2[j] = NormRaspr(A,B);

   }

 if ( Widrow == Yes )

   Widrow_Init();

 Debug ("\nInit_W - sucsefull ");

 return OK;

}

/*  LearnFunc  */

int LearnFunc (void)

{ int  i, j, n, K, NumErr=0;

  int  num=0;

  float err_cur=0.0, Res=0;

  time_t tim;

  float  ep[NMAXPAT];

  GL_Error=1.0;

  time(&tim);

  Debug ("\nLearnFunc ()  ---  Started");

  Debug ("\n     eta = %4.2f",eta);

  Debug ("\n     LearnTolerance = %4.2f",LearnTolerance);

  Init_PromW();

do

   { num++;

     err_cur = 0.0;

     NumErr = 0;

     for (n = 0; n < NWORK; n++)

       { K = Cur_Number[n];

      Res=Forward(Work[K]);

      ep[n]=fabs(Res-Work[K].Target);

      if (ep[n] > LearnTolerance)

        { NumErr++;

          Init_PromW();

          Update_Last(K, Res);

           Update_Prom1(K);

          Prom_to_W();

        }

      err_cur = err_cur + (ep[n]*ep[n]);

       }

     err_cur=0.5*(err_cur/NWORK);

     result = Reset(err_cur, num, NumErr);

     if ((num % NumOut)==0)

     Debug("\nStep :%d   NumErr :%d   Error:%6.4f",num,NumErr,err_cur);

} while (result == CONT || result == RESTART);

  Debug("\nStep :%d   NumErr :%d   Error:%6.4f",num,NumErr,err_cur);

  return num;

}


Страницы: 1, 2, 3, 4, 5, 6


на тему рефераты
НОВОСТИ на тему рефераты
на тему рефераты
ВХОД на тему рефераты
Логин:
Пароль:
регистрация
забыли пароль?

на тему рефераты    
на тему рефераты
ТЕГИ на тему рефераты

Рефераты бесплатно, реферат бесплатно, курсовые работы, реферат, доклады, рефераты, рефераты скачать, рефераты на тему, сочинения, курсовые, дипломы, научные работы и многое другое.


Copyright © 2012 г.
При использовании материалов - ссылка на сайт обязательна.