I'm trying to use ffnet to create a neural network for a project.
I saw that at the end you have to export with "exportnet" to a " *.f " file. But I don't know how to compile this file with ffnet.f module
In fact I think that I have to give the input and after compiling with ffnet.f it will give me the answer output.
I did'nt find the way to do that in the documentation. I just read "You need ‘ffnet.f’ file distributed with ffnet sources to get the exported Fortran routines to work"
It could be a very simple stuff but It will be very nice if someone can help me!
Thank's a lot!
from ffnet import mlgraph, ffnet, exportnet
net = ffnet(mlgraph((3,10,2)))
### some training here ###
exportnet(net, 'mynetwork.f', name='mynet')
Then copy file ffnet.f (which is distributed with sources downloadable from sourceforge) to the same directory. Now you have to write your Fortran program which will use trained network.
double precision input(3), output(2)
input(1) = 0.
input(2) = 3.
input(3) = 10.
call mynet(input, output)
write(*,*) "Network inputs:", input(1), input(2), input(3)
write(*,*) "Network outputs:", output(1), output(2)
If you save this as myprogram.f you can compile everything with:
gfortran ffnet.f mynetwork.f myprogram.f -o myprogram
and call simply as:
Obviously if work on some Fortran project just include mynetwork.f and ffnet.t to the project infrastructure and call the network as in the above example. You can also call network derivatives ('dmynet' subroutine)
I am having a similar problem. I have gotten the XOR problem to run successfully in Python, and now I am trying to compile in Fortran.
I am using Salford F95 compiler on a Win7 machine. I have created a new Fortran project and added the ffnet.f, and xor.f to the project.
I created another file called main.f that reads:
double precision output
call xor((0.,1.), output)
write(*,*) "Network outputs:", output
However, the compiler runs into an error…
Compiling file: main.f95
Compiling file: ffnet.f
C:\Python27\ffnet.F(147) : warning 298 - Variable DERI has been used without being given an initial value
C:\Python27\ffnet.F(147) : error 283 - DERI must appear in a type declaration because IMPLICIT NONE has been used
C:\Python27\ffnet.F(743) : warning 684 - There are (at least) 2 truncated line(s) in this file
Thanks for your help!
P.S. The ffnet code is great. Once I get this working, it is going to be incredibly useful for me.
147 line is:
bunits(ctrg) = bunits(ctrg) * deriv
It seems your compiler cuts of the last "v". Try to edit ffnet.f and remove some spaces/tabs before "bunits….". This should help.
Thanks for report - i'll modify ffnet.f for future releases…
Thanks for the response, I will try that.
Also, have you considered adding functionality to use different transfer functions? Once I get the code working I was going to see if I could implement this, although the programming may be out of my league. For example, user could define tanh for first hidden layer, sigmoid for second hidden layer, and identity for output layer.