Skip to main content
GameDev.net gamedev.net
🔒 Locked

FANN problem

Started by Programistagd Feb 3, 2011 at 8:37 PM 2 replies 3.6k views
Original Post
Programistagd
Programistagd
Hello!
I'm new to this forum, but I'm good at programming(C++,Java,AS3).
I have to write a ANN for some program(my deadline is on Tuesday).
I want to use the FANN library.
I'm writing in C++ in Code::Blocks.
I'm using example code:
/*
Fast Artificial Neural Network Library (fann)
Copyright (C) 2003 Steffen Nissen (lukesky@diku.dk)

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

#include <stdio.h>

#include "fann.h"

int FANN_API test_callback(struct fann *ann, struct fann_train_data *train,
unsigned int max_epochs, unsigned int epochs_between_reports,
float desired_error, unsigned int epochs)
{
printf("Epochs %8d. MSE: %.5f. Desired-MSE: %.5f\n", epochs, fann_get_MSE(ann), desired_error);
return 0;
}

int main()
{
fann_type *calc_out;
const unsigned int num_input = 2;
const unsigned int num_output = 1;
const unsigned int num_layers = 3;
const unsigned int num_neurons_hidden = 3;
const float desired_error = (const float) 0;
const unsigned int max_epochs = 1000;
const unsigned int epochs_between_reports = 10;
struct fann *ann;
struct fann_train_data *data;

unsigned int i = 0;
unsigned int decimal_point;

printf("Creating network.\n");
ann = fann_create_standard(num_layers, num_input, num_neurons_hidden, num_output);

data = fann_read_train_from_file("xor.data");

fann_set_activation_steepness_hidden(ann, 1);
fann_set_activation_steepness_output(ann, 1);

fann_set_activation_function_hidden(ann, FANN_SIGMOID_SYMMETRIC);
fann_set_activation_function_output(ann, FANN_SIGMOID_SYMMETRIC);

fann_set_train_stop_function(ann, FANN_STOPFUNC_BIT);
fann_set_bit_fail_limit(ann, 0.01f);

fann_init_weights(ann, data);

printf("Training network.\n");
fann_train_on_data(ann, data, max_epochs, epochs_between_reports, desired_error);

printf("Testing network. %f\n", fann_test_data(ann, data));

for(i = 0; i < fann_length_train_data(data); i++)
{
calc_out = fann_run(ann, data->input);
printf("XOR test (%f,%f) -> %f, should be %f, difference=%f\n",
data->input[0], data->input[1], calc_out[0], data->output[0],
fann_abs(calc_out[0] - data->output[0]));
}

printf("Saving network.\n");

fann_save(ann, "xor_float.net");

decimal_point = fann_save_to_fixed(ann, "xor_fixed.net");
fann_save_train_to_fixed(data, "xor_fixed.data", decimal_point);

printf("Cleaning up.\n");
fann_destroy_train(data);
fann_destroy(ann);

return 0;
}


But it doesn't works...
I get this:
obj\Debug\fann-win-dll-2.0.0(1)\fann-2.0.0\src\include\fann.o||In function `_Z13test_callbackP4fannP15fann_train_datajjfj':|
E:\projekty\Neurony+GSMama\fann-win-dll-2.0.0(1)\fann-2.0.0\src\include\fann.cpp|28|undefined reference to `_fann_get_MSE'|
obj\Debug\fann-win-dll-2.0.0(1)\fann-2.0.0\src\include\fann.o||In function `main':|
E:\projekty\Neurony+GSMama\fann-win-dll-2.0.0(1)\fann-2.0.0\src\include\fann.cpp|51|undefined reference to `_fann_read_train_from_file'|
E:\projekty\Neurony+GSMama\fann-win-dll-2.0.0(1)\fann-2.0.0\src\include\fann.cpp|53|undefined reference to `_fann_set_activation_steepness_hidden'|
E:\projekty\Neurony+GSMama\fann-win-dll-2.0.0(1)\fann-2.0.0\src\include\fann.cpp|54|undefined reference to `_fann_set_activation_steepness_output'|
E:\projekty\Neurony+GSMama\fann-win-dll-2.0.0(1)\fann-2.0.0\src\include\fann.cpp|56|undefined reference to `_fann_set_activation_function_hidden'|
E:\projekty\Neurony+GSMama\fann-win-dll-2.0.0(1)\fann-2.0.0\src\include\fann.cpp|57|undefined reference to `_fann_set_activation_function_output'|
E:\projekty\Neurony+GSMama\fann-win-dll-2.0.0(1)\fann-2.0.0\src\include\fann.cpp|59|undefined reference to `_fann_set_train_stop_function'|
E:\projekty\Neurony+GSMama\fann-win-dll-2.0.0(1)\fann-2.0.0\src\include\fann.cpp|60|undefined reference to `_fann_set_bit_fail_limit'|
E:\projekty\Neurony+GSMama\fann-win-dll-2.0.0(1)\fann-2.0.0\src\include\fann.cpp|62|undefined reference to `_fann_init_weights'|
E:\projekty\Neurony+GSMama\fann-win-dll-2.0.0(1)\fann-2.0.0\src\include\fann.cpp|65|undefined reference to `_fann_train_on_data'|
E:\projekty\Neurony+GSMama\fann-win-dll-2.0.0(1)\fann-2.0.0\src\include\fann.cpp|67|undefined reference to `_fann_test_data'|
E:\projekty\Neurony+GSMama\fann-win-dll-2.0.0(1)\fann-2.0.0\src\include\fann.cpp|69|undefined reference to `_fann_length_train_data'|
E:\projekty\Neurony+GSMama\fann-win-dll-2.0.0(1)\fann-2.0.0\src\include\fann.cpp|71|undefined reference to `_fann_run'|
E:\projekty\Neurony+GSMama\fann-win-dll-2.0.0(1)\fann-2.0.0\src\include\fann.cpp|79|undefined reference to `_fann_save'|
E:\projekty\Neurony+GSMama\fann-win-dll-2.0.0(1)\fann-2.0.0\src\include\fann.cpp|81|undefined reference to `_fann_save_to_fixed'|
E:\projekty\Neurony+GSMama\fann-win-dll-2.0.0(1)\fann-2.0.0\src\include\fann.cpp|82|undefined reference to `_fann_save_train_to_fixed'|
E:\projekty\Neurony+GSMama\fann-win-dll-2.0.0(1)\fann-2.0.0\src\include\fann.cpp|85|undefined reference to `_fann_destroy_train'|
E:\projekty\Neurony+GSMama\fann-win-dll-2.0.0(1)\fann-2.0.0\src\include\fann.cpp|86|undefined reference to `_fann_destroy'|
||=== Build finished: 18 errors, 0 warnings ===|


I'm linking(or not - I tested both options and got the same result) fannfloat.lib.
In my working directory there are fannfloat(/doubla/fixed).dll, but they aren't used in linking I think...
I don't know what to do.
I also tried to write(before includes) #define FANN_USE_DLL and also FANN_NO_DLL.
So, what to do and set in SDK to compile it?
Maybe there are other solutions. What?
If you know other easy libraries please also tell me.
Thank you in advance.
Regerds, Programistagd.
willh
willh
It sounds like fann.cpp is missing a header.

Is this for school? Are you trying to learn about ANNs? If so, why not write your own?
IADaveMark
IADaveMark
I'm going to go out on a limb and say that the problem detailed above is not an AI problem but rather one of general programming. Therefore, I'm moving this particular thread to that forum. However, if you have a more AI specific question such as about ANN libraries, start a new, uncluttered thread back in the AI forum.
Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit<
Programistagd
Programistagd
I'm not doing it for school.
Yes, I want to learn ANN, but now I have deadline on Tuesday and I don't have much time.
I'll try to write my own class, but for this I need something that would be done quickly - because of the deadline.
@willh: Doi I need to compile also fann.cpp?
I compile only my main.cpp(listed before) and link the lib or use DLL.
So do I need to compile something else?
Thank you in advance.
I'll also try to write my own ANN class and I think that I share it with you, because I think that not onle I would like a header-only ANN lib.
Regards, Programistagd.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.