How to use exported mlp.cxx function in a separate C program

Hello roottalkers,

I have a simple question about using the mlp
(MultiLayerPercepteron). (Searching the roottalk archives
I confirm that was not asked before.)

I have sucessfully used the template example mlpHiggs in
the ROOT tutorials to obtain and save my own mlp in C++ file:

mlp->Train(ntrain, “text,graph,update=10”);
mlp->Export(“p2e_mpl”,“C++”);

Now, I want to use this saved function p2e_mlp in the different
root program (and , eventually, in a different, compiled
C++ program …)

I am a C++ novice, so you can save me some time in
pointing my mistake (though I should be able, eventually,
to figure it myself ;8-).

So, now I have a root program like


#include "p2e_mlp.C

void dataPEN(){
Double_t params[7];

// calculate params

params[0] = int1;
params[1] = int2;
params[2] = int3;
params[3] = int4;
params[4] = int5;
params[5] = tf_degr;
params[6] = npeaks;
if ( p2e_mlp::value(0,params) > 0.5 ) {
h111->Draw();

}

}

But that is apparently the wrong syntax, or something is not
decleared right … I try several other posibilities like
if ( p2e_mlp(0,params) > 0.5 ) or
if ( p2e_mlp->value(0,params) > 0.5 )

but that also does not work, the error message is, of course,

CINT/ROOT C/C++ Interpreter version 5.16.5, November 30 2005
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
root [0]
Processing dataPEN.C…
run 60730 1
Error: Function value(0,params) is not defined in current scope dataPEN.C:316:
Possible candidates are…
filename line:size busy function type and name
*** Interpreter error recovered *

So, what is a correct syntax for using the saved/exported
mlp file in a separate C++/root program?

                                  Thanks in advance, Emil

P.S. My function p2e_mlp is saved in file p2e_mlp.C

double p2e_mlp::value(int index,double in0,double in1,double in2,double in3,double in4,double in5) {
input0 = (in0 - 0)/1;
input1 = (in1 - 0)/1;
input2 = (in2 - 0)/1;
input3 = (in3 - 0)/1;
input4 = (in4 - 0)/1;
input5 = (in5 - 0)/1;
switch(index) {
case 0:
return ((neuron0xb64e328()*1)+0);
default:
return 0.;
}
}

In a ROOt session, do
root > .L p2e_mpl.C or .L p2e_mpl.C+

and in your analysis script, make an instance of teh class p2e_mpl
before the statement

if ( p2e_mlp::value(0,params) > 0.5 ) {
eg

p2e_mlp mlp; if ( m.value(0,params) > 0.5 ) {

Rene

Thanks, but I still cannot make it work ;8-(

As you explained, in a ROOT session I did:

root > .L p2e_mpl.C and, separately
root > .L p2e_mpl.C+

… that worked and I got the file “p2e_mlp_C.so” in my curent subdirectory.
I also added the library load path in my login script and sourced it.

In my root script I added
p2e_mlp mlp;
if ( mlp.value(0,params) > 0.5 ) {

(I assumeed that you had a typo in your previous replly, namely that
Code:
p2e_mlp mlp;
if ( m.value(0,params) > 0.5 ) {

should have been
Code:
p2e_mlp mlp;
if ( mlp.value(0,params) > 0.5 ) {

Then, try to run the script:

$root
root>.L p2e_mlp.C

root> .x dataPEN.C

I still get an error ;8-(

Processing dataPEN.C…
run 60730 1
Error: Can’t call p2e_mlp::value(0,params) in current scope dataPEN.C:322:
Possible candidates are…
filename line:size busy function type and name (in p2e_mlp)
p2e_mlp.C 4:14 0 public: double value(int index,double in0,double in1,double in2,double in3,double in4,double in5);
Error: Symbol mlp is not defined in current scope dataPEN.C:322:
Error: Failed to evaluate mlp.value(0,params)Possible candidates are…
filename line:size busy function type and name
*** Interpreter error recovered ***

I attach the root script with the data file and the p2e_mlp.C function

                                                                                 Regards, Emil

dataPEN.gtar (1.94 MB)

You forgot to add the file p2e_mlp.h

Anyhow, as the compiler says, your calling sequence to the function “value” is wrong. Instead of
value(index, params);
it should be
value(index, p1,p2,);
Specify as many parameters as you had input variables

Rene

Thanks. You are right. Adding the line

p2e_mlp mlp;

and specifying the list of variables in the function call

mlp.value(index,in0,in1,in2,in3,in4,in5,in6)

makes the working code …
Best Regards, Emil