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

📄 art_ext.c

📁 自适应共振神经网络可以实现自动学习与分类具有自适应的功能
💻 C
📖 第 1 页 / 共 5 页
字号:
/*           2 - When file1 not found                                        */
/*           3 - When file2 not found                                        */
/*           4 - Memory Allocation Failure (out of memory)                   */
/* ------------------------------------------------------------------------- */
int   MergeSets (char *file1_prefix, char *file2_prefix, char *save_prefix) 
{
    setTYPE set1;            
    setTYPE set2;
    char    in_fname[84];    /* A charcter string to be used as a filename   */
    int     i;               /* Counter                                      */
    int     status;

    /* Add ".pat" to end of the file prefix                                  */
    strncpy(in_fname,file1_prefix,80);
    strcat(in_fname,".pat");

    /* Load sets                                                             */
    status=LoadSet(&set1,file1_prefix);
    if (status==1) return 2;
    if (status==2) return 4;
    status=LoadSet(&set2,file2_prefix);
    if (status==1) return 3;
    if (status==2) return 4;

    /* Check compatibility of the two sets                                   */
    if (set1.num_inputs  != set2.num_inputs)   return 1;
    if (set1.num_outputs != set2.num_outputs)  return 1;
    if (set1.type_inputs != set2.type_inputs)  return 1;
    if (set1.type_outputs!= set2.type_outputs) return 1;

    /* -------- If everything in order, then merge the sets ---------------- */
    for (i=0;i<set2.num_patterns;i++) 
    {
        status=AddPattern(&set1, set2.num_inputs, set2.pattern[i].input,
            set2.num_outputs, set2.pattern[i].output);
        if (status==4)
            return status;
    }
    SaveSet(&set1,save_prefix);
    return 0;
}

/**
 * \fn int   GetNumPatterns(setPTR set) 
 * \brief Given a pointer to a pattern set, returns the number of patterns in the set.
 * \param set A pointer to a set of patterns of type setTYPE
 * \retval -1 When the set is not initialized or NULL
 * \retval other The number of patterns in the set
 */
int   GetNumPatterns(setPTR set) 
{
    if ((set == NULL)||(set->initB != TRUE))
        return -1;
    else
        return set->num_patterns;
}

/* ------------------------------------------------------------------------- */
/* MakeSet                                                                   */
/*     Given an uninitialized set pointer, the name of two files containing  */
/*     data and the size and type of input and output patterns, creates a    */
/*     pattern set from the data files.  Each data file must have one number */
/*     per line with no blank lines between patterns.                        */
/*                                                                           */
/* Arguments:                                                                */
/*     set          - A pointer to a set of patterns of type setTYPE         */
/*     infile_name  - A pointer to a file of input values                    */
/*     num_inputs   - The number of inputs per pattern                       */
/*     type_inputs  - The type of inputs (NODE_ANALOG or NODE_BINARY)                  */
/*     outfile_name - A pointer to a file of output values                   */
/*     num_outputs  - The number of outputs per pattern                      */
/*     type_outputs - The type of outputs (NODE_ANALOG or NODE_BINARY)                 */
/*                                                                           */
/* Return errs:                                                              */
/*           0 - When successful                                             */
/*           1 - Invalid Set Types                                           */
/*           2 - Output type NODE_NONE with non-zero number of outputs            */
/*           3 - Memory Allocation Failure (out of memory)                   */
/*           4 - Set is NULL                                                 */
/*           5 - Input file not found                                        */
/*           6 - Output file not found                                       */
/*           7 - NODE_ANALOG data given for NODE_BINARY set type                       */
/*           8 - NODE_ANALOG patter data not properly bounded [0 1]               */
/*           9 - Input or Output Vector has all zero values, or zero size    */
/*          10 - WARNING: Input or Output file ended prematurely             */
/* ------------------------------------------------------------------------- */
int  MakeSet (setPTR set,char *infile_name, int num_inputs, 
              int type_inputs, char *outfile_name, 
              int num_outputs, int type_outputs) 
{

    FILE    *infile;         /* A pointer to a file                          */
    FILE    *outfile;
    float   *input;
    float   *output;
    float   tempflt;
    int     i;               /* Counter                                     */
    int     status;
    int     done;
    int     out_of_data;


    if (num_inputs<=0) return 9;
    if (type_outputs != NODE_NONE)
        if (num_outputs<=0) return 9;

    /* Initialize Pattern Set Checking For Errors                           */
    status = InitSet(set, num_inputs, type_inputs, num_outputs,type_outputs);
    if (status)
        return status;


    /* Allocate space for input and output strings                          */
    input=(float *)malloc((size_t) (num_inputs*sizeof(float)));
    if (input==NULL) return 3;

    if (type_outputs != NODE_NONE) 
    {
        output=(float *)malloc((size_t) (num_outputs*sizeof(float)));
        if (output==NULL) return 3;
        outfile=fopen(outfile_name, "r");
        if (outfile==NULL) return 6;
    }  

    infile=fopen(infile_name,"r");
    if (infile==NULL) return 5;

    done = FALSE;
    out_of_data = FALSE;
    while (!done) 
    {
        /* Read in input data                                            */
        status=fscanf(infile,"%f",&tempflt);
        *(input+0)=tempflt;
        if (status==EOF)
            done = TRUE;
        else 
        {
            for (i=1;i<num_inputs;i++)
                if (!out_of_data) 
                {
                    status=fscanf(infile,"%f\n",&tempflt);
                    *(input+i)=tempflt;
                }
                if (status==EOF) out_of_data = TRUE;
                if (type_outputs != NODE_NONE)
                    for (i=0;i<num_outputs;i++)
                        if (!out_of_data)
                        {
                            status=fscanf(outfile,"%f\n",&tempflt);
                            *(output+i)=tempflt;
                        }
                        if (status==EOF) out_of_data = TRUE;
        }
        if (out_of_data)
            done = TRUE;
        else if (!done) 
        {
            status=AddPattern(set, num_inputs, input, num_outputs, output);
            if (status==2) return 7;
            if (status==3) return 8;
            if (status==4) return 9;
            if (status==5) return 3;
        }
    }
    if (GetNumPatterns(set)==0) return 9; /* Not enough data for one pattern! */
    if (out_of_data) return 10;           /* Uneven number of pattern data    */
    return 0;
}


