⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 art_sim.c

📁 自适应共振神经网络可以实现自动学习与分类具有自适应的功能
💻 C
📖 第 1 页 / 共 2 页
字号:
/* ------------------------------------------------------------------------- */
/*                           The ART Gallery                                 */
/* ------------------------------------------------------------------------- */
/* Art_Sim.c    1.0                                                          */
/*    Written By:  Lars H. Liden         laliden@cns.bu.edu                  */
/*    Last Update: 8/02/95                                                   */
/*                                                                           */
/* Please see Art_Doc.txt for a full documentation.                          */
/*                                                                           */
/* The following code contains a simple example of how the procedures in     */
/* The Art Gallery might be used in a program.  It is not intended to be a   */
/* complete simulation package, but rather a demonstration program.          */
/*                                                                           */
/* Send all bug reports to laliden@cns.bu.edu                                */
/* ------------------------------------------------------------------------- */

#include <stdio.h>

#ifndef __Art_Gal_h
#include "Art_Gal.h"
#endif

/* Gets in integer value from the user */
int GetInt(void) {
  char input[100];
 
  gets(input);
  return atoi(input);
}


/* Gets in float value from the user */
float GetFloat(void) {
   char input[100];
 
  gets(input);
  return atof(input);
}
 

/* Gets in char value from the user */
char GetLetter(void) {
  char input[100];
  
  gets(input);
  return input[0];
}

void DumpNet(netPTR net) {
  float vigil,beta;

  if (GetNetType(net)==ART) {
    printf("\t ART NETWORK:\n");
    if (GetArtType(net,ART)==ART1)
      printf("\t  Art Type:         ART1    \n");
    else
      printf("\t  Art Type:     FUZZYART    \n");

    printf("\t  Inputs:      %9i\n",GetNetInSize(net));
    printf("\t  Nodes:       %9i\n",GetArtSize(net,ART));

    GetArtVigil(net,ART,&vigil);
    printf("\t  Vigilance:       %3.3f\n",vigil);
    GetArtBeta(net,ART,&beta);
    printf("\t  Recoding Rate:   %3.3f\n",beta);

    if (GetArtStyle(net,ART)==COMPLIMENT)
      printf("\t  Compliment Coding:  On \n");
    else
      printf("\t  Compliment Coding: Off \n");
  }
  else {
    GetMapVigil(net,&vigil);
    printf("\t ARTMAP NETWORK:    \t\t Map Vigilance:   %3.3f\n",vigil);
    if (GetArtType(net,ARTA)==ART1)
      printf("\t  ArtA Type:        ART1    ");
    else
      printf("\t  ArtA Type:    FUZZYART    ");

    if (GetArtType(net,ARTB)==ART1)
      printf("\t ArtB Type:        ART1    \n");
    else if (GetArtType(net,ARTB)==FUZZYART)
      printf("\t ArtB Type:    FUZZYART    \n");
    else
      printf("\t ArtB Type:        NONE    \n");

    printf("\t  Inputs:      %9i",GetNetInSize(net));
    printf("\t Outputs:     %9i\n",GetNetOutSize(net));
    printf("\t  Nodes:       %9i",GetArtSize(net,ARTA));
    printf("\t Nodes:       %9i\n",GetArtSize(net,ARTB));
    
    GetArtVigil(net,ARTA,&vigil);
    printf("\t  Vigilance:       %3.3f",vigil);
    if (GetArtType(net,ARTB)!=NONE) {
      GetArtVigil(net,ARTB,&vigil);
      printf("\t Vigilance:       %3.3f\n",vigil);
    }
    else 
      printf("\t Vigilance:         n/a\n");

    GetArtBeta(net,ARTA,&beta);
    printf("\t  Recoding Rate:   %3.3f",beta);
    if (GetArtType(net,ARTB)!=NONE) {
      GetArtBeta(net,ARTB,&beta);
      printf("\t Recoding Rate:   %3.3f\n",beta); 
    }
    else
      printf("\t Recoding Rate:     n/a\n");

    if (GetArtStyle(net,ARTA)==COMPLIMENT)
      printf("\t  Compliment Coding:  On    ");
    else
      printf("\t  Compliment Coding: Off    ");

    if (GetArtType(net,ARTB)!=NONE) {
      if (GetArtStyle(net,ARTB)==COMPLIMENT)
	printf("\t Compliment Coding:  On\n");
      else
	printf("\t Compliment Coding: Off\n");
    }
    else
      printf("\t Compliment Coding: n/a\n");
  }
}


void DumpSet(setPTR set) {
  printf("\t PATTERN SET: \t\t\t Patterns: %12i\n",GetNumPatterns(set));
  if (GetSetInType(set)==BINARY)
    printf("\t  Input Type:     BINARY   ");
  else 
    printf("\t  Input Type:     ANALOG   ");

  if (GetSetOutType(set)==BINARY)
    printf("\t Output Type:    BINARY\n");
  else if (GetSetOutType(set)==ANALOG)
    printf("\t Output Type:    ANALOG\n");
  else
    printf("\t Output Type:      NONE\n");

  printf("\t  Input Size: %10i    ",GetSetInSize(set));
  if (GetSetOutType(set)!=NONE)
    printf("\t Output Size: %9i\n",GetSetOutSize(set));
  else
    printf("\n");
}



/* Load a network from a data file                                          */
int LoadNetwork(netPTR net) {
  char file_name[80];
  int  status;

  printf("\n\tNetwork Name:  ");      
  gets(file_name);
  
  printf("\tLoading Network from %s.net\n",file_name);
  status = LoadNet(net,file_name);

  if (status==1) {
    printf("\n\tFile %s.net not found!\n\n",file_name);
    return 1;
  }
  if (status==2) {
    printf("\n\tError!  Out of memory!\n\n");
    return 1;
  }
  return 0;
}


/* Load a pattern set from a file                                           */
int LoadPatternSet(setPTR set) { 
  char file_name[80];
  int  status;

  printf("\n\tPattern Set Name:  ");      
  gets(file_name);
  
  printf("\tLoading Input/Output Patterns from %s.pat\n",file_name);
  status=LoadSet(set,file_name);

  if (status==1) {
    printf("\n\tFile %s.pat not found!\n\n",file_name);
    return 1;
  }
  if (status==2) {
    printf("\n\tError!  Out of memory!\n");
    return 1;
  }
  return 0;
}


/* Initialize a new network, getting information from the user             */
int InitNetwork(netPTR net) {
  int  nettype;
  int  typeA,typeB;
  int  sizeA,sizeB;
  int  styleA,styleB;    
  int  status;           /* Initialization status */
  char input;

  status = TRUE;

  while (status) {
    printf("\tInitialize Network:\n");
    printf("\tNetwork Types:");
    printf("\n\t\t  %i - Art",ART);
    printf("\n\t\t  %i - ArtMap",ARTMAP);
    printf("\n\t\t  What type:             ");
    nettype = GetInt();

    printf("\n\n\t\tArt Types:");
    printf("\n\t\t  %i - Art1",ART1);
    printf("\n\t\t  %i - FuzzyArt",FUZZYART);
    printf("\n\t\t  What type:             ");
    typeA = GetInt();

    printf("\t\t  Input Size:            ");
    sizeA = GetInt();

    printf("\n\n\t\tInput Styles:");
    printf("\n\t\t  %i - Normal",NONE);
    printf("\n\t\t  %i - Compliment Coded",COMPLIMENT);
    printf("\n\t\t  What Style:            ");
    styleA = GetInt();

    if (nettype==ARTMAP) {
      printf("\n\n\t\tTypeB Types:\n");
      printf("\t\t  %i - Art1\n",ART1);
      printf("\t\t  %i - FuzzyArt\n",FUZZYART);
      printf("\t\t  %i - None\n",NONE);
      printf("\t\t  What type:           ");
      typeB = GetInt();

      printf("\t\t  Output Size:         ");
      sizeB = GetInt();
	
      if (typeB!=NONE) {
	printf("\n\n\t\tOutput Styles:");
	printf("\n\t\t  %i - Normal",NONE);
	printf("\n\t\t  %i - Compliment Coded\n",COMPLIMENT);
	printf("\t\t  What Style:           ");
	styleB = GetInt();
      }
      else
	styleB = NONE;
    }
    printf("\n\tInitializing network.\n\n");
    status=InitNet(net,nettype,typeA,styleA,sizeA,typeB,styleB,sizeB);

    if (status==5) {
      printf("\n\tNetwork already initialized.  Re-initialize (y/n)? ");
      input=GetLetter();
      if (input=='y') {
	FreeNet(net);
	status=InitNet(net,nettype,typeA,styleA,sizeA,typeB,styleB,sizeB);
      }
      else
	return 1;
    }
    if (status==6) {
      printf("\n\tError!  Out of memory!\n");
      return 1;
    }
    else if (status) {
      printf("\tInitialization Error #%i!  Incorrect Format.\n",status);
      printf("\tTry Again (y/n)? ");
      input=GetLetter();
      if (input!='y') 
	return 1;
    }
  }
  return 0;
}


