日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

人工智能一种现代化学习方法——学习笔记(13章)

發布時間:2023/12/31 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 人工智能一种现代化学习方法——学习笔记(13章) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

第13章——不確定的量化

人工智能一種現代化的學習方法(第3版)學習筆記。

  • 13.1不確定環境下的行動
  • 13.2基本概率符號
  • 13.3使用完全聯合分布進行推理
  • 13.4獨立性
  • 13.5貝葉斯規則及其應用
  • 13.6重游Wumpus世界
  • 13.7本章小結
  • 文獻與歷史注釋

13.1不確定環境下的行動

決策理論 = 概率理論 + 效用理論
決策理論基本思想:
一個Agent是理性的,當且僅當它選擇能產生最高期望效用的行動,這里的期望效用是行動的所有可能結果的平均。這成為期望效用最大化(Maximum Expected Utility, MEU)。

先驗概率(無條件概率)
是指根據以往經驗和分析得到的概率,如全概率公式,它往往作為”由因求果”問題中的”因”出現的概率·
后驗概率(條件概率)
基于新的信息,修正原來的先驗概率后所獲得的更接近實際情況的概率估計。

13.2.2概率斷言中的命題語言

隨機變量
變量的名字以大寫字母開頭,比如投擲兩個一樣的骰子,他們的點數之和Total就是隨機變量。Total的定義域是{2,…,12};一個布爾變量的定義域是{true,false}(變量的值總是小寫)。
例:
“如果患者是一個沒有牙痛的青少年,那么他有牙洞的概率是0.1” => P(cavity|?toothache^teen)=0.1

13.3使用完全聯合分布進行推理

例:
三個布爾變量
- Toothache,牙痛
- Cavity,牙洞
- Catch,牙醫的鋼探針不潔導致牙齦感染
對應的完全聯合分布2x2x2的表格:

(1)將使命題為真的概率相加
P(cavity∨toothache)=0.108+0.012+0.072+0.008+0.016+0.064=0.28(∨是邏輯或)
(2)無條件概率(邊緣概率)
P(cavity)=0.108+0.012+0.072+0.008=0.2

13.4獨立性

計算,P(toothace,catch,cavity,cloudy)=P(cloudy|toothace,catch,cavity)P(toothace,catch,cavity)
因為cloudy與toothace,catch,cavity互相獨立,
所以,P(cloudy|toothace,catch,cavity)=P(cloudy)
所以,P(toothace,catch,cavity,cloudy)=P(cloudy) P(toothace,catch,cavity)

13.5貝葉斯規則及其應用

常用形式:

通用形式:

例:
醫生知道腦膜炎會引起病人脖子僵硬,比如有70%的機會。醫生還了解一些無條件事實:病人患腦膜炎的先驗概率是1/50000,而任何一個脖子僵硬的先驗概率為1%,令s表示“病人脖子僵硬”的命題,m表示“病人患有腦膜炎”的命題,則有

也就是說,我們期望700個有脖子僵硬癥狀的病人中只有不到1個人患有腦膜炎。注意,盡管腦膜炎相當強烈地預示著會有脖子僵硬的癥狀(概率為0.7),但脖子僵硬的病人患有腦膜炎的 概率依然很低。這是因為脖子僵硬的先驗概率大大高于患腦膜炎的先驗概率。
樸素貝葉斯:
參考算法雜貨鋪——分類算法之樸素貝葉斯分類(Naive Bayesian classification)

例:
實驗內容:
利用貝葉斯算法或者決策樹算法進行數據分類操作
數據集:汽車評估數據集(見附錄CarDatas.txt)
實驗步驟:
1.仔細閱讀并了解實驗數據集;
2.使用任何一種熟悉的計算機語言(比如C,Java或者matlab)實現樸素貝葉斯算法或者決策樹算法;
3.利用樸素貝葉斯算法或者決策樹算法在訓練數據上學習分類器,訓練數據的大小分別設置為:前100個數據,前200個數據,前500個數據,前700個數據,前1000個數據,前1350個數據;
4.利用測試數據對學習的分類器進行性能評估;
5.統計分析實驗結果并上交實驗報告;
實驗思路:

#include<iostream> #include<cstdlib> #include<cstring> #include<vector> #include<fstream> #include<stdio.h> using namespace std;int countTrain = 0;//訓練樣本數目 int countTest = 0;//測試樣本數目 int countTestSuc = 0;//測試樣本正確的數目 int countF=100; //訓練和測試的分界 string CVname[4]={"unacc","acc","good","vgood"}; int ClassValues[4]; //unacc, acc, good, vgood int buying[4][4]; //vhigh, high, med, low. int maint[4][4]; // vhigh, high, med, low. int doors[4][4]; //2, 3, 4, 5more. int persons[4][4]; //2, 4, more. int lug_boot[4][4]; //small, med, big. int safety[4][4]; //low, med, high. float ClassValuesL[4]; //unacc, acc, good, vgood float buyingL[4][4]; //vhigh, high, med, low. float maintL[4][4]; // vhigh, high, med, low. float doorsL[4][4]; //2, 3, 4, 5more. float personsL[4][4]; //2, 4, more. float lug_bootL[4][4]; //small, med, big. float safetyL[4][4]; //low, med, high. //統計個數 void Tonji(string a,string b,string c,string d,string e,string f,string g){ //cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<" "<<f<<" "<<g<<endl; for(int i=0;i<4;i++)if(g==CVname[i]){ClassValues[i]++;//buying: vhigh, high, med, low.if(a=="vhigh") buying[0][i]++;else if(a=="high") buying[1][i]++;else if(a=="med") buying[2][i]++;else if(a=="low") buying[3][i]++;//maint: vhigh, high, med, low. if(b=="vhigh") maint[0][i]++;else if(b=="high") maint[1][i]++;else if(b=="med") maint[2][i]++;else if(b=="low") maint[3][i]++;//doors: 2, 3, 4, 5more.if(c=="2") doors[0][i]++;else if(c=="3") doors[1][i]++;else if(c=="4") doors[2][i]++;else doors[3][i]++;//persons: 2, 4, more. if(d=="2") persons[0][i]++;else if(d=="4") persons[1][i]++;else persons[2][i]++;//lug_boot: small, med, big.if(e=="small") lug_boot[0][i]++;else if(e=="med") lug_boot[1][i]++;else if(e=="big") lug_boot[2][i]++;//safety: low, med, high. if(f=="low") safety[0][i]++;else if(f=="med") safety[1][i]++;else if(f=="high") safety[2][i]++;break;} } //讀取文件 void ReadFileTrain(){ifstream fin("CarDatas.txt");string a,b,c,d,e,f,g;int i = countF;while((i--)>0 && fin>>a && fin>>b&& fin>>c && fin>>d && fin>>e && fin>>f && fin>>g){countTrain++;Tonji(a,b,c,d,e,f,g); }fin.close();cout<<"訓練樣本countTrain="<<countTrain<<endl; } //統計得到在各類別下各個特征屬性的條件概率估計 void CalAP(){ //概率P(yi)for(int i=0;i<4;i++){ClassValuesL[i] = (float) ClassValues[i]/countTrain;}//特別注意的是P(ai|yi)=ai/0的情況!!!,會使 P(ai|yi)等于nan; for(int i=0;i<4;i++){ //概率P(ai|yi) for(int j=0;j<4;j++){buyingL[i][j] = (float) buying[i][j]/ClassValues[j]; if(buyingL[i][j]<0 || buyingL[i][j]>1) buyingL[i][j]=0;maintL[i][j] = (float) maint[i][j]/ClassValues[j]; if(maintL[i][j]<0 || maintL[i][j]>1) maintL[i][j]=0;doorsL[i][j] = (float) doors[i][j]/ClassValues[j]; if(doorsL[i][j]<0 || doorsL[i][j]>1) doorsL[i][j]=0;}}for(int i=0;i<3;i++){ //概率P(ai|yi)for(int j=0;j<4;j++){personsL[i][j] = (float) persons[i][j]/ClassValues[j]; if(personsL[i][j]<0 || personsL[i][j]>1) personsL[i][j]=0;lug_bootL[i][j] = (float) lug_boot[i][j]/ClassValues[j]; if(lug_bootL[i][j]<0 || lug_bootL[i][j]>1) lug_bootL[i][j]=0;safetyL[i][j] = (float) safety[i][j]/ClassValues[j]; if(safetyL[i][j]<0 || safetyL[i][j]>1) safetyL[i][j]=0;}} } //一行數據的準確與否,P(Bi|A)=P(A|Bi)P(Bi)/P(A),其中P(A)相同,只需比較分子的大小即可 bool TestLine(string ai,string bi,string ci,string di,string ei,string fi,string gi){int b, m, d, p, l, s;//buying:if(ai=="vhigh") b=0;else if(ai=="high") b=1;else if(ai=="med") b=2;else if(ai=="low") b=3;//maint:if(bi=="vhigh") m=0;else if(bi=="high") m=1;else if(bi=="med") m=2;else if(bi=="low") m=3;//doors:if(ci=="2") d=0;else if(ci=="3") d=1;else if(ci=="4") d=2;else d=3;//persons:if(di=="2") p=0;else if(di=="4") p=1;else p=2;//lug_boot:if(ei=="small") l=0;else if(ei=="med") l=1;else if(ei=="big") l=2;//safety: if(fi=="low") s=0;else if(fi=="med") s=1;else if(fi=="high") s=2;float Bi; float MaxB=0;int t=0;//計算四個P(Bi|A)的概率取最大的 for(int i=0;i<4;i++){Bi=buyingL[b][i] * maintL[m][i] * doorsL[d][i] * personsL[p][i] * lug_bootL[l][i] * safetyL[s][i] * ClassValuesL[i];if(MaxB < Bi && Bi<=1){MaxB = Bi;t = i;}}//判斷預測和事實是否相等 if(CVname[t]==gi) return true;else return false; } //讀取并測試文件 void ReadFileTest(){ifstream fin("CarDatas.txt");string a,b,c,d,e,f,g;bool t=false;int i=0;while(++i && fin>>a && fin>>b&& fin>>c && fin>>d && fin>>e && fin>>f && fin>>g){if(i>countF){ countTest++;t=TestLine(a,b,c,d,e,f,g); if(t) countTestSuc++; }}fin.close(); } void setZero(); int main(){int a[5]={100,200,500,700,1350};for(int i=0;i<5;i++){setZero();countF=a[i]; //訓練和測試的分界 ReadFileTrain(); //讀取文件并且統計個數CalAP(); //計算條件概率 ReadFileTest(); //測試樣本 cout<<"預測正確countTestSuc="<<countTestSuc<<endl;cout<<"測試樣本countTest="<<countTest<<endl;cout<<"準確率為:"<<100.0*((float)countTestSuc/(float)countTest)<<"%"<<endl<<endl;}return 0; } //重新賦值為零 void setZero(){countTrain = 0;//訓練樣本數目countTest = 0;//測試樣本數目countTestSuc = 0;//測試樣本正確的數目for(int i=0;i<4;i++)for(int j=0;j<4;j++){ClassValues[i]=0; //unacc, acc, good, vgood buying[i][j]=0; //vhigh, high, med, low.maint[i][j]=0; // vhigh, high, med, low. doors[i][j]=0; //2, 3, 4, 5more. persons[i][j]=0; //2, 4, more. lug_boot[i][j]=0; //small, med, big.safety[i][j]=0; //low, med, high. ClassValuesL[i]=0; //unacc, acc, good, vgood buyingL[i][j]=0; //vhigh, high, med, low.maintL[i][j]=0; // vhigh, high, med, low. doorsL[i][j]=0; //2, 3, 4, 5more. personsL[i][j]=0; //2, 4, more. lug_bootL[i][j]=0; //small, med, big.safetyL[i][j]=0; //low, med, high. } }

實驗結果:

總結

以上是生活随笔為你收集整理的人工智能一种现代化学习方法——学习笔记(13章)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。