def bulid_model(activation_function, layerSize, input_size, num_of_classes, learning_rate_local, save_file, covn_net): """Bulid specipic model of the network Return the network """ model = mo.Model(input_size, layerSize, num_of_classes, learning_rate_local, save_file, int(activation_function), cov_net=covn_net) return model
def estimate_IY_by_network(data, labels): tf.reset_default_graph() input_size = data.shape[1] # For each epoch and for each layer we calculate the best decoder - we train a 2 lyaer network model = mo.Model(input_size, [400, 100, 50], labels.shape[1], 0.001, '', cov_net=0) optimizer = model.optimize init = tf.global_variables_initializer() num_of_ephocs = 60 batch_size = 1024 batch_points = np.rint(np.arange(0, data.shape[0] + 1, batch_size)).astype(dtype=np.int32) PYs = np.sum(labels, axis=0) / labels.shape[0] Hy = np.nansum(-PYs * np.log2(PYs + np.spacing(1))) print('rrrrr') with tf.Session() as sess: sess.run(init) # Go over the epochs for j in range(0, num_of_ephocs): for i in xrange(0, len(batch_points) - 1): batch_xs = data[batch_points[i]:batch_points[i + 1]] batch_ys = labels[batch_points[i]:batch_points[i + 1]] feed_dict = {model.x: batch_xs, model.labels: batch_ys} optimizer.run(feed_dict) #if np.mod(j, 1000) == 1: feed_dict = {model.x: data, model.labels: labels} print(j, sess.run(model.accuracy, feed_dict=feed_dict)) # for i in range(data.shape[0]): feed_dict = {model.x: np.matrix(data)} p_y_given_t_i = sess.run(model.prediction, feed_dict=feed_dict) true_label_index = np.argmax(labels, 1) s = np.log2(p_y_given_t_i[np.arange(len(p_y_given_t_i)), true_label_index]) I_TY = np.mean(s[np.isfinite(s)]) sess.close() print('jjj') I_TY = Hy + I_TY I_TY = I_TY if I_TY >= 0 else 0 return I_TY