基於感知器模型的線性神經網絡

   摘要:隨着計算智的提出,人工神經網絡也隨之發展。目前業界考慮到把神經網絡(NN)歸類於人工智能(AI)可能不大合適,而歸類於計算智能(CI)更能說明問題實質。進化計算、人工生命和模糊邏輯系統的某些課題,也都歸類於計算智能。儘管計算智能與人工智能的界限並非十分明顯,然而討論它們的區別和關係是有益的,邏輯性的思維是指根據邏輯規則進行推理的過程;它先將信息化成概念,並用符號表示,然後,根據符號運算按串行模式進行邏輯推理;這一過程可以寫成串行的指令,讓計算機執行。然而,直觀性的思維是將分佈式存儲的信息綜合起來,結果是忽然間產生想法或解決問題的辦法。而本文就是專門討論關於神經網絡處理問題的一般思路,同時也爲計算機科學與技術專業大三下專業課《人工智能》的第四個算法實驗。

關鍵字:人工智能,神經網絡,感知器模型

Production system

Abstract: Putting forward along with the computing intelligence, artificial neural network has been developing. At present the industry considering the neural network (NN) classified as artificial intelligence (AI) may not appropriate, and classified as computational intelligence (CI) more telling. Evolutionary computation, artificial life, and some issues of the fuzzy logic system, are classified as computational intelligence. Despite the limits of computational intelligence and artificial intelligence is not obvious, however, discuss the difference and relationship is beneficial, logical thinking refers to the process according to the rules of logic reasoning; It will first information into the concept and symbol, and then, according to the symbolic operation logic reasoning according to the serial mode; This process can be written as a serial of instruction, let the computer to perform. However, visual thinking is the distributed storage of information together, the result is suddenly an idea or a solution to the problem. And this paper is devoted to general thoughts about neural network processing, as well as computer science and technology under the junior professional class "artificial intelligence" of the fourth algorithm experiment.

Keywords: Artificial intelligence, neural network, the perceptron model

1,神經網絡的發展

 20世紀50年代,Rosenblatt等人提出了感知器(神經網絡)模型,並形成了連接主義學派。

1.1 
連接主義觀點核心
   智能的本質是連接機制,
神經網絡是一個由大量簡單的處理單元組成的高度複雜的大規模非線性自適應系統。
 

1.2 
模擬人腦的智能行爲的四個層面
   
物理結構
   
計算模擬
   
存儲與操作
   
訓練

1.3人工神經網絡
   
神經網絡是一個並行和分佈式的信息處理網絡。它是以處理單元爲節點,用加權有向弧相互連接而成的有向圖。處理單元是對生理神經元的模擬,而有向弧是對軸突-突觸-樹突對的模擬。有向弧的權重表示兩處理單元間相互作用的強弱。它一般由大量神經元組成 
   
每個神經元只有一個輸出,可以連接到很多其他的神經元
   
每個神經元輸入有多個連接通道,每個連接通道對應於一個連接權係數

2.模型的建立

2.1 人工神經網絡模型

 

圖片

2.2 
響應函數的基本作用

控制輸入對輸出的激活作用
對輸入、輸出進行函數轉換
將可能無限域的輸入變換成指定的有限範圍內的輸出  

圖片
       
圖片

2.3 感知器模型

感知器是由美國計算機科學家羅森布拉特(F.Roseblatt)於1957年提出的。單層感知器神經元模型圖:

 

圖片

2.4數學模型

圖片

圖片

圖片

3.感知器算法

3.1訓練步驟

 1)對於所要解決的問題,確定輸入向量  X,目標向量T,由此確定維數及網絡結構參數,n,m;

2)  參數初始化;

3)設定最大循環次數;

4)計算網絡輸出;

5)檢查輸出矢量Y與目標矢量T是否相同,如果相同,或以達最大循環次數,訓練結束,否則轉入6

6)學習,並返回4。


3.2網絡訓練

自適應線性元件的網絡訓練過程可以歸納爲以下三個步驟:

1)表達:計算模型的輸出矢量AW*PB,以及與期望輸出之間的誤差ET—A

2)檢查:將網絡輸出誤差的平方和與期望誤差相比較,如果其值小於期望誤差,或訓練已達到事先設定的最大訓練次數,則停止訓練; 

3)學習:採用W—H學習規則計算新的權值和偏差,並返回到1)。  


4,問題引入

4.1問題描述
   現在來考慮一個較大的多神經元網絡的模式聯想的設計問題。輸入矢量和目標矢量分別爲:

P= 

{

{1,-1,2},

{1.5,2,1},

{1.2,3,-1.6},

{-0.3,-0.5,0.9}

};


T=

{

{0.5,1.1,3,-1},

{3,-1.2,0.2,0.1},

{-2.2,1.7,-1.8,-1.0},

{1.4,-0.4,-0.4,0.6}

};

4.2解題思路

   由輸入矢量和目標輸出矢量可得:輸入向量個數 r=3,輸出向量個數 s=4,樣本數 q=4。

這個問題的求解同樣可以採用線性方程組求出,即對每一個輸出節點寫出輸入和輸出之間的關係等式。 

實際上要求出這16個方程的解是需要花費一定的時間的,甚至是不太容易的。

對於一些實際問題,常常並不需要求出其完美的零誤差時的解。也就是說允許存在一定的誤差。

在這種情況下,採用自適應線性網絡求解就顯示出它的優越性:因爲它可以很快地訓練出滿足一定要求的網絡權值。 

 

5,程序設計

圖片


#include<iostream>
#include<ctime>
#include<cmath>
using namespace std;

const int max_learn_length = 100;        //最大學習次數
const float study_rate = 0.2;            //學習率
const float anticipation_error = 0.01;   //期望誤差
const int input = 3;     //三項輸入
const int output = 4;    //四項輸出
const int sample = 4;    //4組樣本

float P[sample][input] =      //4組3項的輸入矢量
{
	{1,-1,2},
	{1.5,2,1},
	{1.2,3,-1.6},
	{-0.3,-0.5,0.9}
};
float T[sample][output] =     //4組4項的期望輸出矢量
{
	{0.5,1.1,3,-1},
	{3,-1.2,0.2,0.1},
	{-2.2,1.7,-1.8,-1.0},
	{1.4,-0.4,-0.4,0.6}
};

int main(int argc, char **argv)
{
	float precision;            //誤差精度變量
	float W[input][sample];     //3項4組輸入對應的網絡權值變量
	float B[sample];            //4組閾值變量
	float A[sample];    //每組實際輸出值
	int ii, ij, ik, ic;

	srand(time(0));             //初始化隨機函數
	for (ii = 0; ii<sample; ii++)
	{
		B[ii] = 2 * (float)rand() / RAND_MAX - 1;   //閾值變量賦隨機值(-1,1)
		for (ij = 0; ij<input; ij++)      //網絡權值變量賦隨機值 
		{
			W[ij][ii] = 2 * (float)rand() / RAND_MAX - 1;
		}
	}
	precision = FLT_MAX ;         //初始化精度值
	for (ic = 0; ic < max_learn_length; ic++)     //最大學習次數內循環
	{
		if (precision<anticipation_error)   //循環剪枝函數
		{
			break;
		}
		precision = 0;
		for (ii = 0; ii<sample; ii++)  //4組樣本循環疊加誤差精度
		{
			for (ij = 0; ij<output; ij++)  //計算一組中4項實際的輸出
			{
				A[ij] = 0.0;
				for (ik = 0; ik<input; ik++)  
				{
					A[ij] += P[ii][ik] * W[ik][ij];
				}
				A[ij] += B[ij];
			}
			for (ij = 0; ij<output; ij++)   //通過學習率調整網絡權值和閾值
			{
				for (ik = 0; ik<input; ik++)
				{
					W[ik][ij] += study_rate*(T[ii][ij] - A[ij])*P[ii][ik];
				}
				B[ij] += study_rate*(T[ii][ij] - A[ij]);
			}
			for (ij = 0; ij<output; ij++)   //計算誤差精度
			{
				precision += pow((T[ii][ij] - A[ij]),2);
			}
		}
	}
	cout << "最大學習次數爲:" << max_learn_length << endl;
	cout << "完成目標的學習次數爲:" << ic << endl;
	cout << endl << "期望誤差爲:" << anticipation_error << endl;
	cout << "達成目標學習後的精度爲:" << precision <<endl<< endl;
	cout << "學習後的網絡權值爲:" << endl;
	for (ii = 0; ii<sample; ii++)       //輸出學習後的網絡權值
	{
		for (ij = 0; ij<input; ij++)    //4組樣本每組3個輸入
		{
			cout << W[ii][ij] << "   ";
		}
		cout << endl;
	}
	cout <<endl<< "學習後的閾值爲:" << endl;   
 	for (ii = 0; ii<output; ii++)       //輸出學習後的閾值:四個樣本輸出
	{
		cout << B[ii] << "   ";
	}
	cout << endl<<endl;
	system("pause");
	return 0;
}












發佈了21 篇原創文章 · 獲贊 14 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章