/* Set vigilance levels according to user input                      */
void SetVigil(netPTR net) {
  float vigil;
  char  trash;
  int   type;
  int   status;
  
  type=GetNetType(net);

  if (type==ART) {
    GetArtVigil(net,ART,&vigil);
    printf("\n\t  Art Vigil (%3.3f):      ",vigil);
    vigil = GetFloat();

    status = SetArtVigil(net,ART,vigil);
    if (status) {
      printf("\n\tIncorrect range (%f)!  Must be between 0 and 1.\n",vigil);
      return;
    }
  }
  else if (type==ARTMAP) {
    GetArtVigil(net,ARTA,&vigil);
    printf("\n\tArt-A Vigilance    (%3.3f):       ",vigil);
    vigil = GetFloat();

 
    status = SetArtVigil(net,ARTA,vigil);
    if (status) {
      printf("\n\tIncorrect range (%f)!  Must be between 0 and 1.\n",vigil);
      return;
    }
  
    if (GetArtType(net,ARTB)!=NONE) {
      GetArtVigil(net,ARTB,&vigil);
      printf("\tArt-B Vigilance    (%3.3f):       ",vigil);
      vigil = GetFloat();
     
      status=SetArtVigil(net,ARTB,vigil);
      if (status) {
	printf("\n\tIncorrect range (%f)!  Must be between 0 and 1.\n",vigil);
	return;
      }
    }
    GetMapVigil(net,&vigil);
    printf("\tMapfield Vigilance (%3.3f):       ",vigil);
    vigil = GetFloat();
    
    status = SetMapVigil(net,vigil);
    if (status) {
      printf("\n\tIncorrect range (%f)!  Must be between 0 and 1.\n",vigil);
      return;
    }
  }
  printf("\n");
}


/* Set Recoding Rate according to User Input                         */
void SetBeta(netPTR net) {
  float beta;
  char  trash;
  int   type;
  int   status;
 
  type=GetNetType(net);

  if (type==ART) {
    GetArtBeta(net,ART,&beta);
    printf("\n\n\tArt Beta (%3.3f):             ",beta);
    beta = GetFloat();

    SetArtBeta(net,ART,beta);
    if (status) {
      printf("Incorrect range!  Must be between 0 and 1.\n");
      return;
    }
  }
  else if (type==ARTMAP) {
    GetArtBeta(net,ARTA,&beta);
    printf("\n\n\tArt-A Beta (%3.3f):           ",beta);
    beta = GetFloat();

    status=SetArtBeta(net,ARTA,beta);
    if (status) {
      printf("Incorrect range!  Must be between 0 and 1.\n");
      return;
    }
    GetArtBeta(net,ARTB,&beta);
    printf("\tArt-B Beta (%3.3f):           ",beta);
    beta = GetFloat();

    status=SetArtBeta(net,ARTB,beta);
    if (status==2) {
      printf("Incorrect range!  Must be between 0 and 1.\n");
      return;
    }
    else if (status) {
      printf("Network needs to initialized first!\n");
      return;
    }
  }
}


/* Merge two pattern sets                                            */
void MergePatternSets(void) {
  char set1_name[30];
  char set2_name[30];
  char save_name[30];
  char trash;
  int  status;

  printf("\n\tFirst Pattern Set Name:   ");
  gets(set1_name);

  printf("\tSecond Pattern Set Name:  ");      
  gets(set2_name);

  printf("\tNew Pattern Set Name:     ");      
  gets(save_name);
  
  printf("\tMerging %s.pat & %s.pat into %s.pat.\n\n",
	 set1_name,set2_name,save_name);

  status=MergeSets(set1_name,set2_name,save_name);
  if (status==2)
    printf("\n\tFile %s.pat not found!\n\n",set1_name);
  else if (status==3)
    printf("\n\tFile %s.pat not found!\n\n",set2_name);
  else if (status==4)
    printf("\n\tError!  Out of memory!\n");
  else if (status)
    printf("\n\tError Merging.  Incompatible Sets.\n\n");
}


/* Make pattern set                                                        */
int MakePatternSet(setPTR set) {
  char file1_name[80];
  char file2_name[80];
  int  type_inputs;
  int  type_outputs;
  int  num_inputs;
  int  num_outputs;
  int  status;
  
  printf("\n\tInput Types:\n");
  printf("\t  %i - Binary\n",BINARY);
  printf("\t  %i - Analog\n",ANALOG);
  printf("\t  What type:              ");
  type_inputs = GetInt();
  
  printf("\t  Input Size:             ");
  num_inputs = GetInt();
  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -