Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • Eric.Schanet/KerasROOTClassification
  • Nikolai.Hartmann/KerasROOTClassification
2 results
Show changes
Commits on Source (1)
...@@ -250,6 +250,35 @@ def plot_hist_2D_events(plotname, valsx, valsy, nbinsx, xmin, xmax, nbinsy, ymin ...@@ -250,6 +250,35 @@ def plot_hist_2D_events(plotname, valsx, valsy, nbinsx, xmin, xmax, nbinsy, ymin
plot_hist_2D(plotname, xedges, yedges, hist, varx_label, vary_label, log) plot_hist_2D(plotname, xedges, yedges, hist, varx_label, vary_label, log)
def plot_hist_2D_events_ratio(plotname,
valsx1, valsy1,
valsx2, valsy2,
nbinsx, xmin, xmax, nbinsy, ymin, ymax,
weights1=None,
weights2=None,
varx_label=None, vary_label=None, log=False):
xedges = np.linspace(xmin, xmax, nbinsx)
yedges = np.linspace(ymin, ymax, nbinsy)
hist1, xedges, yedges = np.histogram2d(valsx1, valsy1, bins=(xedges, yedges), weights=weights1)
hist2, xedges, yedges = np.histogram2d(valsx2, valsy2, bins=(xedges, yedges), weights=weights2)
hist1 = hist1.T
hist2 = hist2.T
hist1 /= hist1.sum()
hist2 /= hist2.sum()
hist2[hist2==0] = np.nan
hist = hist1/hist2
print(hist)
plot_hist_2D(plotname, xedges, yedges, hist, varx_label, vary_label, log)
def plot_cond_avg_actmax_2D(plotname, model, layer, neuron, ranges, def plot_cond_avg_actmax_2D(plotname, model, layer, neuron, ranges,
varx_index, vary_index, varx_index, vary_index,
nbinsx, xmin, xmax, nbinsy, ymin, ymax, nbinsx, xmin, xmax, nbinsy, ymin, ymax,
......
...@@ -13,6 +13,7 @@ from KerasROOTClassification.plotting import ( ...@@ -13,6 +13,7 @@ from KerasROOTClassification.plotting import (
plot_NN_vs_var_2D, plot_NN_vs_var_2D,
plot_profile_2D, plot_profile_2D,
plot_hist_2D_events, plot_hist_2D_events,
plot_hist_2D_events_ratio,
plot_cond_avg_actmax_2D plot_cond_avg_actmax_2D
) )
from KerasROOTClassification.utils import get_single_neuron_function, get_max_activation_events from KerasROOTClassification.utils import get_single_neuron_function, get_max_activation_events
...@@ -23,7 +24,7 @@ parser.add_argument("output_filename") ...@@ -23,7 +24,7 @@ parser.add_argument("output_filename")
parser.add_argument("varx") parser.add_argument("varx")
parser.add_argument("vary") parser.add_argument("vary")
parser.add_argument("-m", "--mode", parser.add_argument("-m", "--mode",
choices=["mean_sig", "mean_bkg", "profile_sig", "profile_bkg", "hist_sig", "hist_bkg", "hist_actmax", "cond_actmax"], choices=["mean_sig", "mean_bkg", "profile_sig", "profile_bkg", "hist_sig", "hist_bkg", "hist_ratio", "hist_actmax", "cond_actmax"],
default="mean_sig") default="mean_sig")
parser.add_argument("-l", "--layer", type=int, help="Layer index (takes last layer by default)") parser.add_argument("-l", "--layer", type=int, help="Layer index (takes last layer by default)")
parser.add_argument("-n", "--neuron", type=int, default=0, help="Neuron index (takes first neuron by default)") parser.add_argument("-n", "--neuron", type=int, default=0, help="Neuron index (takes first neuron by default)")
...@@ -134,7 +135,7 @@ elif args.mode.startswith("profile"): ...@@ -134,7 +135,7 @@ elif args.mode.startswith("profile"):
**opt_kwargs **opt_kwargs
) )
elif args.mode.startswith("hist"): elif args.mode.startswith("hist") and not args.mode == "hist_ratio":
if not args.mode == "hist_actmax": if not args.mode == "hist_actmax":
if args.mode == "hist_sig": if args.mode == "hist_sig":
...@@ -171,6 +172,30 @@ elif args.mode.startswith("hist"): ...@@ -171,6 +172,30 @@ elif args.mode.startswith("hist"):
log=args.log, log=args.log,
) )
elif args.mode == "hist_ratio":
valsx1 = c.x_test[c.y_test==1][:,varx_index]
valsx2 = c.x_test[c.y_test==0][:,varx_index]
if not plot_vs_activation:
valsy1 = c.x_test[c.y_test==1][:,vary_index]
valsy2 = c.x_test[c.y_test==0][:,vary_index]
else:
valsy1 = c.scores_test[c.y_test==1].reshape(-1)
valsy2 = c.scores_test[c.y_test==0].reshape(-1)
weights1 = c.w_test[c.y_test==1]
weights2 = c.w_test[c.y_test==0]
plot_hist_2D_events_ratio(
args.output_filename,
valsx1, valsy1,
valsx2, valsy2,
xmin=varx_range[0], xmax=varx_range[1], nbinsx=varx_range[2],
ymin=vary_range[0], ymax=vary_range[1], nbinsy=vary_range[2],
weights1=weights1,
weights2=weights2,
varx_label=varx_label, vary_label=vary_label,
log=args.log,
)
elif args.mode.startswith("cond_actmax"): elif args.mode.startswith("cond_actmax"):
x_test_scaled = c.scaler.transform(c.x_test) x_test_scaled = c.scaler.transform(c.x_test)
......