📄 nervecell.h
字号:
/*
filename: NerveCell.h
function: the basic Nerve Cell
a layer
@copyright
date : 2008-12-21
author : loop111
e-mail : loop111@gmail.com
*/
#ifndef NERVECELL_H
#define NERVECELL_H
#ifndef NULL
#define NULL 0
#endif
#include <vector>
using namespace std;
//#include <string>
//namespace NeuralNet
//{
typedef double Vtype;
class Layer;
class NerveCell
{
public:
Vtype value; //output value
//Vtype svalue;
double delta; //error
bool hidden;
int name;
vector<NerveCell*>input;
vector<double> weight;
NerveCell(bool hidden = false):update(false),n(0),hidden(hidden)//,thresh(value_thresh)
{
count++;
name = count;
}
~NerveCell()
{
}
void Initial(Layer* layer);
void Connect(NerveCell* cell)
{
input.push_back(cell);
weight.push_back(0);
lastweight.push_back(0);
n++;
}
void SetWeight(int i,double value)
{
if (weight[i]<1e-5 && weight[i]>-1e-5)//weight[i] = 0
{
lastweight[i] = value;
}
else
{
lastweight[i] = weight[i];
}
weight[i] = value;
update = false;
}
double GetWeight(int i)
{
return weight[i];
}
double GetLastWeight(int i)
{
return lastweight[i];
}
void UpdateOutput()
{
CalcValue();
}
Vtype GetValue()
{
if(update)
{
return value;
}
else
{
value = CalcValue();
return value;
}
}
private:
bool update;
int n;
static int count; //record the num
vector<double> lastweight;
Vtype CalcValue();
};
class NerveCellList
{
public:
bool hidden;
NerveCellList(bool hidden = false):hidden(hidden)
{
head = new NerveCell(hidden);
}
~NerveCellList()
{
delete head;
}
NerveCell* head;
NerveCell* next;
NerveCell* left;
NerveCell* right;
NerveCell* up;
NerveCell* down;
};
class Layer//a NerveCell list
{
public:
//NerveCellList layer;
vector<NerveCellList*> celllist;
bool hidden;
int num;
Layer(int n,bool hidden = false):num(n),hidden(hidden)
{
for (int i=0;i<n-1;i++)
{
NerveCellList *cell = new NerveCellList();
celllist.push_back(cell);
}
NerveCellList *cell = new NerveCellList(hidden);//whether the last node is hidden
celllist.push_back(cell);
}
~Layer()
{
for (int i=0;i<celllist.size();i++)
{
delete celllist[i];
}
}
void DelCell(NerveCell* cell);//delete the cell
NerveCell* operator[](int i);
};
double Sigmoid(double x);
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -