Skip to content

[TMVA] Fix for using integer spectator types in Reader class#9513

Merged
lmoneta merged 3 commits intoroot-project:masterfrom
lmoneta:fix_tmva_spectators_int
Feb 2, 2022
Merged

[TMVA] Fix for using integer spectator types in Reader class#9513
lmoneta merged 3 commits intoroot-project:masterfrom
lmoneta:fix_tmva_spectators_int

Conversation

@lmoneta
Copy link
Copy Markdown
Member

@lmoneta lmoneta commented Jan 7, 2022

TMVA::Reader::AddSpectator allows passing an integer external pointer, but the event class stores only float * pointer.

This PR adds in the Event class the type information of the spectator variables. With this the correct casting is performed when retrieving the spectator variable value in case of dynamic events (the inputs are provided using an external pointer)

Note that the integer is always converted to a float, so one can use integer values only from [-2^24, 2^24].

This PR fixes #9115

@phsft-bot
Copy link
Copy Markdown

Starting build on ROOT-debian10-i386/cxx14, ROOT-performance-centos8-multicore/default, ROOT-ubuntu16/nortcxxmod, ROOT-ubuntu2004/soversion, mac1015/python3, mac11/cxx17, windows10/cxx14
How to customize builds

TMVA::Reader::AddSpectator allows passing an integer external pointer, but the event class stores only float * pointer.

Now add in Event class the type information of the spectator variables and the correct casting is performed when retrieving the spectator variable value

Note that the integer is always converted to a float, so one can use integer values only from -[2^24, 2^24].

This fixes root-project#9115
…for the spectator's.

This test will fail in current master but it passes with the PR root-project#9513
@lmoneta lmoneta force-pushed the fix_tmva_spectators_int branch from 21a9a31 to cac9566 Compare January 28, 2022 09:58
@lmoneta lmoneta requested a review from bellenot as a code owner January 28, 2022 09:58
@phsft-bot
Copy link
Copy Markdown

Starting build on ROOT-debian10-i386/cxx14, ROOT-performance-centos8-multicore/default, ROOT-ubuntu16/nortcxxmod, ROOT-ubuntu2004/soversion, mac1015/python3, mac11/cxx17, windows10/cxx14
How to customize builds

@lmoneta
Copy link
Copy Markdown
Member Author

lmoneta commented Jan 28, 2022

Added a new test for checking that the issue is fixed!

Copy link
Copy Markdown
Member

@Axel-Naumann Axel-Naumann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test looks complex for something that fundamental. Is there no way to load an existing BDT, also to save test time? How much is the running time of this - if it's < 1 second then whatever, but if it's longer just to check whether int and float spectators then maybe we can improve that?

Comment on lines +178 to +182
std::vector<char> spectatorTypes;
for (; it != spectatorinfos.end(); ++it) {
evdyn->push_back( (Float_t*)(*it).GetExternalLink() );
spectatorTypes.push_back(it->GetVarType());
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
std::vector<char> spectatorTypes;
for (; it != spectatorinfos.end(); ++it) {
evdyn->push_back( (Float_t*)(*it).GetExternalLink() );
spectatorTypes.push_back(it->GetVarType());
}
std::vector<char> spectatorTypes;
spectatorTypes.reserve(spectatorinfos.size());
for (auto &&info: spectatorinfos) {
evdyn->push_back( (Float_t*)info.GetExternalLink() );
spectatorTypes.push_back(info.GetVarType());
}


// AccessPathName() == kFALSE means file exits
ASSERT_FALSE(gSystem->AccessPathName(weightPath.c_str())) << "Method was"
<< " not serialised correctly. Path: '" << weightPath << "' does not"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<< " not serialised correctly. Path: '" << weightPath << "' does not"
<< " not serialized correctly. Path: '" << weightPath << "' does not"

Comment on lines +171 to +174


output[ievt] = reader.EvaluateMVA("BDT1");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
output[ievt] = reader.EvaluateMVA("BDT1");
output[ievt] = reader.EvaluateMVA("BDT1");

@lmoneta
Copy link
Copy Markdown
Member Author

lmoneta commented Feb 2, 2022

Thank you Axel for the review comments ! I will include them.
The test is around 1 second, less on my machine. We need to train first the BDT in order to create the XML file. It is true we could create the model externally, store in a file on GitHub, but for self-consistency it is better to have the full procedure, since the time to create and train the model is fast.

@phsft-bot
Copy link
Copy Markdown

Starting build on ROOT-debian10-i386/cxx14, ROOT-performance-centos8-multicore/default, ROOT-ubuntu16/nortcxxmod, ROOT-ubuntu2004/soversion, mac1015/python3, mac11/cxx17, windows10/cxx14
How to customize builds

@phsft-bot
Copy link
Copy Markdown

Build failed on ROOT-debian10-i386/cxx14.
See console output.

@phsft-bot
Copy link
Copy Markdown

Build failed on ROOT-performance-centos8-multicore/default.
See console output.

@phsft-bot
Copy link
Copy Markdown

Build failed on mac11/cxx17.
See console output.

@phsft-bot
Copy link
Copy Markdown

Build failed on windows10/cxx14.
See console output.

@phsft-bot
Copy link
Copy Markdown

Build failed on ROOT-ubuntu16/nortcxxmod.
See console output.

@phsft-bot
Copy link
Copy Markdown

Build failed on ROOT-ubuntu2004/soversion.
See console output.

@phsft-bot
Copy link
Copy Markdown

Build failed on mac1015/python3.
See console output.

@lmoneta lmoneta merged commit 0640942 into root-project:master Feb 2, 2022
lmoneta added a commit that referenced this pull request Feb 2, 2022
…for the spectator's.

This test will fail in current master but it passes with the PR #9513
@lmoneta lmoneta deleted the fix_tmva_spectators_int branch February 2, 2022 15:33
lmoneta added a commit to lmoneta/root that referenced this pull request Feb 3, 2022
TMVA::Reader::AddSpectator allows passing an integer external pointer, but the event class stores only float * pointer.

Now add in Event class the type information of the spectator variables and the correct casting is performed when retrieving the spectator variable value

Note that the integer is always converted to a float, so one can use integer values only from -[2^24, 2^24].

This fixes root-project#9115

Add a test for checking using an integer variable in the TMVA Reader for the spectator's.
This test will fail in current master but it passes with the PR root-project#9513

Implement review comments
lmoneta added a commit that referenced this pull request Feb 4, 2022
TMVA::Reader::AddSpectator allows passing an integer external pointer, but the event class stores only float * pointer.

Now add in Event class the type information of the spectator variables and the correct casting is performed when retrieving the spectator variable value

Note that the integer is always converted to a float, so one can use integer values only from -[2^24, 2^24].

This fixes #9115

Add a test for checking using an integer variable in the TMVA Reader for the spectator's.
This test will fail in current master but it passes with the PR #9513

Implement review comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Spectator type in TMVACrossValidationApplication

3 participants