?? initnet.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);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -