Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
KerasROOTClassification
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nikolai.Hartmann
KerasROOTClassification
Commits
2d359986
Commit
2d359986
authored
6 years ago
by
Nikolai.Hartmann
Browse files
Options
Downloads
Patches
Plain Diff
Adding significance scan function
parent
50d0a2a6
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
toolkit.py
+41
-0
41 additions, 0 deletions
toolkit.py
with
41 additions
and
0 deletions
toolkit.py
+
41
−
0
View file @
2d359986
...
...
@@ -877,6 +877,47 @@ class ClassificationProject(object):
fig
.
savefig
(
os
.
path
.
join
(
self
.
project_dir
,
"
scores.pdf
"
))
def
plot_significance
(
self
,
lumifactor
=
1.
,
significanceFunction
=
None
):
plot_opts
=
dict
(
bins
=
50
,
range
=
(
0
,
1
))
centers_sig_train
,
hist_sig_train
,
rel_errors_sig_train
=
self
.
get_bin_centered_hist
(
self
.
scores_train
[
self
.
y_train
==
1
].
reshape
(
-
1
),
weights
=
self
.
w_train
[
self
.
y_train
==
1
],
**
plot_opts
)
centers_bkg_train
,
hist_bkg_train
,
rel_errors_bkg_train
=
self
.
get_bin_centered_hist
(
self
.
scores_train
[
self
.
y_train
==
0
].
reshape
(
-
1
),
weights
=
self
.
w_train
[
self
.
y_train
==
0
],
**
plot_opts
)
centers_sig_test
,
hist_sig_test
,
rel_errors_sig_test
=
self
.
get_bin_centered_hist
(
self
.
scores_test
[
self
.
y_test
==
1
].
reshape
(
-
1
),
weights
=
self
.
w_test
[
self
.
y_test
==
1
],
**
plot_opts
)
centers_bkg_test
,
hist_bkg_test
,
rel_errors_bkg_test
=
self
.
get_bin_centered_hist
(
self
.
scores_test
[
self
.
y_test
==
0
].
reshape
(
-
1
),
weights
=
self
.
w_test
[
self
.
y_test
==
0
],
**
plot_opts
)
significances_train
=
[]
significances_test
=
[]
for
hist_sig
,
hist_bkg
,
rel_errors_sig
,
rel_errors_bkg
,
significances
in
[
(
hist_sig_train
,
hist_bkg_train
,
rel_errors_bkg_train
,
rel_errors_sig_train
,
significances_train
),
(
hist_sig_test
,
hist_bkg_test
,
rel_errors_bkg_test
,
rel_errors_sig_test
,
significances_test
),
]:
# first set nan values to 0 and multiply by lumi
for
arr
in
hist_sig
,
hist_bkg
,
rel_errors_bkg
:
arr
[
np
.
isnan
(
arr
)]
=
0
hist_sig
*=
lumifactor
hist_bkg
*=
lumifactor
for
i
in
range
(
len
(
hist_sig
)):
s
=
sum
(
hist_sig
[
i
:])
b
=
sum
(
hist_bkg
[
i
:])
db
=
math
.
sqrt
(
sum
((
rel_errors_bkg
[
i
:]
*
hist_bkg
[
i
:])
**
2
))
if
significanceFunction
is
None
:
try
:
z
=
s
/
math
.
sqrt
(
b
+
db
**
2
)
except
(
ZeroDivisionError
,
ValueError
)
as
e
:
z
=
0
else
:
z
=
significanceFunction
(
s
,
b
,
db
)
logger
.
debug
(
"
s, b, db, z = {}, {}, {}, {}
"
.
format
(
s
,
b
,
db
,
z
))
significances
.
append
(
z
)
fig
,
ax
=
plt
.
subplots
()
width
=
centers_sig_train
[
1
]
-
centers_sig_train
[
0
]
ax
.
plot
(
centers_bkg_train
,
significances_train
,
label
=
"
train
"
)
ax
.
plot
(
centers_bkg_test
,
significances_test
,
label
=
"
test
"
)
ax
.
set_xlabel
(
"
Cut on NN score
"
)
ax
.
set_ylabel
(
"
Significance
"
)
ax
.
legend
(
loc
=
'
lower center
'
,
framealpha
=
0.5
)
fig
.
savefig
(
os
.
path
.
join
(
self
.
project_dir
,
"
significances.pdf
"
))
@property
def
csv_hist
(
self
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment