Discussion:
python bindings: dataset manipulation patch
Ondrej Pacovsky
2008-09-23 16:35:12 UTC
Permalink
Hi,

I have mailed this patch to the original author, but got no response so
far, so I am sending it here, maybe somebody will find it useful and/or
submit it to the CVS :)

In short, it makes fann_{de|}scale_{in|out}put work in python.

-- Ondrej
Thomas Glezakos
2008-09-23 21:27:18 UTC
Permalink
Thank you very much.
I would really like to be able to scale/descale fann training data in python, but so far it didn't seem to work. Since I am a complete newbie in this kind of bindings could you please help me out and tell me how to use your patch? How should I use your code? What should I do to make my system work?

Thanx in advance for your time

Thomas Glezakos

------------------------------------eof-----------------------------------
Subject: [Fann-general] python bindings: dataset manipulation patch
Date: Tuesday, September 23, 2008, 9:35 AM
Hi,
I have mailed this patch to the original author, but got no
response so
far, so I am sending it here, maybe somebody will find it
useful and/or
submit it to the CVS :)
In short, it makes fann_{de|}scale_{in|out}put work in
python.
-- Ondrej
diff -ur ./python/pyfann/fann_cpp_subclass.h
/tmp/fann-2.1.0/python/pyfann/fann_cpp_subclass.h
--- ./python/pyfann/fann_cpp_subclass.h 2008-02-25
12:08:44.000000000 -0800
+++
/tmp/fann-2.1.0/python/pyfann/fann_cpp_subclass.h 2006-03-25
12:00:44.000000000 -0800
@@ -317,38 +317,6 @@
}
- /* Ondrej: This is a quick fix to be able to scale the
input/output vectors
- * of a training set in swigged wrappers (python)
- * the fann_{de|}scale_{in|out}put functions don't
really work as the
- * passed vector argument is copied before passing to
the fann C function
- * and therefore modified sets are not returned back
to python. This hack
- * passes the modified vectors by return value.
- */
-
-/* Macro that calls fnc, copies the results in a newly
created helper_array
- * and retruns it.
- */
-#define XFORMER_HELPER(fnc) \
- helper_array<fann_type>
*fnc(helper_array<fann_type> *input) \
- { \
- if (ann == NULL &&
input->array_len!=ann->num_input) \
- { \
- return NULL; \
- } \
- helper_array<fann_type>* res= new
helper_array<fann_type>; \
- res->array= input->array; \
- fann_ ## fnc (ann, input->array); \
- res->array_len=input->array_len; \
- res->can_delete=false; \
- return res; \
- }
-
- XFORMER_HELPER(scale_input)
- XFORMER_HELPER(descale_input)
- XFORMER_HELPER(scale_output)
- XFORMER_HELPER(descale_output)
-#undef XFORMER_HELPER
-
#ifndef FIXEDFANN
/* Method: train
diff -ur ./src/include/fann_train.h
/tmp/fann-2.1.0/src/include/fann_train.h
--- ./src/include/fann_train.h 2008-02-27
11:13:04.568522000 -0800
+++ /tmp/fann-2.1.0/src/include/fann_train.h 2006-09-13
22:02:06.000000000 -0700
@@ -413,10 +413,6 @@
*/
FANN_EXTERNAL int FANN_API
fann_clear_scaling_params(struct fann *ann);
-
-// the scaling functions for SWIG are replaced by those in
fann_cpp_subclass.h
-#ifndef SWIG
-
/* Function: fann_scale_input
Scale data in input vector before feed it to ann based
on previously calculated parameters.
@@ -430,8 +426,8 @@
This function appears in FANN >= 2.1.0
*/
-
FANN_EXTERNAL void FANN_API fann_scale_input( struct fann
*ann, fann_type *input_vector );
+
/* Function: fann_scale_output
Scale data in output vector before feed it to ann based
on previously calculated parameters.
@@ -477,8 +473,6 @@
*/
FANN_EXTERNAL void FANN_API fann_descale_output( struct
fann *ann, fann_type *output_vector );
-#endif // SWIG
-
#endif
/* Function: fann_scale_input_train_data
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move
Developer's challenge
Build the coolest Linux based applications with Moblin SDK
& win great prizes
Grand prize is a trip for two to an Open Source event
anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/_______________________________________________
Fann-general mailing list
https://lists.sourceforge.net/lists/listinfo/fann-general
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
Ondrej Pacovsky
2008-09-24 06:57:44 UTC
Permalink
Thomas,

first tell me how far can you get alone: do you know how to use the
patch utility ? Can you compile the fann + python extension ?

-- Ondrej
Post by Thomas Glezakos
Thank you very much.
I would really like to be able to scale/descale fann training data in python, but so far it didn't seem to work. Since I am a complete newbie in this kind of bindings could you please help me out and tell me how to use your patch? How should I use your code? What should I do to make my system work?
Thanx in advance for your time
Thomas Glezakos
------------------------------------eof-----------------------------------
Subject: [Fann-general] python bindings: dataset manipulation patch
Date: Tuesday, September 23, 2008, 9:35 AM
Hi,
I have mailed this patch to the original author, but got no
response so
far, so I am sending it here, maybe somebody will find it
useful and/or
submit it to the CVS :)
In short, it makes fann_{de|}scale_{in|out}put work in
python.
-- Ondrej
diff -ur ./python/pyfann/fann_cpp_subclass.h
/tmp/fann-2.1.0/python/pyfann/fann_cpp_subclass.h
--- ./python/pyfann/fann_cpp_subclass.h 2008-02-25
12:08:44.000000000 -0800
+++
/tmp/fann-2.1.0/python/pyfann/fann_cpp_subclass.h 2006-03-25
12:00:44.000000000 -0800
@@ -317,38 +317,6 @@
}
- /* Ondrej: This is a quick fix to be able to scale the
input/output vectors
- * of a training set in swigged wrappers (python)
- * the fann_{de|}scale_{in|out}put functions don't
really work as the
- * passed vector argument is copied before passing to
the fann C function
- * and therefore modified sets are not returned back
to python. This hack
- * passes the modified vectors by return value.
- */
-
-/* Macro that calls fnc, copies the results in a newly
created helper_array
- * and retruns it.
- */
-#define XFORMER_HELPER(fnc) \
- helper_array<fann_type>
*fnc(helper_array<fann_type> *input) \
- { \
- if (ann == NULL &&
input->array_len!=ann->num_input) \
- { \
- return NULL; \
- } \
- helper_array<fann_type>* res= new
helper_array<fann_type>; \
- res->array= input->array; \
- fann_ ## fnc (ann, input->array); \
- res->array_len=input->array_len; \
- res->can_delete=false; \
- return res; \
- }
-
- XFORMER_HELPER(scale_input)
- XFORMER_HELPER(descale_input)
- XFORMER_HELPER(scale_output)
- XFORMER_HELPER(descale_output)
-#undef XFORMER_HELPER
-
#ifndef FIXEDFANN
/* Method: train
diff -ur ./src/include/fann_train.h
/tmp/fann-2.1.0/src/include/fann_train.h
--- ./src/include/fann_train.h 2008-02-27
11:13:04.568522000 -0800
+++ /tmp/fann-2.1.0/src/include/fann_train.h 2006-09-13
22:02:06.000000000 -0700
@@ -413,10 +413,6 @@
*/
FANN_EXTERNAL int FANN_API
fann_clear_scaling_params(struct fann *ann);
-
-// the scaling functions for SWIG are replaced by those in
fann_cpp_subclass.h
-#ifndef SWIG
-
/* Function: fann_scale_input
Scale data in input vector before feed it to ann based
on previously calculated parameters.
@@ -430,8 +426,8 @@
This function appears in FANN >= 2.1.0
*/
-
FANN_EXTERNAL void FANN_API fann_scale_input( struct fann
*ann, fann_type *input_vector );
+
/* Function: fann_scale_output
Scale data in output vector before feed it to ann based
on previously calculated parameters.
@@ -477,8 +473,6 @@
*/
FANN_EXTERNAL void FANN_API fann_descale_output( struct
fann *ann, fann_type *output_vector );
-#endif // SWIG
-
#endif
/* Function: fann_scale_input_train_data
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move
Developer's challenge
Build the coolest Linux based applications with Moblin SDK
& win great prizes
Grand prize is a trip for two to an Open Source event
anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/_______________________________________________
Fann-general mailing list
https://lists.sourceforge.net/lists/listinfo/fann-general
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Fann-general mailing list
https://lists.sourceforge.net/lists/listinfo/fann-general
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/

Loading...