Exemplo n.º 1
0
def singleshot():
    fn = str(random.randint(1, 25))
    filename = 'rt-data-io/' + fn + '.csv'
    weightFile = 'Data/weights.h5'
    predFile = 'Data/singleCSV/singlePred.h5'
    columns = [
        'stresses_full_xx', 'stresses_full_yy', 'stresses_full_xy',
        'stresses_full_xz', 'stresses_full_yz', 'stresses_full_zz'
    ]
    testFile = 'single.h5'

    dictionary = defaultdict(list)
    print('working with {},...'.format(filename.split('/')[-1]))
    data = helper_functions.csv2dict(filename)
    grid_aftershock_count = np.double(data['aftershocksyn'])
    temp = grid_aftershock_count.tolist()
    dictionary['aftershocksyn'].extend(temp)
    for column in columns:
        dictionary[column].extend(np.double(data[column]))

    columns.append('aftershocksyn')
    helper_functions.dict2HDF('single.h5', columns, dictionary)
    features_in = [
        'stresses_full_xx', 'stresses_full_yy', 'stresses_full_xy',
        'stresses_full_xz', 'stresses_full_yz', 'stresses_full_zz'
    ]

    features_out = 'aftershocksyn'
    model = helper_functions.createModel()
    model.load_weights(weightFile)
    X, y = helper_functions.loadDataFromHDF(testFile, features_in,
                                            features_out)
    y_pred = model.predict(X)
    helper_functions.writeHDF(predFile, X, y)
    auc = sklearn.metrics.roc_auc_score(y, y_pred)
    return auc
Exemplo n.º 2
0
           'stresses_full_xy', 'stresses_full_xz',
           'stresses_full_yz','stresses_full_zz']
testFile = 'single.h5'

dictionary = defaultdict(list)
print('working with {},...'.format(filename.split('/')[-1]))
data = helper_functions.csv2dict(filename)
grid_aftershock_count = np.double(data['aftershocksyn'])
temp = grid_aftershock_count.tolist()
dictionary['aftershocksyn'].extend(temp)
for column in columns:
    dictionary[column].extend(np.double(data[column]))


columns.append('aftershocksyn')
helper_functions.dict2HDF('single.h5', columns, dictionary)
features_in = ['stresses_full_xx',
               'stresses_full_yy',
               'stresses_full_xy',
               'stresses_full_xz',
               'stresses_full_yz',
               'stresses_full_zz']

features_out = 'aftershocksyn'
model = helper_functions.createModel()
model.load_weights(weightFile)
X, y = helper_functions.loadDataFromHDF(testFile, features_in, features_out)
y_pred = model.predict(X)
helper_functions.writeHDF(predFile, X, y)
auc = sklearn.metrics.roc_auc_score(y, y_pred)
        print('{}. working with {}, please wait...'.format(
            i, filename.decode('utf-8')))
        # calling csv2dict(), to convert the csv file to dictionary
        data = helper_functions.csv2dict('Data/csvfiles/' +
                                         str(filename.decode('utf-8')))
        # accessing the key aftershocksyn to check for unique values, similar like (set(list[1, 1, 0, 2, 3])) -> outputs [1, 1, 0, 2, 3]
        grid_aftershock_count = np.double(data['aftershocksyn'])
        # no use of if
        #if len(np.unique(grid_aftershock_count)) < 2:
        #   continue
        temp = grid_aftershock_count.tolist()
        # adding a (key, value) to the testingSet
        dictionary['aftershocksyn'].extend(temp)
        # now adding remaining columns
        for column in columns:
            dictionary[column].extend(np.double(data[column]))

    return dictionary


##########################CREATING TESTING DATASET#############################
testingSet = makeDataDict(testingFilenames)

##########################CREATING TRAINING DATASET#############################
trainingSet = makeDataDict(trainingFilenames)

#############################SAVING THE DATASET################################
columns.append('aftershocksyn')
helper_functions.dict2HDF('training_tmp.h5', columns, trainingSet)
helper_functions.dict2HDF('testing_tmp.h5', columns, testingSet)