Skip to content
Snippets Groups Projects
Commit a95d7482 authored by Nikolai's avatar Nikolai
Browse files

profile histogram plot

parent b9f44b75
No related branches found
No related tags found
No related merge requests found
...@@ -273,117 +273,198 @@ def plot_cond_avg_actmax_2D(plotname, model, layer, neuron, ranges, ...@@ -273,117 +273,198 @@ def plot_cond_avg_actmax_2D(plotname, model, layer, neuron, ranges,
plot_hist_2D(plotname, xedges, yedges, hist, zlabel="Neuron output", **kwargs) plot_hist_2D(plotname, xedges, yedges, hist, zlabel="Neuron output", **kwargs)
def plot_profile_2D(plotname, valsx, valsy, scores,
nbinsx, xmin, xmax,
nbinsy, ymin, ymax,
metric=np.mean,
**kwargs):
kwargs["zlabel"] = kwargs.get("zlabel", "Profile")
if __name__ == "__main__": xedges = np.linspace(xmin, xmax, nbinsx)
yedges = np.linspace(ymin, ymax, nbinsy)
from .toolkit import ClassificationProject
c = ClassificationProject(os.path.expanduser("~/p/scripts/keras/008-allhighlevel/all_highlevel_985")) binindices_x = np.digitize(valsx, xedges)
binindices_y = np.digitize(valsy, yedges)
mean_signal = get_mean_event(c.x_test, c.y_test, 1) # create profile histogram
hist = []
for binindex_x in range(1, len(xedges)+1):
line = []
for binindex_y in range(1, len(xedges)+1):
try:
prof_score = metric(scores[(binindices_x == binindex_x) & (binindices_y == binindex_y)])
except ValueError:
prof_score = 0
line.append(prof_score)
hist.append(line)
hist = np.array(hist)
print("Mean signal: ") plot_hist_2D(plotname, xedges, yedges, hist, **kwargs)
for branch_index, val in enumerate(mean_signal):
print("{:>20}: {:<10.3f}".format(c.branches[branch_index], val))
plot_NN_vs_var_1D("met.pdf", mean_signal,
scorefun=c.evaluate,
var_index=c.branches.index("met"),
var_range=(0, 1000, 10),
var_label="met [GeV]")
plot_NN_vs_var_1D("mt.pdf", mean_signal, if __name__ == "__main__":
scorefun=c.evaluate,
var_index=c.branches.index("mt"),
var_range=(0, 500, 10),
var_label="mt [GeV]")
plot_NN_vs_var_2D("mt_vs_met.pdf", means=mean_signal, import sys
scorefun=c.evaluate,
var1_index=c.branches.index("met"), var1_range=(0, 1000, 10),
var2_index=c.branches.index("mt"), var2_range=(0, 500, 10),
var1_label="met [GeV]", var2_label="mt [GeV]")
from .toolkit import ClassificationProject
# plot_NN_vs_var_2D_all("mt_vs_met_all.pdf", means=mean_signal, import logging
# model=c.model, transform_function=c.scaler.transform, logging.basicConfig()
# var1_index=c.branches.index("met"), var1_range=(0, 1000, 10), logging.getLogger("tfhelpers").setLevel(logging.DEBUG)
# var2_index=c.branches.index("mt"), var2_range=(0, 500, 10),
# var1_label="met [GeV]", var2_label="mt [GeV]")
import keras.backend as K
from .tfhelpers import get_single_neuron_function, get_max_activation_events from .tfhelpers import get_single_neuron_function, get_max_activation_events
import meme import meme
meme.setOptions(overrideCache="/scratch-local/nhartmann/meme_cache") # meme.setOptions(overrideCache="/scratch-local/nhartmann/meme_cache")
import logging if len(sys.argv) < 2:
logging.basicConfig() c = ClassificationProject(os.path.expanduser("~/p/scripts/keras/008-allhighlevel/all_highlevel_985"))
logging.getLogger("tfhelpers").setLevel(logging.DEBUG) else:
c = ClassificationProject(sys.argv[1])
def test_mean_signal():
mean_signal = get_mean_event(c.x_test, c.y_test, 1)
print("Mean signal: ")
for branch_index, val in enumerate(mean_signal):
print("{:>20}: {:<10.3f}".format(c.branches[branch_index], val))
plot_NN_vs_var_1D("met.pdf", mean_signal,
scorefun=c.evaluate,
var_index=c.branches.index("met"),
var_range=(0, 1000, 10),
var_label="met [GeV]")
plot_NN_vs_var_1D("mt.pdf", mean_signal,
scorefun=c.evaluate,
var_index=c.branches.index("mt"),
var_range=(0, 500, 10),
var_label="mt [GeV]")
plot_NN_vs_var_2D("mt_vs_met_crosscheck.pdf", means=mean_signal, plot_NN_vs_var_2D("mt_vs_met.pdf", means=mean_signal,
scorefun=get_single_neuron_function(c.model, layer=3, neuron=0, scaler=c.scaler), scorefun=c.evaluate,
var1_index=c.branches.index("met"), var1_range=(0, 1000, 10), var1_index=c.branches.index("met"), var1_range=(0, 1000, 10),
var2_index=c.branches.index("mt"), var2_range=(0, 500, 10), var2_index=c.branches.index("mt"), var2_range=(0, 500, 10),
var1_label="met [GeV]", var2_label="mt [GeV]") var1_label="met [GeV]", var2_label="mt [GeV]")
# transformed events plot_NN_vs_var_2D_all("mt_vs_met_all.pdf", means=mean_signal,
c.load(reload=True) model=c.model, transform_function=c.scaler.transform,
ranges = [np.percentile(c.x_test[:,var_index], [1,99]) for var_index in range(len(c.branches))] var1_index=c.branches.index("met"), var1_range=(0, 1000, 10),
var2_index=c.branches.index("mt"), var2_range=(0, 500, 10),
losses, events = get_max_activation_events(c.model, ranges, ntries=100000, layer=3, neuron=0, threshold=0.2) var1_label="met [GeV]", var2_label="mt [GeV]")
events = c.scaler.inverse_transform(events) plot_NN_vs_var_2D("mt_vs_met_crosscheck.pdf", means=mean_signal,
scorefun=get_single_neuron_function(c.model, layer=3, neuron=0, scaler=c.scaler),
plot_hist_2D_events( var1_index=c.branches.index("met"), var1_range=(0, 1000, 10),
"mt_vs_met_actmaxhist.pdf", var2_index=c.branches.index("mt"), var2_range=(0, 500, 10),
events[:,c.branches.index("met")], var1_label="met [GeV]", var2_label="mt [GeV]")
events[:,c.branches.index("mt")],
100, 0, 1000,
100, 0, 500, def test_max_act():
varx_label="met [GeV]", vary_label="mt [GeV]",
) # transformed events
c.load(reload=True)
plot_cond_avg_actmax_2D( ranges = [np.percentile(c.x_test[:,var_index], [1,99]) for var_index in range(len(c.branches))]
"mt_vs_met_cond_actmax.pdf",
c.model, 3, 0, ranges, losses, events = get_max_activation_events(c.model, ranges, ntries=100000, layer=3, neuron=0, threshold=0.2)
c.branches.index("met"),
c.branches.index("mt"), events = c.scaler.inverse_transform(events)
30, 0, 1000,
30, 0, 500, plot_hist_2D_events(
scaler=c.scaler, "mt_vs_met_actmaxhist.pdf",
varx_label="met [GeV]", vary_label="mt [GeV]", events[:,c.branches.index("met")],
) events[:,c.branches.index("mt")],
100, 0, 1000,
plot_hist_2D_events( 100, 0, 500,
"mt_vs_output_actmax.pdf", varx_label="met [GeV]", vary_label="mt [GeV]",
events[:,c.branches.index("mt")], )
losses,
100, 0, 500, plot_hist_2D_events(
100, 0, 1, "mt_vs_output_actmax.pdf",
varx_label="mt [GeV]", vary_label="NN output", events[:,c.branches.index("mt")],
log=True, losses,
) 100, 0, 500,
100, 0, 1,
utrf_x_test = c.scaler.inverse_transform(c.x_test) varx_label="mt [GeV]", vary_label="NN output",
log=True,
plot_hist_2D_events( )
"mt_vs_output_signal_test.pdf",
utrf_x_test[c.y_test==1][:,c.branches.index("mt")],
c.scores_test[c.y_test==1].reshape(-1), def test_cond_max_act():
100, 0, 1000,
100, 0, 1, c.load(reload=True)
varx_label="mt [GeV]", vary_label="NN output", ranges = [np.percentile(c.x_test[:,var_index], [1,99]) for var_index in range(len(c.branches))]
log=True,
) plot_cond_avg_actmax_2D(
"mt_vs_met_cond_actmax.pdf",
plot_hist_2D_events( c.model, 3, 0, ranges,
"apl_vs_output_actmax.pdf", c.branches.index("met"),
events[:,c.branches.index("LepAplanarity")], c.branches.index("mt"),
losses, 30, 0, 1000,
100, 0, 0.1, 30, 0, 500,
100, 0, 1, scaler=c.scaler,
varx_label="Aplanarity", vary_label="NN output", varx_label="met [GeV]", vary_label="mt [GeV]",
) )
def test_xtest_vs_output():
c.load(reload=True)
utrf_x_test = c.scaler.inverse_transform(c.x_test)
plot_hist_2D_events(
"mt_vs_output_signal_test.pdf",
utrf_x_test[c.y_test==1][:,c.branches.index("mt")],
c.scores_test[c.y_test==1].reshape(-1),
100, 0, 1000,
100, 0, 1,
varx_label="mt [GeV]", vary_label="NN output",
log=True,
)
# plot_hist_2D_events(
# "apl_vs_output_actmax.pdf",
# events[:,c.branches.index("LepAplanarity")],
# losses,
# 100, 0, 0.1,
# 100, 0, 1,
# varx_label="Aplanarity", vary_label="NN output",
# )
def test_profile():
c.load(reload=True)
utrf_x_test = c.scaler.inverse_transform(c.x_test)
plot_profile_2D(
"mt_vs_met_profilemean_sig.pdf",
utrf_x_test[c.y_test==1][:,c.branches.index("met")],
utrf_x_test[c.y_test==1][:,c.branches.index("mt")],
c.scores_test[c.y_test==1].reshape(-1),
20, 0, 500,
20, 0, 1000,
varx_label="met [GeV]", vary_label="mt [GeV]",
)
plot_profile_2D(
"mt_vs_met_profilemax_sig.pdf",
utrf_x_test[c.y_test==1][:,c.branches.index("met")],
utrf_x_test[c.y_test==1][:,c.branches.index("mt")],
c.scores_test[c.y_test==1].reshape(-1),
20, 0, 500,
20, 0, 1000,
metric=np.max,
varx_label="met [GeV]", vary_label="mt [GeV]",
)
for obj in dir():
if obj.startswith("test_") and callable(locals()[obj]):
if (len(sys.argv) > 2) and (not sys.argv[2] == obj):
continue
print("Running {}".format(obj))
locals()[obj]()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment