Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
2a63c21
header changed to comma-separated for h5py access
dbullock1086 Oct 11, 2016
a5c5f02
using lxplus samples
dbullock1086 Oct 11, 2016
54d1b39
capitalization fix
dbullock1086 Oct 11, 2016
3964194
capitalization fix
dbullock1086 Oct 11, 2016
b406dab
capitalization fix
dbullock1086 Oct 11, 2016
d869ca4
capitalization fix
dbullock1086 Oct 11, 2016
914524e
revert np.float32 to float
dbullock1086 Oct 11, 2016
c3d34a3
sample directories
dbullockphd Oct 20, 2016
ac30136
test CSV output
dbullockphd Oct 20, 2016
ce1c288
refork
dbullockphd Oct 23, 2016
537fa8c
refork
dbullockphd Oct 23, 2016
83ce483
redundancy
dbullockphd Oct 24, 2016
79c44af
cleanup
dbullockphd Oct 26, 2016
53e7859
regroup
dbullockphd Oct 27, 2016
03a2950
trying different grouping
dbullockphd Oct 27, 2016
cacf5c5
missing comma
dbullockphd Oct 27, 2016
1603b5d
trying new style
dbullockphd Oct 27, 2016
80941b6
simple pedagogy models
dbullockphd Nov 1, 2016
0b1605b
name fix
dbullockphd Nov 1, 2016
552a617
missing comma
dbullockphd Nov 1, 2016
735212b
missing slash
dbullockphd Nov 1, 2016
06d41ff
missing comma
dbullockphd Nov 1, 2016
d445c01
missing variable
dbullockphd Nov 1, 2016
9a8f437
reorder for color
dbullockphd Nov 2, 2016
290d2b1
new configs
dbullockphd Nov 10, 2016
df6a356
new tutorial test
dbullockphd Nov 11, 2016
5160fd7
tested lxplus, checking uta
dbullockphd Nov 11, 2016
25a8047
tested lxplus, checking uta
dbullockphd Nov 11, 2016
8599efc
actually quick
dbullockphd Nov 11, 2016
c1e81d2
optimizing
dbullockphd Nov 11, 2016
0738ed5
testing new normalization
dbullockphd Dec 1, 2016
d5e4ec9
IQR weight
dbullockphd Dec 2, 2016
49973c6
scale/shift
dbullockphd Dec 2, 2016
c08a0ee
capitalization
dbullockphd Dec 2, 2016
7c0e159
set for tutorial again
dbullockphd Dec 14, 2016
ee483c0
retest
dbullockphd Jan 10, 2017
99a17dc
retest
dbullockphd Jan 11, 2017
afe4384
update bbll+MET
dbullockphd Jan 16, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 30 additions & 57 deletions Analysis.py
Original file line number Diff line number Diff line change
@@ -1,75 +1,48 @@
# Analysis
import numpy as np
import matplotlib as mpl
mpl.use('pdf')
import matplotlib.pyplot as plt
from sklearn.metrics import roc_curve, auc

def ClassificationAnalysis(MyModel,Test_X,Test_Y,BatchSize, SignalClassIndex=5):
import matplotlib as mpl
mpl.use('pdf')
import matplotlib.pyplot as plt
mpColors = ['red', 'darkorange', 'lawngreen', 'green', 'lightseagreen', 'cyan', 'royalblue', 'blue', 'blueviolet', 'magenta', 'hotpink']

from sklearn.metrics import roc_curve, auc
def ClassificationAnalysis (MyModel, Test_X, Test_Y, BatchSize, SignalClassIndex=5):
result = MyModel.Model.predict (Test_X, batch_size=BatchSize)

print "Prediction Analysis."
result = MyModel.Model.predict(Test_X, batch_size=BatchSize)

fpr, tpr, _ = roc_curve(Test_Y[:,SignalClassIndex],
result[:,SignalClassIndex])
roc_auc = auc(fpr, tpr)

lw=2

plt.plot(fpr,tpr,color='darkorange',
lw=lw, label='ROC curve (area = %0.2f)' % roc_auc)

print "ROC AUC: ",roc_auc

plt.plot([0, 1], [0, 1], color='navy', lw=lw, linestyle='--')
plt.xlim([0.0, 1.0])
plt.ylim([0.0, 1.05])

plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')

plt.legend(loc="lower right")
fpr, tpr, _ = roc_curve (Test_Y[:,SignalClassIndex],
result[:,SignalClassIndex])
roc_auc = auc (fpr, tpr)

plt.savefig(MyModel.OutDir+"/ROC.pdf")


mpColors=["blue","green","red","cyan","magenta","yellow","black","white"]
lw=2

def MultiClassificationAnalysis(MyModel,Test_X,Test_Y,BatchSize):
import matplotlib as mpl
mpl.use('pdf')
import matplotlib.pyplot as plt
plt.plot (fpr,tpr,color=mpColors[SignalClassIndex],
lw=lw, label='ROC curve (area = %0.2f)' % roc_auc)

from sklearn.metrics import roc_curve, auc
print 'ROC', SignalClassIndex, 'AUC:', roc_auc
pass

print "Prediction Analysis."
result = MyModel.Model.predict(Test_X, batch_size=BatchSize)

NClasses=Test_Y.shape[1]

for ClassIndex in xrange(0,NClasses):
fpr, tpr, _ = roc_curve(Test_Y[:,ClassIndex],
result[:,ClassIndex])
roc_auc = auc(fpr, tpr)
def MultiClassificationAnalysis (MyModel, Test_X, Test_Y, BatchSize):
print 'Prediction Analysis.'
result = MyModel.Model.predict (Test_X, batch_size=BatchSize)

lw=2
NClasses = Test_Y.shape[1]

plt.plot(fpr,tpr,color=mpColors[ClassIndex],
lw=lw, label='ROC curve (area = %0.2f)' % roc_auc)
for ClassIndex in xrange(NClasses):
ClassificationAnalysis (MyModel, Test_X, Test_Y, BatchSize, ClassIndex)
pass

print "ROC ",ClassIndex," AUC: ",roc_auc
lw=2

plt.plot([0, 1], [0, 1], color='navy', lw=lw, linestyle='--')
plt.xlim([0.0, 1.0])
plt.ylim([0.0, 1.05])
plt.plot ([0, 1], [0, 1], color='navy', lw=lw, linestyle='--')
plt.xlim ([0.0, 1.0])
plt.ylim ([0.0, 1.05])

plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.xlabel ('False Positive Rate')
plt.ylabel ('True Positive Rate')

plt.legend(loc="lower right")
plt.legend (loc='lower right')


plt.savefig(MyModel.OutDir+"/ROC.pdf")

plt.savefig (MyModel.OutDir + '/ROC.pdf')
return result
68 changes: 33 additions & 35 deletions Arguments.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,47 @@
import argparse

# Configuration of this job
parser = argparse.ArgumentParser()
parser.add_argument('-C', '--config',default="EventClassificationDNN/ScanConfig.py")
parser.add_argument('-I', '--inputdata',default="/data/afarbin/crogan/h5/mP1000_mC200_mX100.h5")
parser.add_argument('-L', '--LoadModel',default=False)
parser.add_argument('--gpu', dest='gpuid', default="")
parser.add_argument('--cpu', action="store_true")
parser.add_argument('--NoTrain', action="store_true")
parser.add_argument('-s',"--hyperparamset", default="0")
parser.add_argument('-v',"--varset", default="0")
parser.add_argument('--NoResults', action="store_false")
parser.add_argument ('-C', '--config', default='EventClassificationDNN/ScanConfig.py')
parser.add_argument ('-I', '--inputdata', default='/data/afarbin/crogan/h5/mP1000_mC200_mX100.h5')
parser.add_argument ('-L', '--LoadModel', default=False)
parser.add_argument ('--gpu', dest='gpuid', default='')
parser.add_argument ('--cpu', action='store_true')
parser.add_argument ('--NoTrain', action='store_true')
parser.add_argument ('-s', '--hyperparamset', type=int, default=0)
parser.add_argument ('-v', '--varset', type=int, default=0)
parser.add_argument ('--NoResults', action='store_false')

