【情感識別】基於matlab PNN概率神經網路語音情感識別【含Matlab原始碼 544期】
阿新 • • 發佈:2021-06-27
一、簡介
1 概述
1.1 模式分類的貝葉斯決策理論
2 概率神經網路的網路結構(PNN)
總結:
1、輸入層接收樣本的值,神經元個數與輸入向量長度相等。
2、隱藏層為徑向基層,每個神經元對應一箇中心(對應一個樣本資料)。
3、輸入資料分為了i類,因為PNN就是用來分類的,就是先用樣本訓練網路,然後輸入資料,用此網路來鑑別,是屬於哪一類資料。
4、上式Xij其實與RBF神經網路一致,就是求每個輸入與樣本的歐式距離,只不過此隱藏層把資料分為了i個類,並且設第i個類有j個數據。
5、然後下圖可以看出,求和層的神經元個數與資料分類的個數相等,此求和層求得上式中,每類資料的平均值。
6、然後比較每一類平均值的大小,把此資料分類到值最大的那一類。
7、下文中,提出在實際計算中,用來理解的公式與實際計算中公式不同,
注意:上邊的求和層的神經元個數與模式分類的個數相等。也就是說只有對應類別的樣本( 隱藏層的神經元)連線, 不與其他無關的樣本連線。
3 概率神經網路的優點
二、原始碼
lc close all clear all load A_fear fearVec; load F_happiness hapVec; load N_neutral neutralVec; load T_sadness sadnessVec; load W_anger angerVec; trainsample(1:30,1:140)=angerVec(:,1:30)'; trainsample(31:60,1:140)=hapVec(:,1:30)'; trainsample(61:90,1:140)=neutralVec(:,1:30)'; trainsample(91:120,1:140)=sadnessVec(:,1:30)'; trainsample(121:150,1:140)=fearVec(:,1:30)'; trainsample(1:30,141)=1; trainsample(31:60,141)=2; trainsample(61:90,141)=3; trainsample(91:120,141)=4; trainsample(121:150,141)=5; testsample(1:20,1:140)=angerVec(:,31:50)'; testsample(21:40,1:140)=hapVec(:,31:50)'; testsample(41:60,1:140)=neutralVec(:,31:50)'; testsample(61:80,1:140)=sadnessVec(:,31:50)'; testsample(81:100,1:140)=fearVec(:,31:50)'; testsample(1:20,141)=1; testsample(21:40,141)=2; testsample(41:60,141)=3; testsample(61:80,141)=4; testsample(81:100,141)=5; class=trainsample(:,141); sum=bpnn(trainsample,testsample,class); figure(1) bar(sum,0.5); set(gca,'XTickLabel',{'生氣','高興','中性','悲傷','害怕'}); ylabel('識別率'); xlabel('五種基本情感'); p_train=trainsample(:,1:140)'; t_train=trainsample(:,141)'; p_test=testsample(:,1:140)'; t_test=testsample(:,141)'; sumpnn=pnn(p_train,t_train,p_test,t_test); figure(2) bar(sumpnn,0.5); set(gca,'XTickLabel',{'生氣','高興','中性','悲傷','害怕'}); ylabel('識別率'); xlabel('五種基本情感'); sumlvq=lvq(trainsample,testsample,class); function sum=bpnn(trainsample,testsample,class) %輸入引數:trainsample是訓練樣本,testsample是測試樣本,class表示訓練樣本的類別,與trainsample中資料對應 %sum:五種基本情感的識別率 for i=1:140 feature(:,i)= trainsample(:,i); end %特徵值歸一化 [input,minI,maxI] = premnmx( feature') ; %構造輸出矩陣 s = length( class ) ; output = zeros( s , 5 ) ; for i = 1 : s output( i , class( i ) ) = 1 ; end %建立神經網路 net = newff( minmax(input) , [10 5] , { 'logsig' 'purelin' } , 'traingdx' ) ; %建立前饋神經網路 %設定訓練引數 net.trainparam.show = 50 ; net.trainparam.epochs = 150 ; net.trainparam.goal = 0.1 ; net.trainParam.lr = 0.05 ; %開始訓練 net = train( net, input , output' ) ; %讀取測試資料 for i=1:140 featuretest(:,i)= testsample(:,i); end c=testsample(:,141); %測試資料歸一化 testInput = tramnmx(featuretest' , minI, maxI ) ; %模擬 Y = sim( net , testInput ) sum=[0 0 0 0 0]; %每類情感正確識別個數 %統計識別正確樣本數 for i=1:20 if Y(1,i)>Y(2,i)&&Y(1,i)>Y(3,i)&&Y(1,i)>Y(4,i)&&Y(1,i)>Y(5,i) sum(1)=sum(1)+1; end function sumlvq=lvq(trainsample,testsample,class) P=trainsample(:,1:140)'; C=class'; T=ind2vec(C); net=newlvq(minmax(P),20,[0.2 0.2 0.2 0.2 0.2],0.1); %建立lvq網路 w1=net.IW{1}; net.trainParam.epochs=100; net=train(net,P,T); y=sim(net,testsample(:,1:140)'); y3c=vec2ind(y); sumlvq=[0 0 0 0 0]; %每類情感正確識別個數 %統計識別正確樣本數 for i=1:20 if y3c(i)==1 sumlvq(1)=sumlvq(1)+1; end end for i=21:40 if y3c(i)==2 sumlvq(2)=sumlvq(2)+1; end end for i=41:60 if y3c(i)==3 sumlvq(3)=sumlvq(3)+1; end end for i=61:80 if y3c(i)==4 sumlvq(4)=sumlvq(4)+1; end end for i=81:100 end
三、執行結果
四、備註
版本:2014a
完整程式碼或代寫加1564658423