def __init__(self, n_labeled, n_unlabeled, n_classes):
self._t_uu = t_uu = tf.placeholder(tf.float32, shape=[n_unlabeled, n_unlabeled])
self._t_ul = t_ul = tf.placeholder(tf.float32, shape=[n_unlabeled, n_labeled])
self._y_l = y_l = tf.placeholder(tf.float32, shape=[n_labeled, n_classes])
w_init = tf.random_uniform(shape=[], minval=0.5, maxval=5)
self._w = w = tf.get_variable("w", dtype=tf.float32, initializer=w_init)
b_init = tf.random_uniform(shape=[], minval=-1, maxval=1)
self._b = b = tf.get_variable("b", dtype=tf.float32, initializer=b_init)
tuu = tf.sigmoid(w * t_uu + b)
tul = tf.sigmoid(w * t_ul + b)
# tuu = tf.Print(tuu, [tuu], 'tuu', summarize=30)
# tul = tf.Print(tul, [tul], 'tul', summarize=30)
# column normalization
tuu_col_norms = tf.norm(tuu, ord=1, axis=0)
tul_col_norms = tf.norm(tul, ord=1, axis=0)
tuu /= tuu_col_norms
tul /= tul_col_norms
# row normalization
tuu_row_norms = tf.norm(tuu, ord=1, axis=1)
tul_row_norms = tf.norm(tul, ord=1, axis=1)
tuu /= tf.reshape(tuu_row_norms, [n_unlabeled, 1])
tul /= tf.reshape(tul_row_norms, [n_unlabeled, 1])
I = tf.eye(n_unlabeled, dtype=tf.float32)
inv = tf.matrix_solve_ls((I - tuu), I, l2_regularizer=0.01)
y_u = tf.matmul(tf.matmul(inv, tul), y_l)
y = tf.concat([y_u, y_l], 0)
self._y = y = tf.clip_by_value(y, 1e-15, float("inf"))
self._entropy = entropy = - tf.reduce_sum(y * tf.log(y))
self._train_op = tf.train.AdamOptimizer(0.1).minimize(entropy)
评论列表
文章目录