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
4f02d77d
Commit
4f02d77d
authored
6 years ago
by
Nikolai.Hartmann
Browse files
Options
Downloads
Patches
Plain Diff
adding functionality to mask values in random events
parent
9430ad7c
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
toolkit.py
+16
-0
16 additions, 0 deletions
toolkit.py
utils.py
+9
-2
9 additions, 2 deletions
utils.py
with
25 additions
and
2 deletions
toolkit.py
+
16
−
0
View file @
4f02d77d
...
@@ -1710,6 +1710,22 @@ class ClassificationProjectRNN(ClassificationProject):
...
@@ -1710,6 +1710,22 @@ class ClassificationProjectRNN(ClassificationProject):
self
.
checkpoint_model
()
self
.
checkpoint_model
()
def
clean_mask
(
self
,
x
):
"""
Mask recurrent fields such that once a masked value occurs,
all values corresponding to the same and following objects are
masked as well. Works in place.
"""
for
recurrent_field_idx
in
self
.
recurrent_field_idx
:
for
evt
in
x
:
masked
=
False
for
line_idx
in
recurrent_field_idx
.
reshape
(
*
recurrent_field_idx
.
shape
[
1
:]):
if
(
evt
[
line_idx
]
==
self
.
mask_value
).
any
():
masked
=
True
if
masked
:
evt
[
line_idx
]
=
self
.
mask_value
def
get_input_list
(
self
,
x
):
def
get_input_list
(
self
,
x
):
"
Format the input starting from flat ntuple
"
"
Format the input starting from flat ntuple
"
x_input
=
[]
x_input
=
[]
...
...
This diff is collapsed.
Click to expand it.
utils.py
+
9
−
2
View file @
4f02d77d
...
@@ -33,22 +33,29 @@ def get_single_neuron_function(model, layer, neuron, input_transform=None):
...
@@ -33,22 +33,29 @@ def get_single_neuron_function(model, layer, neuron, input_transform=None):
return
eval_single_neuron
return
eval_single_neuron
def
create_random_event
(
ranges
):
def
create_random_event
(
ranges
,
mask_probs
=
None
,
mask_value
=
None
):
random_event
=
np
.
array
([
p
[
0
]
+
(
p
[
1
]
-
p
[
0
])
*
np
.
random
.
rand
()
for
p
in
ranges
])
random_event
=
np
.
array
([
p
[
0
]
+
(
p
[
1
]
-
p
[
0
])
*
np
.
random
.
rand
()
for
p
in
ranges
])
random_event
=
random_event
.
reshape
(
-
1
,
len
(
random_event
))
random_event
=
random_event
.
reshape
(
-
1
,
len
(
random_event
))
# if given, mask values with a certain probability
if
mask_probs
is
not
None
:
for
var_index
,
mask_prob
in
enumerate
(
mask_probs
):
random_event
[:,
var_index
][
np
.
random
.
rand
(
len
(
random_event
))
<
mask_prob
]
=
mask_value
return
random_event
return
random_event
def
get_ranges
(
x
,
quantiles
,
weights
,
mask_value
=
None
,
filter_index
=
None
):
def
get_ranges
(
x
,
quantiles
,
weights
,
mask_value
=
None
,
filter_index
=
None
):
"
Get ranges for plotting or random event generation based on quantiles
"
"
Get ranges for plotting or random event generation based on quantiles
"
ranges
=
[]
ranges
=
[]
mask_probs
=
[]
for
var_index
in
range
(
x
.
shape
[
1
]):
for
var_index
in
range
(
x
.
shape
[
1
]):
if
(
filter_index
is
not
None
)
and
(
var_index
!=
filter_index
):
if
(
filter_index
is
not
None
)
and
(
var_index
!=
filter_index
):
continue
continue
x_var
=
x
[:,
var_index
]
x_var
=
x
[:,
var_index
]
not_masked
=
np
.
where
(
x_var
!=
mask_value
)[
0
]
not_masked
=
np
.
where
(
x_var
!=
mask_value
)[
0
]
masked
=
np
.
where
(
x_var
==
mask_value
)[
0
]
ranges
.
append
(
weighted_quantile
(
x_var
[
not_masked
],
quantiles
,
sample_weight
=
weights
[
not_masked
]))
ranges
.
append
(
weighted_quantile
(
x_var
[
not_masked
],
quantiles
,
sample_weight
=
weights
[
not_masked
]))
return
ranges
mask_probs
.
append
(
float
(
len
(
masked
))
/
float
(
len
(
x_var
)))
return
ranges
,
mask_probs
def
max_activation_wrt_input
(
gradient_function
,
random_event
,
threshold
=
None
,
maxthreshold
=
None
,
maxit
=
100
,
step
=
1
,
const_indices
=
[],
def
max_activation_wrt_input
(
gradient_function
,
random_event
,
threshold
=
None
,
maxthreshold
=
None
,
maxit
=
100
,
step
=
1
,
const_indices
=
[],
...
...
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