def _covariance_final_ops(sum_squares, total):
# http://www.johnloomis.org/ece563/notes/covar/covar.html
total = total - tf.constant(1.0)
total_3x3 = tf.reshape(tf.tile(tf.expand_dims(total, 0), [9]), [3, 3])
covariance = tf.div(sum_squares, total_3x3)
variance = tf.gather(tf.reshape(covariance, [-1]), [0, 4, 8])
# eigenvalues and eigenvectors for PCA
eigens = tf.self_adjoint_eig(covariance)
eigenvalues = tf.slice(eigens, [0, 0], [-1, 1])
eigenvectors = tf.slice(eigens, [1, 0], [-1, -1])
return tf.sqrt(variance), eigenvalues, eigenvectors
评论列表
文章目录