Esempio n. 1
0
import numpy as np
import sklearn as sklearn
import pdb as check
import modelfunctions

#set name of weights/biases file
weightFile = '../Data/TheBestWeights.h5'
predFile = './Predicted.h5'
testFile = '../Data/Testing.h5'

#names of features
field_names_in = [
    'stresses_full_xx', 'stresses_full_yy', 'stresses_full_xy',
    'stresses_full_xz', 'stresses_full_yz', 'stresses_full_zz'
]

#name of label
field_names_out = 'aftershocksyn'

#load model
model = modelfunctions.create_model()

#assess performance of training network on testing data set
model.load_weights(weightFile)
inTrue, outTrue = modelfunctions.LoadInputs(testFile, field_names_in,
                                            field_names_out)
outPred = model.predict(inTrue)
modelfunctions.writeHDF(predFile, inTrue, outPred)
auc = sklearn.metrics.roc_auc_score(outTrue, outPred)
print 'merged AUC on testing data set: ' + str(auc)
from keras.callbacks import ModelCheckpoint
import matplotlib.pyplot as plt

#set name of weights file and training/testing files
weightFile = '../Data/TheBestWeights.h5'
trainFile = '../Data/Training.h5'
testFile = '../Data/Testing.h5'

#names of features
field_names_in = ['stresses_full_xx', 'stresses_full_yy', 'stresses_full_xy', 'stresses_full_xz','stresses_full_yz','stresses_full_zz']

#name of label
field_names_out = 'aftershocksyn'

#load training data set
IN_Train, OUT_Train = modelfunctions.LoadInputs(trainFile, field_names_in, field_names_out)

#pull out some validation data with positive grid cells upsampled so that validation data has equal numbers of positive and negative samples
posidx = np.where(OUT_Train==1)
numpos = np.size(posidx)
negidx = np.where(OUT_Train==0)
numneg = np.size(negidx)

#divide data into positive and negative samples
POSdata = np.column_stack((IN_Train[posidx,:][0], OUT_Train[posidx].T))
NEGdata = np.column_stack((IN_Train[negidx,:][0], OUT_Train[negidx].T))

np.random.seed(42) #shuffle order of samples (same way every time to ensure validation data does not change)
np.random.shuffle(POSdata)
np.random.shuffle(NEGdata)
np.random.seed() #reseed