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])
self._w = w = tf.placeholder(tf.float32, shape=[])
self._b = b = tf.placeholder(tf.float32, shape=[])
tuu = tf.sigmoid(w * t_uu + b)
tul = tf.sigmoid(w * t_ul + b)
# 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"))
评论列表
文章目录