Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!hp4nl!fwi.uva.nl!smagt From: smagt@fwi.uva.nl (Patrick van der Smagt) Newsgroups: comp.ai.neural-nets Subject: ART1&2 source code (WAS: Detailed description of ART-1 & 2 wanted) Keywords: ART NN Message-ID: <1991Feb27.153904.10455@fwi.uva.nl> Date: 27 Feb 91 15:39:04 GMT References: <132@blakex.RAIDERNET.COM> Sender: news@fwi.uva.nl Distribution: comp Organization: FWI, University of Amsterdam Lines: 998 Nntp-Posting-Host: wendy.fwi.uva.nl root@blakex.RAIDERNET.COM (Blake McBride) writes: >Am looking for a source for a detailed description of Adaptive Resonance >Theory (ART) by Grossberg & Carpenter. Both 1 & 2. In addition, if >anyone has any source it sure would be appreciated! Well, I do have a description of ART-1, whereas one of my students tried to disentangle ART itself. But one had better read Lippmann and reconstruct ART-1 from that. Anyway, here is some source code for ART-1 and ART-2; I wrote neither but looked at both. I also have another ART-2 source code, but I will not clobber the net by including that one, too. Patrick van der Smagt /\/\ \ / Organisation: Faculty of Mathematics & Computer Science / \ University of Amsterdam, Kruislaan 403, _ \/\/ _ NL-1098 SJ Amsterdam, The Netherlands | | | | Phone: +31 20 525 7524 | | /\/\ | | Fax: +31 20 525 7490 | | \ / | | | | / \ | | email: smagt@fwi.uva.nl | | \/\/ | | | \______/ | \________/ /\/\ ``The opinions expressed herein are the author's only and do \ / not necessarily reflect those of the University of Amsterdam.'' / \ \/\/ ---------art1.c-------------cut here-----------------art1.c----------------- /* Simiulation of ART-1 Neural network (Ref: Lippman 87) Written by Jagath Samarabandu To compile, type cc art1.c -o art1 */ #include #define N 25 /* No. of nodes in F1 */ #define M 20 /* No. of nodes in F2 */ initialize(top_down,bot_up,n,m) /* initialize the LTM traces */ double top_down[],bot_up[]; /* top down and bot. up LTM traces */ int n,m; /* No. of nodes in F1 and F2 */ { int i; double t; t = 1.0/(1.0+n); for (i=0;iarray[jmax]) jmax = j; return (jmax); } adapt_LTM(top_down,bot_up, input,jmax,n,m) /* change top down and bot.up LTM */ double top_down[],bot_up[],input[]; int n,m,jmax; { int i,ij; double sum,t; for (i=0,sum=0.5; imax) { printf("Warning! only %2d patterns out of %d are read\n",max,n_pat); n_pat = max; } if (n_var!=n) exit(printf("wrong pattern size: should be %2d. was %2d\n",n,n_var)); for (i=0;j0.5)?'#':' '); printf(" | "); for (j=0; j0.5)?'#':' '); printf(" "); } printf("\n"); } printf("\n"); } /***************** main routine starts here *******************************/ int data[20][N]={ #include "art1.data" }; main(argc,argv) int argc; char *argv[]; { char ch; double t[N][M],b[N][M],x[N],mu[M],rho; int max_j,i,j,n_pat,ok,seq[M]; if (argc>1) n_pat = load_data(data,20,N,argv[1]); else n_pat=20; initialize(t,b,N,M); printf("Vigilance threshold: "); scanf("%lf",&rho); printf("\nSimulation of ART1 network with vigilance Threshold = %3.3lf\n\n",rho); do { for (i=0; irho) { adapt_LTM(t,b,x,max_j,N,M); seq[max_j] = -1; break; } else mu[max_j] = 0.0; } while (1); printf("IN:%2d ",i); for (j=0;j0) printf("%1d ",seq[j]); else if (seq[j]==0) printf(" "); else { printf("R\n"); break; } } display(x,t,5,5,M); } printf("Another round? (1-yes): "); scanf("%d",&ok); } while (ok); ok =1; do { printf("\n[A-T] or ESC to quit :"); scanf("%s",&ch); printf("\n"); if ((ch == 27) || ((ch < 'A') || (ch > 'T'))) ok =0; else { for (j=0; jrho) { adapt_LTM(t,b,x,max_j,N,M); seq[max_j] = -1; break; } else mu[max_j] = 0.0; } while (1); printf("IN:%2d ",i++); for (j=0;j0) printf("%1d ",seq[j]); else if (seq[j]==0) printf(" "); else { printf("R\n"); break; } } display(x,t,5,5,M); } } while (ok); } ----------------------end-------------end------------------------------------ ------art1 data file--------cut here-------------art1 data file-------------- /* art1 data file - 20x25 */ {1,1,1,1,1, 1,0,0,0,1, 1,1,1,1,1, 1,0,0,0,1, 1,0,0,0,1,}, {1,1,1,1,0, 1,0,0,0,1, 1,1,1,1,0, 1,0,0,0,1,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0, 0,0,1,0,0,}, --------------------end------------------end--------------------------------- ------------art2.c-----------cut here-----------------art2.c----------------- #include #include #include /* dans addition */ #define M 10 #define N 8 #define STREQ(s1,s2) (strcmp((s1),(s2)) == 0) /*****************************************************************/ /** art2 algorithm **/ /** simulates the art2 algorithm for clustering vectors **/ /** Steve Lehar Sept 89 **/ /*****************************************************************/ /**** global variables & functions ****/ int reset; float w[M],p[M],oldp[M],x[M],q[M],v[M],u[M],r[M],topdown[M]; float w1[M],p1[M],x1[M],q1[M],v1[M],u1[M]; float rho,normp,normu,normv,normw,normr; float normq1,normp1,normu1,normv1,normw1,normr1; float zup[M][N],zdn[N][M],oldzdn[M]; float I[M], F1[M], F2[N],F2val[N]; int F2winner,F2reset[N]; float pchange=1.0,zchange=1.0,diff(); float a=5.0, b=5.0, c=0.225, e=0.000001, theta = 0.3,del_t = 0.1; char pattern[80]; FILE *fp; int iter,learning,nreset=0; float f(),floatval(); main(argc,argv) int argc; char *argv[]; { int i,j,k; char key; /**** initialize ****/ init_weights(); get_commandline_args(argc,argv); /**** learn training patterns ****/ for(i=0;i<10;i++){ fscanf(fp,"%s ",pattern); learning = 1; /**** if(STREQ(pattern,"E") || STREQ(pattern,"F")) learning = 0; else learning = 1; ****/ read_input(); init_reset(); print_input(); restart:; init_nodes(); /**** equilibrate f0 ****/ for(iter=0;iter<10;iter++){ update_f0(); } /**** equilibrate f1 ****/ for(iter=0;iter<10;iter++){ update_f1(); } /**** equilibrate f1 & f2 ****/ for(iter=0;iter<10;iter++){ update_f1(); update_f2(); update_r(); } /**** check for reset ****/ if(reset){ printf("RESET\n"); reset = 0; nreset++; if(nreset==N)goto nextpattern; if(learning) goto restart; } if(!learning) goto skip; /**** learn resonant pattern ****/ for(k=0;k<1000;k++){ update_zup(); update_zdn(); update_f1(); } skip:; print_vals(); if(is_arg("-v",argc,argv)) print_f0(); print_f1(); print_f2(); print_z(F2winner); } printf("\n"); nextpattern:; fclose(fp); } /**** zchange = diff(zdn[F2winner],oldzdn,N); pchange = diff(p,oldp,M); print_f2(); print_all(); ****/ /*****************************************************************/ /** function f() **/ /** returns 0 if x max && !F2reset[j]){ max = F2[j]; F2winner = j; } F2[j] = 0.0; } F2[F2winner] = 0.8; } /*****************************************************************/ /** update_r **/ /*****************************************************************/ update_r() { int i,j; float cnormp; /**** compute cnormp ****/ cnormp = 0.0; for(i=0;i 1.0) reset = 1; else reset = 0; if(reset){ F2reset[F2winner] = 1.0; } } /*****************************************************************/ /** update_zup **/ /*****************************************************************/ update_zup() { int i,j; for(i=0;i 0) { result = (strcmp(str,arg_v[--arg_c]) == 0) ? 1 : 0; } return(result); } float floatval(str,arg_c,arg_v) char str[],*arg_v[]; int arg_c; { float result; result = 0.0; while (arg_c > 0) { if (strcmp(str,arg_v[--arg_c]) == 0) break; } if (arg_c > 0) { if (sscanf(arg_v[arg_c+1],"%lf",result) < 1) printf("\n\7ERR: syntax error - expecting a float, got %s\n", arg_v[arg_c+1]); } return(result); } char strval(str,arg_c,arg_v) char str[],*arg_v[]; int arg_c; { char result[128]; int ll; for (ll = 0; ll < 128; result[ll++] = 'A'); /* clear out result str */ result[127] = '\n'; /* null terminate */ while (arg_c > 0) { if (strcmp(str,arg_v[--arg_c]) == 0) break; } if (arg_c > 0) { if (sscanf(arg_v[arg_c+1],"%s",result) < 1) printf("\n\7ERR: syntax error - expecting a string, got nothing \n"); } return(result); }