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

📄 initnet.c

📁 各种神经网络C源代码。包括: CPN、BPN、ART1、ART2
💻 C
字号:
/**************************************************************************
 **************************************************************************
 ***									***
 ***				INITNET.C				***
 ***									***
 *** Notice:                                                            ***
 ***    This code is copyright (C) 1995 by David M. Skapura.  It may    ***
 ***    be used as is, or modified to suit the requirements of a  	***
 ***    specific application without permission of the author.		***
 ***    There are no royalty fees for use of this code, as long         ***
 ***    as the original author is credited as part of the final		***
 ***    work.  In exchange for this royalty free use, the user    	***
 ***    agrees that no guarantee or warantee is given or implied.	***
 ***									***
 ***									***
 **************************************************************************
 **************************************************************************/


#include <stdlib.h>


void set_random_weights (layer *layer)
 {
  float **connects, *wts;
  int i, j, incnt, tocnt;

  connects = layer->connects;
  if (!connects) return;

  incnt = layer->inputs;
  tocnt = layer->units;

  for (i=0; i<tocnt; i++)
   {
    wts = connects[i];
    for (j=0; j<incnt; j++)
     wts[j] = ((float)rand() / 32767.0) - 0.5;
   }
 }


void set_test_weights (layer *layer)
 {
  float **connects, *wts;
  int i, j, incnt, tocnt;

  connects = layer->connects;
  if (!connects) return;

  incnt = layer->inputs;
  tocnt = layer->units;

  for (i=0; i<tocnt; i++)
   {
    wts = connects[i];
    for (j=0; j<incnt; j++)
     wts[j] = (float)i + ((float)j / 1000.0);
   }
 }


void set_normal_weights (layer *layer)
 {
  float **connects, *wts, wtval;
  int i, j, incnt, tocnt;

  connects = layer->connects;
  if (!connects) return;

  incnt = layer->inputs;
  tocnt = layer->units;
  wtval = 1 / sqrt (incnt);

  for (i=0; i<tocnt; i++)
   {
    wts = connects[i];
    for (j=0; j<incnt; j++)
     wts[j] = wtval;
   }
 }



void set_value_weights (layer *layer)
 {
  float **connects, *wts, wtval;
  int i, j, incnt, tocnt;

  connects = layer->connects;
  if (!connects) return;

  incnt = layer->inputs;
  tocnt = layer->units;
  wtval = layer->initval;

  for (i=0; i<tocnt; i++)
   {
    wts = connects[i];
    for (j=0; j<incnt; j++)
     wts[j] = wtval;
   }
 }



void set_weights (layer *l, int how)
 {
  if (how == RANDOM) set_random_weights (l);
  if (how == TEST)   set_test_weights (l);
  if (how == NORMAL) set_normal_weights (l);
  if (how == VALUE)  set_value_weights (l);
}

⌨️ 快捷键说明

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