args = parser.parse_args()

UseGPU=not args.cpu
gpuid=args.gpuid
if args.hyperparamset:
HyperParamSet = int(args.hyperparamset)

if args.varset:
VarSet = int(args.varset)

print "Using VarSet: ",VarSet
UseGPU = not args.cpu
gpuid = args.gpuid
HyperParamSet = args.hyperparamset

ConfigFile=args.config
InputData=args.inputdata
VarSet = args.varset
print 'Using VarSet:', VarSet

LoadModel=args.LoadModel
ConfigFile = args.config
InputData = args.inputdata
LoadModel = args.LoadModel

# Configuration from PBS:
if "PBS_ARRAYID" in os.environ:
HyperParamSet = int(os.environ["PBS_ARRAYID"])
if 'PBS_ARRAYID' in os.environ: HyperParamSet = int(os.environ['PBS_ARRAYID'])

if "PBS_QUEUE" in os.environ:
if "cpu" in os.environ["PBS_QUEUE"]:
UseGPU=False
if "gpu" in os.environ["PBS_QUEUE"]:
UseGPU=True
gpuid=int(os.environ["PBS_QUEUE"][3:4])
if 'PBS_QUEUE' in os.environ:
if 'cpu' in os.environ['PBS_QUEUE']: UseGPU = False
if 'gpu' in os.environ['PBS_QUEUE']:
UseGPU = True
gpuid = int(os.environ['PBS_QUEUE'][3:4])
pass
pass

if UseGPU:
print "Using GPU",gpuid
os.environ['THEANO_FLAGS'] = "mode=FAST_RUN,device=gpu%s,floatX=float32,force_device=True" % (gpuid)
else:
print "Using CPU."
print 'Using GPU', gpuid
os.environ['THEANO_FLAGS'] = 'mode=FAST_RUN,device=gpu%s,floatX=float32,force_device=True' % (gpuid)
pass
else: print 'Using CPU.'

Train= not args.NoTrain
Train = not args.NoTrain

WriteResults= args.NoResults
WriteResults = args.NoResults
33 changes: 13 additions & 20 deletions CSVWriter.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
import numpy as np

def CSVWriter(filename,X,Y,R):

names=X.dtype.names

colnames=""
#!/usr/bin/env python

for n in names:
colnames+=n+"/f:"
import numpy as np

# colnames+="TrueClass/f:"
for i in xrange(0,Y.shape[1]):
colnames+="true_"+str(i)+"/f:"
def CSVWriter (filename, X, Y, R, arrType):
names = X.dtype.names
colnames = []

for i in xrange(0,R.shape[1]):
colnames+="predict_"+str(i)+"/f:"
for n in names: colnames.append(n)
for i in xrange(0, Y.shape[1]): colnames.append('true_' + str(i))
for i in xrange(0, R.shape[1]): colnames.append('predict_' + str(i))

f = open(filename, 'w')
f.write(colnames[:-1]+"\n")

X0=X.view(np.float32).reshape(X.shape + (-1,))
f.write(','.join(colnames) + '\n')

YI=np.nonzero(Y)[1]
out=np.concatenate((X0,Y,R),axis=1)
X0 = X.view(arrType).reshape(X.shape + (-1,))
out = np.concatenate((X0,Y,R), axis=1)

np.savetxt(f,out,delimiter=',')
np.savetxt(f, out, delimiter=',')
pass
2 changes: 1 addition & 1 deletion Classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ def Build(self):
self.Model=model

def Compile(self, Loss="categorical_crossentropy", Optimizer="rmsprop"):
self.Model.compile(loss=loss, optimizer=optimizer,metrics=["accuracy"])
self.Model.compile(loss=Loss, optimizer=Optimizer,metrics=["accuracy"])
Loading