- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello, I'm trying to train some FeedForward Neural Networks wthi the dtrnlsp subroutines from MKL, but it seems not to work properly, I've been searching for an error for three days already and I just can't figure it out. So I think I'm not using it right. The files from my program are added here, It is small program and has the files.
Rede.f -> Starts the subroutines
CalcErro.f -> Calculates the error of the neural network
FF.f -> The Neural network itself, that write the weights, bias and the output for the function
Gaussiana.f -> The activation function (Gaussian)
Entradas.dat -> The input file, in this case a sinus in a half period
Makefile -> Self explanatory
Well, the problem is! it returns me Segmentation fault every time. I think is something wrong with the fvec, but I couldn't figure it out! As i'm not really sure that the files are here I will paste the files here too.
Thanks
Rene
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Program Rede
Implicit none
integer i,j,k,l,m,n,numneu
parameter (m=200,numneu=8,n=3*numneu+1)
double precision Ent(m,2),X(n),eps(6),rs
double precision fvec(m),fjac(m,n),jac_eps,r1,r2
integer iter1,iter2,RCI_Request,sucesso,st_cr,iter
parameter (iter1=10000,iter2=100,rs=1d2,jac_eps=1d-8)
include "/opt/intel/Compiler/11.1/064/mkl/include/mkl_rci.fi"
integer*8 handle
external CalcErro
Call Random_Seed()
open (unit=1, file='Entradas.dat', status='unknown')
do i=1,m
read(1,*)(Ent(i,j),j=1,2)
enddo
Call Random_Number(X)
X=(X*2.d0)-1.d0
eps(1)=1d-5
eps(2)=1d-5
eps(3)=1d-5
eps(4)=1d-5
eps(5)=1d-5
eps(6)=1d-5
fvec=0.d0
fjac=0.d0
if (dtrnlsp_init(handle,n,m,x,eps,iter1,iter2,rs)/=TR_SUCCESS)then
print*, 'Deu pau na hora de iniciar'
Call MKL_FREEBUFFERS
stop
end if
RCI_Request=0
sucesso=0
do while (sucesso==0)
if (dtrnlsp_solve(handle, fvec, fjac, RCI_Request)/= TR_SUCCESS) then
print*,'Deu pau na hora de resolver'
Call MKL_FREEBUFFERS
stop
end if
Select Case (RCI_Request)
Case (-1,-2,-3,-4,-5,-6)
Sucesso=1
Case(1)
Call CalcErro(X,fvec,Ent,m,n,numneu)
Case(2)
If(djacobi(CalcErro,n,m,fjac,X,jac_eps)/=TR_SUCCESS) then
Print*,'Deu pau na matriz Jacobiana'
Call MKL_FREEBUFFERS
stop
end if
EndSelect
enddo
if (dtrnlsp_get(handle,iter,st_cr,r1,r2)/= TR_SUCCESS) then
Print*,'Deu pau no get'
Call MKL_FREEBUFFERS
stop
end if
if (dtrnlsp_delete(handle)/= TR_SUCCESS) then
Print *, 'Deu pau na hora de apagar'
Call MKL_FREEBUFFERS
stop
end if
Call MKL_FREEBUFFERS
if (r2<1d-5) then
Print *,'Deu certo'
else
Print*, 'Falhou'
end if
Print *, st_cr
Call FF(X,Ent,m,n,numneu)
end Program Rede
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
c ******************************************************************
c Calculo do Erro
c ******************************************************************
c Subrotina utilizada para calcular o erro da rede
c O erro calculado da seguinte forma
c
c Erro=(target-(saida da rede))
Subroutine Calcerro(X,Erro,XY,n,m,numneu)
Implicit none
c
type neuronio
double precision entrada
double precision ativacao
end type neuronio
integer i,j,k,l,m,n,numneu
Double precision Pesos(2*numneu), Erro(n), Bias(numneu+1),X(m)
Double precision Gauss, XY(n,2), Saida
type(neuronio) H1(numneu), Or
Erro=0.d0
k=0
do i=1,2*numneu
k=k+1
Pesos(i)=X(k)
enddo
do i=1,numneu+1
k=k+1
Bias(i)=X(k)
enddo
do l=1,n
do i=1,numneu
H1(i)%entrada=0.d0
H1(i)%ativacao=0.d0
enddo
c
Or%entrada=0.d0
Or%ativacao=0.d0
do i=1,numneu
H1(i)%entrada=XY(l,1)*Pesos(i)
H1(i)%entrada=H1(i)%entrada+Bias(i)
H1(i)%ativacao=Gauss(H1(i)%entrada)
enddo
do i=(numneu+1),2*numneu
Or%entrada=Or%entrada+(H1(i-numneu)%ativacao*Pesos(i))
enddo
Or%entrada=Or%entrada+Bias(numneu+1)
Or%ativacao=Or%entrada
Saida=0.d0
Saida=Or%ativacao
Erro(l)=0.d0
Erro(l)=(XY(l,2)-Saida)
enddo
Print *, 'Passei por aqui'
return
end subroutine Calcerro
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Function Gauss(W)
Implicit none
double precision W, Gauss
Gauss=dexp(-(W**2.d0))
end Function Gauss
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Subroutine FF(X,XY,n,m,numneu)
Implicit none
c
type neuronio
double precision entrada
double precision ativacao
end type neuronio
integer i,j,k,l,m,n,numneu
Double precision Pesos(2*numneu), Bias(numneu+1),X(3*numneu+1)
Double precision Gauss, XY(n,2), Saida(n)
type(neuronio) H1(numneu), Or
Saida=0.d0
k=0
do i=1,2*numneu
k=k+1
Pesos(i)=X(k)
enddo
do i=1,numneu+1
k=k+1
Bias(i)=X(k)
enddo
do l=1,n
do i=1,numneu
H1(i)%entrada=0.d0
H1(i)%ativacao=0.d0
enddo
c
Or%entrada=0.d0
Or%ativacao=0.d0
do i=1,numneu
H1(i)%entrada=XY(l,1)*Pesos(i)
H1(i)%entrada=H1(i)%entrada+Bias(i)
H1(i)%ativacao=Gauss(H1(i)%entrada)
enddo
do i=(numneu+1),2*numneu
Or%entrada=Or%entrada+(H1(i-numneu)%ativacao*Pesos(i))
enddo
Or%entrada=Or%entrada+Bias(numneu+1)
Or%ativacao=Or%entrada
Saida(l)=0.d0
Saida(l)=Gauss(Or%ativacao)
enddo
open (unit=5, file='Saida.dat', status='Unknown')
do i=1,n
write(5,*) XY(i,1),Saida(i)
enddo
open (unit=3, file='Pesos.dat', status='Unknown')
do i=1,2*numneu
write(3,*) Pesos(i)
enddo
open (unit=4, file='Bias.dat', status='Unknown')
do i=1,numneu+1
write(4,*) Bias(i)
enddo
return
end subroutine FF
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SOURCE = Rede.f CalcErro.f Gaussiana.f FF.f
FFLAGS =
MKLINCLUDE= /opt/intel/Compiler/11.1/064/mkl/include
MKLPATH = /opt/intel/Compiler/11.1/064/mkl/lib/em64t/
LIBS = -L$(MKLPATH) -I$(MKLINCLUDE) -Wl,--start-group $(MKLPATH)libmkl_intel_lp64.a $(MKLPATH)libmkl_sequential.a $(MKLPATH)libmkl_core.a -Wl,--end-group -lpthread
FC = ifort
all:
$(FC) $(FFLAGS) $(SOURCE) $(LIBS) -o Rede
clean:
rm -rf Rede Pesos.dat Bias.dat Saida.dat
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Segmentation fault means that you're trying to access a memory location that it is not allowed to access or in not allowed way (e.g. write to a read-only location). Check whether all arrays are correctly allocated and passed etc. Does the calling program "see" the FF function the right way. try to switch on automatic (or code it manually) interfaces for the routines, so compiler will have a chance to check couple of things for you.
If this doesn't help, then post here exact error message and place where it appears.
A.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Rene,
Ive looked over your codes. At first sight here is a problem with djacobi calling. The first parameter is pointer to function which should has the following interface:
fcn (m, n, x, f) with the following parameters:
m - INTEGER. Input parameter. Length of f
n - INTEGER. Input parameter. Length of x.
x - DOUBLE PRECISION. Input parameter. Array of size n. Vector, at which the function is evaluated. The fcn function should not change this parameter.
f - DOUBLE PRECISION. Output parameter. Array of size m; contains the function values at x.
Declare fcn as EXTERNAL in the calling program.
In your codes:
If(djacobi(CalcErro,n,m,fjac,X,jac_eps)/=TR_SUCCESS) then
Where: Subroutine Calcerro(X,Erro,XY,n,m,numneu)
So, please change the interface or use the RCI version djacobi routine.
If it doesnt work, please let me know.
Thank you!
--Nikita
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank You very much! It's working really fine! I've made the fcn subroutine and followed the example programs too! But your help was really important! I'm really grateful
Rene
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page