test.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:sdp 作者: tansey 项目源码 文件源码
def __init__(self, length, k, lam):
        with tf.variable_scope(type(self).__name__):
            self.length = length
            self.k = k
            self.lam = lam
            self.D = tf_get_delta(get_sparse_penalty_matrix((length,)), k)
            self.samples = tf.placeholder(tf.int32, [None])
            self.y = tf.one_hot(self.samples, length)
            self.q = tf.Variable([1.]*length)
            self.yhat = tf.nn.softmax(self.q, name='yhat')
            self.acc = tf.reduce_mean(-tf.reduce_sum(self.y * tf.log(tf.clip_by_value(self.yhat, 1e-10, 1.0)) 
                                                          + (1 - self.y) * tf.log(tf.clip_by_value(1 - self.yhat, 1e-10, 1.0)),
                                        axis=[1]))
            self.reg = tf.reduce_sum(tf.abs(tf.sparse_tensor_dense_matmul(self.D, tf.expand_dims(self.q,-1))))
            self.loss = self.acc + self.lam * self.reg
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号