Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
DavidWalz
airshower-deeplearning
Commits
89690194
Commit
89690194
authored
Aug 09, 2017
by
JGlombitza
Browse files
v1.1
New Path Correct description
parent
584ff2f2
Changes
6
Hide whitespace changes
Inline
Side-by-side
training/DNN_AngularRec.py
View file @
89690194
...
...
@@ -19,8 +19,8 @@ nbatch = 132
# load and prepare data
# ----------------------------------------------------------------------
Folder
=
'
/home/JGlombitza/DataLink/Public/Paper/P
re
P
ro
Data
'
filenames
=
glob
.
glob
(
Folder
+
"/
Data_
PlanarWaveShower_PrePro
_NewMC_Mixed_Composition
*"
)
Folder
=
'
../Data_p
re
p
ro
cessed
'
filenames
=
glob
.
glob
(
Folder
+
"/PlanarWaveShower_PrePro*"
)
N
=
10000
*
len
(
filenames
)
a
=
10000
# packagesize
...
...
@@ -30,10 +30,10 @@ showeraxis = np.zeros(N*3).reshape(N,3)
Energy
=
np
.
zeros
(
N
)
for
i
in
range
(
0
,
len
(
filenames
)):
data
=
np
.
load
(
filenames
[
i
])
Input1
[
a
*
i
:
a
*
(
i
+
1
)]
=
data
[
'Input1'
]
.
reshape
(
a
,
9
,
9
,
80
,
1
)
showeraxis
[
a
*
i
:
a
*
(
i
+
1
)]
=
data
[
'showeraxis'
]
.
reshape
(
a
,
3
)
Input2
[
a
*
i
:
a
*
(
i
+
1
)]
=
data
[
'Input2'
]
.
reshape
(
a
,
9
,
9
,
2
)
Energy
[
a
*
i
:
a
*
(
i
+
1
)]
=
data
[
'Energy'
]
.
reshape
(
a
)
Input1
[
a
*
i
:
a
*
(
i
+
1
)]
=
data
[
'Input1'
]
showeraxis
[
a
*
i
:
a
*
(
i
+
1
)]
=
data
[
'showeraxis'
]
Input2
[
a
*
i
:
a
*
(
i
+
1
)]
=
data
[
'Input2'
]
Energy
[
a
*
i
:
a
*
(
i
+
1
)]
=
data
[
'Energy'
]
print
(
'Loaded %i showers'
%
N
)
...
...
training/DNN_AngularRec_OnlyTime.py
View file @
89690194
...
...
@@ -18,8 +18,8 @@ nbatch = 132
# load and prepare data
# ----------------------------------------------------------------------
Folder
=
'
/home/JGlombitza/DataLink/Public/Paper/P
re
P
ro
Data
'
filenames
=
glob
.
glob
(
Folder
+
"/
Data_
PlanarWaveShower_PrePro
_NewMC_Mixed_Composition
*"
)
Folder
=
'
../Data_p
re
p
ro
cessed
'
filenames
=
glob
.
glob
(
Folder
+
"/PlanarWaveShower_PrePro*"
)
N
=
10000
*
len
(
filenames
)
a
=
10000
# packagesize
...
...
@@ -28,9 +28,9 @@ showeraxis = np.zeros(N*3).reshape(N,3)
Energy
=
np
.
zeros
(
N
)
for
i
in
range
(
0
,
len
(
filenames
)):
data
=
np
.
load
(
filenames
[
i
])
showeraxis
[
a
*
i
:
a
*
(
i
+
1
)]
=
data
[
'showeraxis'
]
.
reshape
(
a
,
3
)
showeraxis
[
a
*
i
:
a
*
(
i
+
1
)]
=
data
[
'showeraxis'
]
Input2
[
a
*
i
:
a
*
(
i
+
1
)]
=
data
[
'Input2'
][:,:,:,
0
].
reshape
(
a
,
9
,
9
,
1
)
Energy
[
a
*
i
:
a
*
(
i
+
1
)]
=
data
[
'Energy'
]
.
reshape
(
a
)
Energy
[
a
*
i
:
a
*
(
i
+
1
)]
=
data
[
'Energy'
]
## Reshape, Split to test and train sets
ntest
=
40000
...
...
training/DNN_Energy.py
View file @
89690194
...
...
@@ -13,16 +13,12 @@ lr = 0.001
log_dir
=
"."
nbatch
=
132
def
DenselyConnectedSepConv
(
z
,
nfilter
,
**
kwargs
):
c
=
SeparableConv2D
(
nfilter
,
(
3
,
3
),
padding
=
'same'
,
depth_multiplier
=
1
,
**
kwargs
)(
z
)
return
concatenate
([
z
,
c
],
axis
=-
1
)
# ----------------------------------------------------------------------
# load and prepare data
# ----------------------------------------------------------------------
Folder
=
'
/home/JGlombitza/DataLink/Public/Paper/P
re
P
ro
Data
'
filenames
=
glob
.
glob
(
Folder
+
"/
Data_
PlanarWaveShower_PrePro
_NewMC_Mixed_Composition
*"
)
Folder
=
'
../Data_p
re
p
ro
cessed
'
filenames
=
glob
.
glob
(
Folder
+
"/PlanarWaveShower_PrePro*"
)
N
=
10000
*
len
(
filenames
)
a
=
10000
# packagesize
...
...
@@ -31,9 +27,9 @@ Input2 = np.zeros(N*9*9*2).reshape(N,9,9,2)
Energy
=
np
.
zeros
(
N
)
for
i
in
range
(
0
,
len
(
filenames
)):
data
=
np
.
load
(
filenames
[
i
])
Input1
[
a
*
i
:
a
*
(
i
+
1
)]
=
data
[
'Input1'
]
.
reshape
(
a
,
9
,
9
,
80
,
1
)
Input1
[
a
*
i
:
a
*
(
i
+
1
)]
=
data
[
'Input1'
]
Energy
[
a
*
i
:
a
*
(
i
+
1
)]
=
data
[
'Energy'
]
Input2
[
a
*
i
:
a
*
(
i
+
1
)]
=
data
[
'Input2'
]
.
reshape
(
a
,
9
,
9
,
2
)
Input2
[
a
*
i
:
a
*
(
i
+
1
)]
=
data
[
'Input2'
]
## Reshape, Split to test and train sets
ntest
=
40000
...
...
@@ -67,7 +63,7 @@ x = concatenate([TimeProcess, inputT0])
# Densely connected convolutions
nfilter
=
12
for
i
in
range
(
4
):
x
=
DenselyConnectedSepConv
(
x
,
nfilter
,
**
kwargs
)
x
=
tools
.
DenselyConnectedSepConv
(
x
,
nfilter
,
**
kwargs
)
nfilter
=
2
*
nfilter
x
=
SeparableConv2D
(
nfilter
,
(
3
,
3
),
padding
=
'same'
,
depth_multiplier
=
1
,
**
kwargs
)(
x
)
x
=
Flatten
()(
x
)
...
...
training/DNN_Energy_OnlySignal.py
View file @
89690194
...
...
@@ -18,8 +18,8 @@ nbatch = 132
# load and prepare data
# ----------------------------------------------------------------------
Folder
=
'
/home/JGlombitza/DataLink/Public/Paper/P
re
P
ro
Data
'
filenames
=
glob
.
glob
(
Folder
+
"/
Data_
PlanarWaveShower_PrePro
_NewMC_Mixed_Composition
*"
)
Folder
=
'
../Data_p
re
p
ro
cessed
'
filenames
=
glob
.
glob
(
Folder
+
"/PlanarWaveShower_PrePro*"
)
N
=
10000
*
len
(
filenames
)
a
=
10000
# packagesize
...
...
training/DNN_Xmax.py
View file @
89690194
...
...
@@ -17,8 +17,8 @@ nbatch = 132
# load and prepare data
# ----------------------------------------------------------------------
Folder
=
'
/home/JGlombitza/DataLink/Public/Paper/P
re
P
ro
Data
'
filenames
=
glob
.
glob
(
Folder
+
"/
Data_
PlanarWaveShower_PrePro
_NewMC_Mixed_Composition
*"
)
Folder
=
'
../Data_p
re
p
ro
cessed
'
filenames
=
glob
.
glob
(
Folder
+
"/PlanarWaveShower_PrePro*"
)
N
=
10000
*
len
(
filenames
)
a
=
10000
# packagesize
...
...
@@ -28,10 +28,10 @@ Xmax = np.zeros(N)
Energy
=
np
.
zeros
(
N
)
for
i
in
range
(
0
,
len
(
filenames
)):
data
=
np
.
load
(
filenames
[
i
])
Input1
[
a
*
i
:
a
*
(
i
+
1
)]
=
data
[
'Input1'
]
.
reshape
(
a
,
9
,
9
,
80
,
1
)
Input1
[
a
*
i
:
a
*
(
i
+
1
)]
=
data
[
'Input1'
]
Xmax
[
a
*
i
:
a
*
(
i
+
1
)]
=
data
[
'Xmax'
]
Energy
[
a
*
i
:
a
*
(
i
+
1
)]
=
data
[
'Energy'
]
Input2
[
a
*
i
:
a
*
(
i
+
1
)]
=
data
[
'Input2'
]
.
reshape
(
a
,
9
,
9
,
2
)
Input2
[
a
*
i
:
a
*
(
i
+
1
)]
=
data
[
'Input2'
]
## Reshape, Split to test and train sets
ntest
=
40000
...
...
training/tools.py
View file @
89690194
...
...
@@ -13,13 +13,17 @@ def Distance(y_true, y_pred):
mean
,
var
=
tf
.
nn
.
moments
((
y_true
-
y_pred
),
axes
=
[
0
])
return
tf
.
sqrt
(
var
)
def
MeanElong
(
y_true
,
y_pred
):
##inGrad
def
MeanElong
(
y_true
,
y_pred
):
''' Metric to control the mean of the angulardistance distribution '''
return
57.29577951308232
*
K
.
mean
(
tf
.
minimum
(
tf
.
acos
((
y_pred
[:,
0
]
*
y_true
[:,
0
]
+
y_pred
[:,
1
]
*
y_true
[:,
1
]
+
y_pred
[:,
2
]
*
y_true
[:,
2
])
/
(
tf
.
sqrt
(
y_pred
[:,
0
]
*
y_pred
[:,
0
]
+
y_pred
[:,
1
]
*
y_pred
[:,
1
]
+
y_pred
[:,
2
]
*
y_pred
[:,
2
])
*
tf
.
sqrt
(
y_true
[:,
0
]
*
y_true
[:,
0
]
+
y_true
[:,
1
]
*
y_true
[:,
1
]
+
y_true
[:,
2
]
*
y_true
[:,
2
]))),
1
))
def
Percentile68
(
x
):
''' Calculates 68% quantile of distribution'''
return
np
.
percentile
(
x
,
68
)
def
vec2ang
(
v
):
'''Calculates phi and theta for given shower axis'''
x
,
y
,
z
=
np
.
asarray
(
v
).
T
...
...
@@ -27,11 +31,13 @@ def vec2ang(v):
theta
=
np
.
pi
/
2
-
np
.
arctan2
(
z
,
(
x
**
2
+
y
**
2
)
**
.
5
)
return
np
.
rad2deg
(
phi
),
np
.
rad2deg
(
theta
)
def
DenselyConnectedSepConv
(
z
,
nfilter
,
**
kwargs
):
''' Densely Connected SeparableConvolution2D Layer'''
c
=
SeparableConv2D
(
nfilter
,
(
3
,
3
),
padding
=
'same'
,
depth_multiplier
=
1
,
**
kwargs
)(
z
)
return
concatenate
([
z
,
c
],
axis
=-
1
)
def
PlotHistosXmaxReconstruction
(
y_true
,
y_pred
,
log_dir
,
name
,
Energy
):
''' Plottingfunction to evaluate the reconstruction of the shower depths Xmax
plots: predicted Xmax against MC Xmax and the energy dependence of the reconstruction (embedded)'''
...
...
@@ -41,7 +47,7 @@ def PlotHistosXmaxReconstruction(y_true, y_pred, log_dir, name, Energy):
ax1
.
scatter
(
y_true
,
y_pred
,
s
=
2
,
color
=
'royalblue'
,
alpha
=
.
90
)
ax1
.
set_xlabel
(
r
'$X_{max,\;true}$ $[g/cm^{2}]$'
)
ax1
.
set_ylabel
(
r
'$X_{max,\;DNN}$ $[g/cm^{2}]$'
)
left
,
bottom
,
width
,
height
=
[
0.23
,
0.6
,
0.3
,
0.26
]
# Links Oben
left
,
bottom
,
width
,
height
=
[
0.23
,
0.6
,
0.3
,
0.26
]
ax1
.
text
(
0.95
,
0.2
,
r
"$\mu = $ %.3f "
%
np
.
mean
(
reco
)
+
r
"$[g/cm^{2}]$"
+
"
\n
"
+
"$\sigma = $ %.3f "
%
np
.
std
(
reco
)
+
r
"$[g/cm^{2}]$"
,
verticalalignment
=
'top'
,
horizontalalignment
=
'right'
,
transform
=
ax1
.
transAxes
,
backgroundcolor
=
'w'
)
ax1
.
plot
([
np
.
min
(
y_true
),
np
.
max
(
y_true
)],
[
np
.
min
(
y_true
),
np
.
max
(
y_true
)],
color
=
'red'
)
# Energy dependence plot
...
...
@@ -59,14 +65,13 @@ def PlotHistosXmaxReconstruction(y_true, y_pred, log_dir, name, Energy):
fig
.
savefig
(
log_dir
+
'/Xmax_embedding_%s.png'
%
name
)
return
reco
def
PlotHistosEnergyReconstruction
(
y_true
,
y_pred
,
log_dir
,
name
):
''' Plottingfunction to evaluate the reconstruction of the cosmic ray energy
plots: predicted Energy against MC Energy and the energy dependence of the relative energy resolution (embedded)'''
y_true
=
y_true
.
reshape
(
y_true
.
shape
[
0
],
1
)
reco
=
y_true
-
y_pred
# Embedding plot
# Embedding plot
fig
,
ax1
=
plt
.
subplots
(
1
)
ax1
.
scatter
(
y_true
,
y_pred
,
s
=
2
,
color
=
'royalblue'
,
alpha
=
.
90
)
ax1
.
set_xlabel
(
r
'$Energy_{true}\;[EeV]$'
)
...
...
@@ -87,17 +92,18 @@ def PlotHistosEnergyReconstruction(y_true, y_pred, log_dir, name):
fig
.
savefig
(
log_dir
+
'/Energy_embedding_%s.png'
%
name
)
return
reco
def
PlotHistosAngularReconstruction
(
y_true
,
y_pred
,
log_dir
,
name
,
Energy
,
Signal
=
0
):
''' Plotting function to evaluate the reconstruction of the shower axis
plots: angular distance distribution and the energy dependence of the angular reconstruction (embedded)'''
phi
,
theta
=
vec2ang
(
y_true
)
angulardistance
=
180
/
np
.
pi
*
np
.
arccos
(
np
.
clip
(
np
.
sum
(
y_true
*
y_pred
,
axis
=-
1
)
/
np
.
linalg
.
norm
(
y_pred
,
axis
=-
1
)
/
np
.
linalg
.
norm
(
y_true
,
axis
=-
1
),
-
1
,
1
))
resolution
=
Percentile68
(
angulardistance
)
# Embedding plot
# Embedding plot
fig
,
ax1
=
plt
.
subplots
(
1
)
ax1
.
hist
(
angulardistance
,
bins
=
np
.
linspace
(
0
,
4
,
51
))
ax1
.
set
(
xlabel
=
r
'$Angulardistance\;\delta\;[^\circ]$'
,
ylabel
=
r
'$N$'
)
left
,
bottom
,
width
,
height
=
[
0.56
,
0.6
,
0.31
,
0.27
]
# Rechts Oben
left
,
bottom
,
width
,
height
=
[
0.56
,
0.6
,
0.31
,
0.27
]
ax2
=
fig
.
add_axes
([
left
,
bottom
,
width
,
height
])
x_bins
=
12
logE
=
18
+
np
.
log10
(
Energy
)
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment