Discussion:
Training Style
Chris Spencer
2007-02-02 16:44:17 UTC
Permalink
All the examples I've seen for training a FANN network use
train_on_file(), which seems somewhat awkward to me. In my app I
generate a lot of training sets dynamically. How can I give this data
directly to FANN instead of first writing it to a file? I see a
fann_train_on_data() but I can't find any examples of it's use,
particularly through pyfann.

I've also heavily used Pyrobot's Conx module, which let's you train or
propagate a network by simply saying something like:

net.step(fruitType='apple', fruitAge='new', color='red')

where separate input layers have been mapped to the 'fruitType' and
'fruitAge' labels, the output layer has been labeled 'color', and the
strings 'apple', 'new', and 'red' have been mapped to lists of numeric
inputs like [1,0,0]. Does FANN have any features similar to this?

Regards,
Chris

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
George Dahl
2007-02-02 17:03:24 UTC
Permalink
Last time I looked at FANN there was not a convenient way to do create
FANN data that isn't in a file. I wrote some code to do it when I was
doing some experiments with parallelizing FANN over a cluster of
workstations. The code below is basically the same as the read from
file code but it takes arrays and makes them into a training data
struct. One thing with this code is, I was working in a version of
FANN where I had forced fann_type to be double. If you want to make
this general, you will have to put back in the fann_types. Or write
your own and use this code as a reference. That might be best.

Also, I am one of the programmers who worked on Conx. I am glad you
like it. I worked on the Cascade-correlation code. I don't think
FANN has any way to do the string thing like that. But that is
probably much less important than making training data on dynamically
and creating a training data struct. Below I have pasted the code I
wrote. Like I said, you should probably rewrite it to use fann_type
correctly instead of double.

struct fann_train_data *read_from_array(double *din, double *dout,
unsigned int num_data,
unsigned int num_input, unsigned int num_output) {
unsigned int i, j;
fann_type *data_input, *data_output;
struct fann_train_data *data =
(struct fann_train_data *) malloc(sizeof(struct fann_train_data));
if(data == NULL) {
fann_error(NULL, FANN_E_CANT_ALLOCATE_MEM);
return NULL;
}

fann_init_error_data((struct fann_error *) data);

data->num_data = num_data;
data->num_input = num_input;
data->num_output = num_output;
data->input = (double **) calloc(num_data, sizeof(double *));
if(data->input == NULL) {
fann_error(NULL, FANN_E_CANT_ALLOCATE_MEM);
fann_destroy_train(data);
return NULL;
}

data->output = (double **) calloc(num_data, sizeof(double *));
if(data->output == NULL) {
fann_error(NULL, FANN_E_CANT_ALLOCATE_MEM);
fann_destroy_train(data);
return NULL;
}

data_input = (double *) calloc(num_input * num_data, sizeof(double));
if(data_input == NULL) {
fann_error(NULL, FANN_E_CANT_ALLOCATE_MEM);
fann_destroy_train(data);
return NULL;
}

data_output = (double *) calloc(num_output * num_data, sizeof(double));
if(data_output == NULL) {
fann_error(NULL, FANN_E_CANT_ALLOCATE_MEM);
fann_destroy_train(data);
return NULL;
}
for(i = 0; i != num_data; i++) {
data->input[i] = data_input;
data_input += num_input;

for(j = 0; j != num_input; j++) {
data->input[i][j] = din[i*num_input+j];
}


data->output[i] = data_output;
data_output += num_output;

for(j = 0; j != num_output; j++) {
data->output[i][j] = dout[i*num_output+j];
}
}
return data;
}



- George
Post by Chris Spencer
All the examples I've seen for training a FANN network use
train_on_file(), which seems somewhat awkward to me. In my app I
generate a lot of training sets dynamically. How can I give this data
directly to FANN instead of first writing it to a file? I see a
fann_train_on_data() but I can't find any examples of it's use,
particularly through pyfann.
I've also heavily used Pyrobot's Conx module, which let's you train or
net.step(fruitType='apple', fruitAge='new', color='red')
where separate input layers have been mapped to the 'fruitType' and
'fruitAge' labels, the output layer has been labeled 'color', and the
strings 'apple', 'new', and 'red' have been mapped to lists of numeric
inputs like [1,0,0]. Does FANN have any features similar to this?
Regards,
Chris
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Fann-general mailing list
https://lists.sourceforge.net/lists/listinfo/fann-general
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
Chris Spencer
2007-02-02 17:26:42 UTC
Permalink
Post by George Dahl
Last time I looked at FANN there was not a convenient way to do create
FANN data that isn't in a file. I wrote some code to do it when I was
doing some experiments with parallelizing FANN over a cluster of
workstations. The code below is basically the same as the read from
file code but it takes arrays and makes them into a training data
struct. One thing with this code is, I was working in a version of
FANN where I had forced fann_type to be double. If you want to make
this general, you will have to put back in the fann_types. Or write
your own and use this code as a reference. That might be best.
Also, I am one of the programmers who worked on Conx. I am glad you
like it. I worked on the Cascade-correlation code. I don't think
FANN has any way to do the string thing like that. But that is
probably much less important than making training data on dynamically
and creating a training data struct. Below I have pasted the code I
wrote. Like I said, you should probably rewrite it to use fann_type
correctly instead of double.
Thanks, but I'm trying to restrict myself to Pyfann, so I'd like to
avoid having to maintain a custom patch to the C code. Is there any
way to at least read a tmpfile from memory, by passing FANN a pipe or
something? I'm researching RL techniques that do a lot of training
sequences on just a single (input,target) pair at a time. It's really
going to hurt performance if I have to write everything to disk.

Regards,
Chris

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
Chris Spencer
2007-02-02 17:47:49 UTC
Permalink
Post by Chris Spencer
Thanks, but I'm trying to restrict myself to Pyfann, so I'd like to
avoid having to maintain a custom patch to the C code. Is there any
way to at least read a tmpfile from memory, by passing FANN a pipe or
something? I'm researching RL techniques that do a lot of training
sequences on just a single (input,target) pair at a time. It's really
going to hurt performance if I have to write everything to disk.
Just realized that the incremental train() method is exactly what I
need. Nevermind my previous rant :)

Regards,
Chris

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
Loading...