📄 cell.cpp
字号:
#include "Formula.h"
#include "Cell.h"
#include <assert.h>
void CNerve_cell::Put_input_value (int pos, std::vector <CNerve_cell *> & vec_cell)
{
int i;
if (cell_type == VIRTUAL_TYPE )
return;
db_input_val = 0.0;
for (i = 0; i < vec_cell.size (); i++)
{
//∑w*x
db_input_val += vec_cell[i]->Get_output_value ()*vec_cell[i]->Get_weight (pos);
}
}
void CNerve_cell::Put_input_value ( double x )
{
db_output_val = db_input_val = x;
}
//根据公式计算输出
void CNerve_cell::Calculate()
{
if ( (cell_type != INPUT_TYPE) && (cell_type != VIRTUAL_TYPE ) )
{
db_output_val = CFormula::Instance()->Ask_result (db_input_val);
db_old_input = db_input_val;
db_input_val = 0.0;
}
}
//返回计算结果
double CNerve_cell::Get_output_value ()
{
return db_output_val;
}
double
CNerve_cell::Get_old_input ()
{
return db_old_input;
}
//修改j层神经元与i层神经元的权重
void CNerve_cell::Put_weight ( int pos, double dbw )
{
WEIGHT_MAP::iterator it = map_weight.find (pos);
if (it != map_weight.end())
it->second = dbw;
else
map_weight.insert (std::make_pair ( pos, dbw));
}
//返回某个神经元的权重
double CNerve_cell::Get_weight (int pos)
{
WEIGHT_MAP::iterator it = map_weight.find (pos);
assert (it != map_weight.end ());
return it->second;
}
void
CNerve_cell::Put_diff_w (int pos, double w)
{
WEIGHT_MAP::iterator it = map_diff_w.find (pos);
if (it != map_diff_w.end())
it->second = w;
else
map_diff_w.insert (std::make_pair ( pos, w));
}
double
CNerve_cell::Get_diff_w (int pos)
{
double db = 0.0;
WEIGHT_MAP::iterator it = map_diff_w.find (pos);
if (it != map_diff_w.end())
db = it->second;
return db;
}
//更新所有权重
void
CNerve_cell::Update_weight (int pos, double diffw)
{
WEIGHT_MAP::iterator it = map_weight.find (pos);
/*WEIGHT_MAP::iterator itdiff;
for (; it != map_weight.end (); it++)
{
itdiff = map_diff_w.find (it->first); //w = w+△w
it->second += (itdiff != map_diff_w.end () ? itdiff->second : 0);
}*/
if ( it != map_weight.end () )
it->second += diffw;
Put_diff_w (pos, diffw);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -