📄 art_int.c
字号:
}
/**< Check if set data needs to be compliment coded */
if (Compliment(set, net->art.style, ART_STYLE_NONE))
{
return 7;
}
}
if (net->type == ARTMAP)
{
if ((net->map.artA.type == ART_TYPE_ART1)&&(set->type_inputs == NODE_ANALOG))
{
return 3;
}
if ((net->map.artB.type == ART_TYPE_ART1)&&(set->type_outputs == NODE_ANALOG))
{
return 3;
}
if (set->type_outputs == NODE_NONE)
{
return 6;
}
/**< Check input size */
if ((net->map.artA.style == ART_STYLE_NONE)&&(net->num_inputs != set->num_inputs))
{
return 4;
}
if ((net->map.artA.style == ART_STYLE_COMPLIMENT)&&(net->num_inputs != 2 * (set->num_inputs)))
{
return 4;
}
/**< Check output size */
if ((net->map.artB.style == ART_STYLE_NONE)&&(net->num_outputs != set->num_outputs))
{
return 5;
}
if ((net->map.artB.style == ART_STYLE_COMPLIMENT)&&(net->num_outputs != 2 * (set->num_outputs)))
{
return 5;
}
if ((net->map.artB.type == ART_TYPE_NONE)&&(net->num_outputs != set->num_outputs))
{
return 5;
}
/**< Check if set data needs to be compliment coded */
if (Compliment(set, net->map.artA.style, net->map.artB.style))
{
return 7;
}
}
/**< Everything looks ok, so mark as checked */
net->checkB = TRUE;
set->checkB = TRUE;
/**< Training not done since either pattern set or network changed */
net->doneB = FALSE;
return 0;
}
/**
* \fn int InitArt(artPTR art, int type, int style, int num_inputs)
* \brief Initializes art network values and allocate space
* \param art the ART network
* \param type network type
* \param style network style
* \param num_inputs network input nodes number
* \retval 0 Successfule
* \retval 1 Out of memory
*/
int InitArt(artPTR art, int type, int style, int num_inputs)
{
int i, j;
art->type = type;
art->num_inputs = num_inputs;
if (type == ART_TYPE_NONE)
{
art->nodes_used = num_inputs; /**< Inputs just copied so number of */
art->max_nodes = num_inputs; /**< categories is a constant. */
art->cat = (float *)malloc((size_t)(art->max_nodes * sizeof(float)));
if (art->cat == NULL)
{
return 1;
}
art->style = ART_STYLE_NONE;
}
else
{
art->style = style;
art->nodes_used = 0; /**< All categories are currently unused */
art->max_nodes = MAX; /**< Starting number of available categories */
art->beta = 1; /**< No recoding */
art->vigil = 0;
art->num_reset = 0;
art->cat = (float *)malloc((size_t)(art->max_nodes * sizeof(float)));
if (art->cat == NULL)
{
return 1;
}
art->elig = (float *)malloc((size_t)(art->max_nodes * sizeof(float)));
if (art->elig == NULL)
{
free(art->cat);
art->cat = NULL;
return 1;
}
art->commit = (int *)malloc((size_t)(art->max_nodes * sizeof(int)));
if (art->commit == NULL)
{
free(art->cat);
art->cat = NULL;
free(art->elig);
art->elig = NULL;
return 1;
}
art->weight = (float **)malloc((size_t)(art->max_nodes * sizeof(float *)));
if (art->weight==NULL)
{
free(art->cat);
art->cat = NULL;
free(art->elig);
art->elig = NULL;
free(art->commit);
art->commit = NULL;
return 1;
}
art->weight[0] = (float *)malloc((size_t)((art->max_nodes * art->num_inputs) * sizeof(float)));
if (art->weight[0] == NULL)
{
free(art->cat);
art->cat = NULL;
free(art->elig);
art->elig = NULL;
free(art->commit);
art->commit = NULL;
free(art->weight);
art->weight = NULL;
return 1;
}
for(i = 1; i < art->max_nodes; i++)
{
art->weight[i] = art->weight[i - 1] + art->num_inputs;
}
art->sum_weights = (float *)malloc((size_t)(art->max_nodes * sizeof(float)));
if (art->sum_weights == NULL)
{
free(art->cat);
art->cat = NULL;
free(art->elig);
art->elig = NULL;
free(art->commit);
art->commit = NULL;
free(art->weight);
art->weight = NULL;
free(art->weight[0]);
art->weight[0] = NULL;
return 1;
}
art->sum_IW = (float *)malloc((size_t)(art->max_nodes * sizeof(float)));
if (art->sum_IW == NULL)
{
free(art->cat);
art->cat = NULL;
free(art->elig);
art->elig = NULL;
free(art->commit);
art->commit = NULL;
free(art->weight);
art->weight = NULL;
free(art->weight[0]);
art->weight[0] = NULL;
free(art->sum_weights);
art->sum_weights = NULL;
return 1;
}
/**< Set Initial Weight Values */
for (i = 0; i < art->max_nodes; i++)
{
for (j = 0; j < art->num_inputs; j++)
{
*(*(art->weight + i) + j) = 1;
}
}
/**< Calculate initial weight sums */
for (i = 0; i < art->max_nodes; i++)
{
*(art->sum_weights + i) = 0;
for (j = 0; j < art->num_inputs; j++)
{
*(art->sum_weights + i) += (*(*(art->weight + i) + j));
}
}
/**< Set Initial Commitments to false */
for (i = 0; i < art->max_nodes; i++)
{
*(art->commit + i) = FALSE;
}
}
return 0;
}
/**
* \fn int InitMap(mapPTR map, int typeA, int styleA, int typeB, int styleB,
int num_inputs, int num_outputs)
* \brief Initialize mapfield values and allocate space
* \param map the map struct
* \param typeA ARTA type
* \param styleA ARTA style
* \param typeB ARTB type
* \param styleB ARTB style
* \param num_inputs input nodes number
* \param num_outputs output nodes number
* \retval 0 Successfule
* \retval 1 Out of memory
*/
int InitMap(mapPTR map, int typeA, int styleA, int typeB, int styleB,
int num_inputs, int num_outputs)
{
int i,j;
map->vigil = 1; /**< Require perfect mapfield match */
map->base_vigil = 0;
map->num_mismatch = 0;
/**< Initialize Art Networks */
if (InitArt(&map->artA, typeA, styleA, num_inputs))
{
return 1;
}
if (InitArt(&map->artB, typeB, styleB, num_outputs))
{
return 1;
}
map->maxA_nodes = map->artA.max_nodes;
map->maxB_nodes = map->artB.max_nodes;
/**< Allocate space for map and weights */
map->map = (float *)malloc((size_t)(map->artB.max_nodes * sizeof(float)));
if (map->map == NULL)
{
return 1;
}
map->map_weight = (float **)malloc((size_t)(map->artA.max_nodes * sizeof(float *)));
if (map->map_weight == NULL)
{
free(map->map);
map->map = NULL;
return 1;
}
map->map_weight[0] = (float *)malloc((size_t)((map->artA.max_nodes * map->artB.max_nodes) * sizeof(float)));
if (map->map_weight[0] == NULL)
{
free(map->map);
map->map = NULL;
free(map->map_weight);
map->map_weight = NULL;
return 1;
}
for(i = 1; i < map->artA.max_nodes; i++)
{
map->map_weight[i] = map->map_weight[i - 1] + map->artB.max_nodes;
}
/**< Set Initial Map Field Weight Values */
for (i = 0; i < map->artA.max_nodes; i++)
{
for (j = 0; j < map->artB.max_nodes; j++)
{
*(*(map->map_weight + i) + j) = 1;
}
}
return 0;
}
/**
* \fn int LoadArt(artPTR art, FILE *LoadFile)
* \brief Load ART net from file
* Given a pointer to a file, loads art network data, setting
* appropriate initial values.
* \param art the ART network structure
* \param LoadFile the file contains the old data.
* \retval 0 Successful
* \retval 1 Out of memory
*/
int LoadArt(artPTR art, FILE *LoadFile)
{
float temp_flt;
int i,j;
fscanf(LoadFile, "%i\n", &art->type);
fscanf(LoadFile, "%i\n", &art->num_inputs);
fscanf(LoadFile, "%i\n", &art->nodes_used);
art->max_nodes = art->nodes_used; /**< No unused nodes were saved */
art->cat = (float *)malloc((size_t)(art->max_nodes * sizeof(float)));
if (art->cat == NULL)
{
return 1;
}
if (art->type != ART_TYPE_NONE)
{
fscanf(LoadFile, "%i\n", &art->style);
fscanf(LoadFile, "%f\n", &art->beta);
fscanf(LoadFile, "%f\n", &art->vigil);
art->num_reset = 0; /**< Number Reset is zero */
art->elig = (float *)malloc((size_t)(art->max_nodes * sizeof(float)));
if (art->elig == NULL)
{
free(art->cat);
art->cat = NULL;
return 1;
}
art->commit = (int *)malloc((size_t)(art->max_nodes * sizeof(int)));
if (art->commit == NULL)
{
free(art->cat);
art->cat = NULL;
free(art->elig);
art->elig = NULL;
return 1;
}
art->weight = (float **)malloc((size_t)(art->max_nodes * sizeof(float*)));
if (art->weight == NULL)
{
free(art->cat);
art->cat = NULL;
free(art->elig);
art->elig = NULL;
free(art->commit);
art->commit = NULL;
return 1;
}
art->weight[0] = (float *)malloc((size_t)((art->max_nodes * art->num_inputs) * sizeof(float)));
if (art->weight[0] == NULL)
{
free(art->cat);
art->cat = NULL;
free(art->elig);
art->elig = NULL;
free(art->commit);
art->commit = NULL;
free(art->weight);
art->weight = NULL;
return 1;
}
for(i = 1; i < art->max_nodes; i++)
{
art->weight[i] = art->weight[i-1] + art->num_inputs;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -