! Below is an example whereby a network with 2 inputs, 1 output and ! two hidden layers each with 3 nodes is trained to output the XOR of the two inputs: ! The training files should start with the number of inputs, followed by the number of outputs, each on a new lines. ! The rest of the data should then follow, with inputs before their outputs. ! For example, if there are two inputs and one output, the following file suggests that 1 and 0 should result in 1: ! following file suggests that 1 and 0 should result in 1: use neural type(network) :: testNet !Integer :: Mxvar, Myvar, Nspl !Integer :: i,j !Real, Allocatable :: X_inp(:,:), Y_out(:,:), Yest(:,:), X(:) double precision, Allocatable :: tmp(:) Real :: a,b,c,d,PC,POD !----------------------------------------------------------------------------- call neural_init_network(testNet, (/ 5, 3, 2, 1 /)) ! 4 so ung voi 4 layers va so node cua tung layer ! layer 1=input, layer 2,3 hidden, layer va so node trong layer, layer 4=output call neural_train_network_file(testNet, "data_test_spei.txt", 10000,0.05d00) ! xor.dat la input data filename: ! Dong 1: So bien dau vao (X1,X2,..,Xm) ! Dong 2: So bien dau ra (y1, Y2, Yk) ! m+k dong tiep theo: m gia tri cua X va k gia tri cua Y ! Neu dung luong mau bang N thi se co N khoi m+k tren day. print*,"neural_train_network_file ... Done" ! call neural_save_network(testNet, "network.dat") print*,"neural_save_network ---" ! call neural_load_network(testNet, "network.dat") print*,"neural_load_network...Done" !print *, "1 and 1 = ", neural_use_network(testNet, (/ 1.0d00, 1.0d00 /)) ! Test for x1=1, x2=1 !print *, "0 and 1 = ", neural_use_network(testNet, (/ 0.0d00, 1.0d00 /)) ! Test for x1=0, x2=1 Allocate (X(Mxvar),tmp(Myvar)) a=0.;b=0.;c=0.;d=0. !Do j=1,Myvar Do i=1,Nspl X(1:Mxvar)=X_inp(i,1:Mxvar) tmp(:) = neural_use_network(testNet,X) tmp(:) = tmp(:)*(Ymax(:)-Ymin(:))+Ymin(:) !print*,neural_use_network(testNet,X) print "(10F6.2)",tmp(:),Y_out(i,:)*(Ymax(:)-Ymin(:))+Ymin(:) if (tmp(1)==1..AND.Y_out(i,1)==1.) a=a+1. if (tmp(1)==0..AND.Y_out(i,1)==0.) d=d+1. if (tmp(1)==0..AND.Y_out(i,1)==1.) c=c+1. if (tmp(1)==1..AND.Y_out(i,1)==0.) b=b+1. ! print*,a,b,c,d Enddo PC = (a+d)/(a+b+c+d) POD = (a+c)/(a+b+c+d) print*,PC,POD !Enddo End