def create_cnn_model(learning_rate, weight_decay, dropout, hidden_layers, activation): g_model = Sequential() for i in range(len(hidden_layers)): if (i == 0): g_model.add( GraphConv(filters=hidden_layers[i], neighbors_ix_mat=graph_mat, num_neighbors=num_neighbors, activation=activation, input_shape=(input_size, features), kernel_regularizer=regularizers.l2(weight_decay))) g_model.add(Dropout(dropout)) else: g_model.add( GraphConv(filters=hidden_layers[i], neighbors_ix_mat=graph_mat, num_neighbors=num_neighbors, activation=activation, kernel_regularizer=regularizers.l2(weight_decay))) g_model.add(GraphConvPro()) g_model.add(Flatten()) g_model.add(Dense(1, activation='sigmoid')) optimizer = Adam(lr=learning_rate) g_model.compile(optimizer=optimizer, loss='mean_squared_error') return g_model
seed_value = 0 if len(sys.argv) > 1: max_train = int(sys.argv[1]) epochs = int(sys.argv[2]) seed_value = int(sys.argv[3]) os.environ['PYTHONHASHSEED'] = str(seed_value) random.seed(seed_value) np.random.seed(seed_value) g_model = Sequential() g_model.add( GraphConv(filters=10, neighbors_ix_mat=graph_mat, num_neighbors=num_neighbors, activation='elu', input_shape=(X_train_2.shape[1], features))) g_model.add(Dropout(0.2)) g_model.add( GraphConv(filters=5, neighbors_ix_mat=graph_mat, num_neighbors=num_neighbors, activation='elu')) g_model.add(GraphConvPro()) g_model.add(Flatten()) g_model.add(Dense(1, activation='sigmoid')) g_model.compile(loss='mean_squared_error', optimizer='Adam', metrics=[soft_AUC_theano, oe])
### Prepare the Graph Correlation matrix corr_mat = np.array(normalize(np.abs(np.corrcoef(X_train.transpose())), norm='l1', axis=1), dtype='float64') graph_mat = np.argsort(corr_mat, 1)[:, -nb_neighbors:] # %% ### Single layer of Graph Convolution g_model = Sequential() g_model.add( GraphConv(nb_filter=nb_filter, neighbors_ix_mat=graph_mat, nb_neighbors=nb_neighbors, activation='relu', input_shape=( X_train.shape[1], 1, ))) g_model.add(Dropout(0.2)) g_model.add(Flatten()) g_model.add(Dense(10, activation='softmax')) g_model.summary() g_model.compile(loss='categorical_crossentropy', optimizer=RMSprop(), metrics=['accuracy']) results['g'] = g_model.fit(X_train.reshape(X_train.shape[0], X_train.shape[1], 1),
epochs = np.arange(epoch) results_train = np.ones(epoch) * 20 results_test = np.ones(epoch) * 20 batch_size = 30 num_hidden = 32 filters_1 = 20 filters_2 = 22 filters_3 = 22 filters_4 = 16 filters_5 = 16 model = Sequential() model.add( GraphConv(filters=filters_1, neighbors_ix_mat=graph_mat, num_neighbors=num_neighbors, input_shape=(X_train.shape[1], 1))) model.add(BatchNormalization()) model.add(Activation('relu')) model.add( GraphConv(filters=filters_2, neighbors_ix_mat=graph_mat, num_neighbors=num_neighbors)) model.add(Activation('relu')) model.add( GraphConv(filters=filters_3, neighbors_ix_mat=graph_mat, num_neighbors=num_neighbors)) model.add(BatchNormalization()) model.add(Activation('relu')) model.add(
corr_mat = np.array(normalize(np.abs(np.corrcoef(X_train.transpose())), norm='l1', axis=1), dtype='float64') graph_mat = np.argsort(corr_mat, 1)[:, -num_neighbors:] print('graph_mat shape:(%d,%d)' % (graph_mat.shape)) # %% ### 1 layer graph CNN g_model = Sequential() g_model.add( GraphConv(filters=filters_1, neighbors_ix_mat=graph_mat, num_neighbors=num_neighbors, activation='relu', input_shape=(X_train.shape[1], 1))) g_model.add(Dropout(0.25)) g_model.add(Flatten()) g_model.add(Dense(1, kernel_regularizer=l2(0.01))) g_model.add(Dropout(0.1)) g_model.summary() g_model.compile(loss='mean_squared_error', optimizer='adam') results['g'] = [] for i in range(epochs): g_model.fit( X_train.reshape(X_train.shape[0], X_train.shape[1], 1),
Y_test = np_utils.to_categorical(y_test, nb_classes) # %% Generate the transition matrix Q q_mat_layer1 = generate_Q(28, 3) q_mat_layer2 = generate_Q(14, 3) q_mat_layer1 = np.argsort(q_mat_layer1, 1)[:, -nb_neighbors:] q_mat_layer2 = np.argsort(q_mat_layer2, 1)[:, -nb_neighbors:] # %% Standard LeNet structure with Graph Convolution model = Sequential() model.add( GraphConv(nb_filter=nb_layer_1, neighbors_ix_mat=q_mat_layer1, nb_neighbors=nb_neighbors, activation='relu', input_shape=( X_train.shape[1], 1, ))) model.add(Reshape((28, 28, nb_layer_1))) model.add(MaxPooling2D(pool_size=pool_size, dim_ordering='tf')) model.add(Dropout(0.25)) model.add(Reshape((196, nb_layer_1))) model.add( GraphConv(nb_filter=nb_layer_2, neighbors_ix_mat=q_mat_layer2, nb_neighbors=nb_neighbors, activation='relu', bias=True)) model.add(Reshape((14, 14, nb_layer_2))) model.add(MaxPooling2D(pool_size=pool_size, dim_ordering='tf'))
Y_test = np_utils.to_categorical(y_test, num_classes) # %% Generate the transition matrix Q q_mat_layer1 = generate_Q(28, 3) q_mat_layer2 = generate_Q(14, 3) q_mat_layer1 = np.argsort(q_mat_layer1, 1)[:, -num_neighbors:] q_mat_layer2 = np.argsort(q_mat_layer2, 1)[:, -num_neighbors:] # %% Standard LeNet structure with Graph Convolution model = Sequential() model.add( GraphConv(filters=num_layer_1, neighbors_ix_mat=q_mat_layer1, num_neighbors=num_neighbors, activation='relu', input_shape=( X_train.shape[1], 1, ))) model.add(Reshape((28, 28, num_layer_1))) model.add(MaxPooling2D(pool_size=pool_size, data_format='channels_last')) model.add(Dropout(0.25)) model.add(Reshape((196, num_layer_1))) model.add( GraphConv(filters=num_layer_2, neighbors_ix_mat=q_mat_layer2, num_neighbors=num_neighbors, activation='relu')) model.add(Reshape((14, 14, num_layer_2))) model.add(MaxPooling2D(pool_size=pool_size, data_format='channels_last'))