/* ------------------------------------------------------------------------- */
/* SetArtVigil                                                               */
/*              Given a pointer to a network, a network component and a      */
/*              vigilence sets the compenents vigilence level.               */
/*                                                                           */
/* Arguments:                                                                */
/*          net       - A pointer to an initialized netowrk of type netTYPE  */
/*          component - ARTA, ARTB, or ART                                   */
/*          vigil     - new vigilence value between [0 1]                    */
/*                                                                           */
/* Return Values:                                                            */
/*           0 - When successful                                             */
/*           1 - When network type is incompatible                           */
/*           2 - When vigilence is in incorrect range                        */
/*           3 - When network not initialized or NULL                        */
/* ------------------------------------------------------------------------- */
int   SetArtVigil(netPTR net, int component, float vigil)
{

    /* Check range */
    if ((vigil>1)||(vigil<0))
        return 2;

    /* Check initialization */
    if ((net==NULL)||(net->initB!=TRUE))
        return 3;

    /* Check network type and set */
    if (component==ARTA) 
    {
        if (net->type!=ARTMAP)
            return 1;
        net->map.artA.vigil=vigil;
        net->map.base_vigil=vigil;
    }
    else if (component==ARTB)
    {
        if ((net->type!=ARTMAP)||(net->map.artB.type==ART_TYPE_NONE))
            return 1;
        net->map.artB.vigil=vigil;
    }
    else if (component==ART) 
    {
        if (net->type!=ART)
            return 1;
        net->art.vigil=vigil;
    }
    else
        return 1;

    /* New Vigil So Training No Longer Up To Date */
    net->doneB = FALSE; 
    return 0;

}



/* ------------------------------------------------------------------------- */
/* SetMapVigil                                                               */
/*              Given a pointer to an ArtMap network, sets the mapfield      */
/*              vigilence level.                                             */
/*                                                                           */
/* Arguments:                                                                */
/*          net        - A pointer to an initialized network of type netTYPE */
/*          vigil      - New vigilence value between [0 1]                   */
/*                                                                           */
/* Return Values:                                                            */
/*           0 - When successful                                             */
/*           1 - When network type is incompatible                           */
/*           2 - When vigilence is in incorrect range                        */
/*           3 - When network not initialized or NULL                        */
/* ------------------------------------------------------------------------- */
int   SetMapVigil(netPTR net, float map_vigil)
{

    /* Check range */
    if ((map_vigil>1)||(map_vigil<0))
        return 2;

    /* Check initialization */
    if ((net==NULL)||(net->initB!=TRUE))
        return 3;

    /* Check network type and set */
    if (net->type!=ARTMAP)
        return 1;

    net->map.vigil=map_vigil;

    /* New Vigil So Training No Longer Up To Date */
    net->doneB = FALSE;
    return 0;
}


/* ------------------------------------------------------------------------- */
/* GetMapVigil                                                               */
/*              Given a pointer to an ArtMap network, and a pointer to a     */
/*              float, sets the pointer to the vigilence level of the        */
/*              mapfield.                                                    */
/*                                                                           */
/* Arguments:                                                                */
/*          net        - A pointer to an initialized network of type netTYPE */
/*          vigil      - A pointer to a float                                */
/*                                                                           */
/* Return Values:                                                            */
/*           0         - When successful                                     */
/*           1         - When network NULL or not initialized                */
/*           2         - When netowrk not of type ARTMAP                     */
/* ------------------------------------------------------------------------- */
int   GetMapVigil(netPTR net, float *vigil)
{

    if ((net==NULL)||(net->initB!=TRUE))
        return 1;

    /* Check network type and set */
    if (net->type!=ARTMAP)
        return 2;
    *vigil = net->map.vigil;
    return 0;
}


/* ------------------------------------------------------------------------- */
/* SetArtBeta                                                                */
/*              Given a pointer to a network, a network component and a      */
/*              recoding rate sets the compenents recoding rate.             */
/*                                                                           */
/* Arguments:                                                                */
/*          net       - A pointer to an initialized netowrk of type netTYPE  */
/*          component - ARTA, ARTB, or ART                                   */
/*          beta      - new recoding rate value between [0 1]                */
/*                                                                           */
/* Return Values:                                                            */
/*           0 - When successful                                             */
/*           1 - When network type is incompatible                           */
/*           2 - When vigilence is in incorrect range                        */
/*           3 - When network not initialized or NULL                        */
/* ------------------------------------------------------------------------- */
int   SetArtBeta(netPTR net, int component, float beta)
{

    /* Check range */
    if ((beta>1)||(beta<0))
        return 2;

    /* Check initialization */
    if ((net==NULL)||(net->initB!=TRUE))
        return 3;

    /* Check network type and set */
    if (component==ARTA) 
    {
        if (net->type!=ARTMAP)
            return 1;

⌨️ 快捷键说明

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