?? node.cpp
字號:
// Node.cpp: implementation of the CNode class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "數字識別.h"
#include "Node.h"
#include <fstream.h>
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CNode::CNode(char fileName[]){
valve = 1;
file = NULL;
file = new char[strlen(fileName)];
if(NULL != file){
length = 140; // 長度可變
int i;
strcpy(file, fileName);
ifstream inf(fileName);
weight = new int[length];
for(i = 0; i < length; i++){
weight[i] = 0;
inf>>weight[i];
}
}
}
CNode::~CNode(){
Save();
if(NULL != file){
delete[] file;
delete[] weight;
}
}
int CNode::GetResult(int * input){ // 計算輸出
int i = 0;
int sum = 0;
for(i = 0;i < length; i++){
sum += input[i] * weight[i];
}
return sum > valve?1:0; // 函數比較簡單,大于1(初始化時value為1)則輸入1,否則輸出0
}
void CNode::Save(){
if(NULL != file){
int i;
ofstream ofs(file, ios::out);
for(i = 0; i < length; i++){
ofs<<weight[i]<<" ";
}
}
}
void CNode::Study(int * input, int result){ // 學習函數
int tr = GetResult(input);
if(tr > result){
//-
int i = 0;
for(i = 0;i < length; i++){
weight[i] -= input[i];
}
}
else if(tr < result){
//+
int i = 0;
for(i = 0;i < length; i++){
weight[i] += input[i];
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -