Go and neural networks

915 views
Skip to first unread message

white_pony

unread,
Mar 14, 2011, 6:01:16 PM3/14/11
to golang-nuts
Hi, all!

Probably, somebody will be interested:

I wrote Go bindings for nice neural networks library - FANN (http://
leenissen.dk/fann/wp/). You can find it here - https://github.com/white-pony/go-fann
. I rewrote some samples from original library, so it should be easy
to start. If you have any questions - fell free to ask.

John Asmuth

unread,
Mar 14, 2011, 6:27:58 PM3/14/11
to golang-nuts
Great to see someone else playing around with Go and machine
learning :)

I don't know more than the basics for neural networks, but it strikes
me that go's concurrency and channel communication might make for a
nice way to evaluate a NN.

Something about sending a node's contribution to the next node via a
channel, and allowing large groups of nodes to be evaluated
concurrently on different processors.

Admittedly, neural networks are not known for pushing the limits of
computational power, but it might be a nice experiment.

- John

On Mar 14, 6:01 pm, white_pony <rizen...@gmail.com> wrote:
> Hi, all!
>
> Probably, somebody will be interested:
>
> I wrote Go bindings for nice neural networks library - FANN (http://
> leenissen.dk/fann/wp/). You can find it here -https://github.com/white-pony/go-fann

sun...@gmail.com

unread,
Mar 15, 2011, 9:26:33 AM3/15/11
to white_pony, golang-nuts
Nice job!
 
I think it's works fine on Linux. Though I just tested it on windows(my linux machine is not at hand), when I tried to build the examples I got the errors as blow:
 
$ make mushroom
8g mushroom.go
8l -o mushroom mushroom.8
C:/Go/pkg/windows_386/fann.a(fann.cgo2.o)(.text): fann_set_activation_function: not defined
C:/Go/pkg/windows_386/fann.a(fann.cgo2.o)(.text): fann_create_sparse_array: not defined
C:/Go/pkg/windows_386/fann.a(fann.cgo2.o)(.text): fann_set_rprop_delta_min: not defined
C:/Go/pkg/windows_386/fann.a(fann.cgo2.o)(.text): fann_get_network_type: not defined
C:/Go/pkg/windows_386/fann.a(fann.cgo2.o)(.text): fann_get_total_neurons: not defined
C:/Go/pkg/windows_386/fann.a(fann.cgo2.o)(.text): fann_train_on_file: not defined
C:/Go/pkg/windows_386/fann.a(fann.cgo2.o)(.text): fann_get_num_output: not defined
C:/Go/pkg/windows_386/fann.a(fann.cgo2.o)(.text): fann_set_weight_array: not defined
C:/Go/pkg/windows_386/fann.a(fann.cgo2.o)(.text): fann_get_bias_array: not defined
C:/Go/pkg/windows_386/fann.a(fann.cgo2.o)(.text): fann_get_rprop_decrease_factor: not defined
C:/Go/pkg/windows_386/fann.a(fann.cgo2.o)(.text): fann_get_train_error_function: not defined
C:/Go/pkg/windows_386/fann.a(fann.cgo2.o)(.text): fann_save_to_fixed: not defined
C:/Go/pkg/windows_386/fann.a(fann.cgo2.o)(.text): fann_get_rprop_delta_max: not defined
C:/Go/pkg/windows_386/fann.a(fann.cgo2.o)(.text): fann_get_connection_rate: not defined
C:/Go/pkg/windows_386/fann.a(fann.cgo2.o)(.text): fann_clear_scaling_params: not defined
C:/Go/pkg/windows_386/fann.a(fann.cgo2.o)(.text): fann_set_activation_function_layer: not defined
C:/Go/pkg/windows_386/fann.a(fann.cgo2.o)(.text): fann_set_rprop_delta_max: not defined
C:/Go/pkg/windows_386/fann.a(fann.cgo2.o)(.text): fann_get_MSE: not defined
C:/Go/pkg/windows_386/fann.a(fann.cgo2.o)(.text): fann_init_weights: not defined
C:/Go/pkg/windows_386/fann.a(fann.cgo2.o)(.text): fann_get_total_connections: not defined
C:/Go/pkg/windows_386/fann.a(fann.cgo2.o)(.text): fann_get_rprop_increase_factor: not defined
too many errors
make: *** [mushroom] Error 1
 
Surely there’s something wrong with cgo, it can’t find the linked libs but what’s wrong? Is there some thing I can do?
 
Of couse I've first build FANN on windows using MSYS and all the examples works fine, then I installed the go-bindings : go-fann with no problems:
 
CGOPKGPATH= cgo --  fann.go fann-train.go fann-enums.go fann-cascade.go fann-error.go
touch _obj/_cgo_run
8g -o _go_.8  _obj/fann.cgo1.go _obj/fann-train.cgo1.go _obj/fann-enums.cgo1.go _obj/fann-cascade.cgo1.go _obj/fann-error.cgo1.go _obj/_cgo_gotypes.go
8c -FVw -IC:/Go/pkg/windows_386 -I . -o "_cgo_defun.8" _obj/_cgo_defun.c
gcc -m32 -I . -g -fPIC -O2 -o _cgo_main.o -c   _obj/_cgo_main.c
_obj/_cgo_main.c:1:0: warning: -fPIC ignored for target (all code is position independent)
gcc -m32 -I . -g -fPIC -O2 -o fann.cgo2.o -c   _obj/fann.cgo2.c
_obj/fann.cgo2.c:1:0: warning: -fPIC ignored for target (all code is position independent)
gcc -m32 -I . -g -fPIC -O2 -o fann-train.cgo2.o -c   _obj/fann-train.cgo2.c
_obj/fann-train.cgo2.c:1:0: warning: -fPIC ignored for target (all code is position independent)
gcc -m32 -I . -g -fPIC -O2 -o fann-enums.cgo2.o -c   _obj/fann-enums.cgo2.c
_obj/fann-enums.cgo2.c:1:0: warning: -fPIC ignored for target (all code is position independent)
gcc -m32 -I . -g -fPIC -O2 -o fann-cascade.cgo2.o -c   _obj/fann-cascade.cgo2.c
_obj/fann-cascade.cgo2.c:1:0: warning: -fPIC ignored for target (all code is position independent)
gcc -m32 -I . -g -fPIC -O2 -o fann-error.cgo2.o -c   _obj/fann-error.cgo2.c
_obj/fann-error.cgo2.c:1:0: warning: -fPIC ignored for target (all code is position independent)
gcc -m32 -I . -g -fPIC -O2 -o _cgo_export.o -c   _obj/_cgo_export.c
_obj/_cgo_export.c:1:0: warning: -fPIC ignored for target (all code is position independent)
gcc -m32 -g -fPIC -O2 -o _cgo1_.o _cgo_main.o fann.cgo2.o fann-train.cgo2.o fann-enums.cgo2.o fann-cascade.cgo2.o fann-error.cgo2.o _cgo_export.o -lfann -lm
cgo -dynimport _cgo1_.o >_obj/_cgo_import.c_ && mv -f _obj/_cgo_import.c_ _obj/_cgo_import.c
8c -FVw -I . -o "_cgo_import.8" _obj/_cgo_import.c
rm -f _obj/fann.a
gopack grc _obj/fann.a _go_.8  _cgo_defun.8 _cgo_import.8 fann.cgo2.o fann-train.cgo2.o fann-enums.cgo2.o fann-cascade.cgo2.o fann-error.cgo2.o _cgo_export.o
cp _obj/fann.a "C:/Go/pkg/windows_386/fann.a"
 
it works fine and seems no problems, but why can’t I use the fann.a lib with go ?

white_pony

unread,
Mar 15, 2011, 12:19:04 PM3/15/11
to golang-nuts
Hm, actually I never check it in Windows :) I will try to check when
I get to Windows machine. I am not sure, but can you, please, try to
do:

In Makefile change line:

CGO_LDFLAGS=-lfann -lm

to

CGO_LDFLAGS==-Lc:/msys/1.0/local/lib -lfann -lm

where "c:/msys/1.0/local/lib" absolute path to libfann.


Thanks for response!
> >> leenissen.dk/fann/wp/). You can find it here -https://github.com/white-pony/go-fann

white_pony

unread,
Mar 15, 2011, 12:30:55 PM3/15/11
to golang-nuts
I think it's a nice idea) I am not sure that using goroutines will be
very effective, but it nice thing to try)

Thanks!

sun...@gmail.com

unread,
Mar 16, 2011, 10:46:39 PM3/16/11
to white_pony, golang-nuts
Thanks for your reply. I’ve tried the CGO_LDFLAGS options but it won’t work, the error still go on.
 
Perhaps I shall try it on Linux. 微笑
 
 

wlEmoticon-smile[1].png
Reply all
Reply to author
Forward
0 new messages