_optim_tf.py 文件源码

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

项目:AdaptiveOptim 作者: tomMoral 项目源码 文件源码
def optimize(self, X, lmbd, Z=None, max_iter=1, tol=1e-5):
        if Z is None:
            batch_size = X.shape[0]
            K = self.D.shape[0]
            z_curr = np.zeros((batch_size, K))
        else:
            z_curr = np.copy(Z)
        self.train_cost, self.train_z = [], []
        feed = {self.X: X, self.Z: z_curr, self.lmbd: lmbd}
        for k in range(max_iter):
            z_curr[:], dz, cost = self.session.run(
                [self.step_optim, self.dz, self._cost], feed_dict=feed)
            self.train_cost += [cost]
            self.train_z += [np.copy(z_curr)]
            if dz < tol:
                print("\r{} reached optimal solution in {}-iteration"
                      .format(self.name, k))
                break
            out.write("\rIterative optimization ({}): {:7.1%} - {:.4e}"
                      "".format(self.name, k/max_iter, dz))
            out.flush()
        self.train_cost += [self.session.run(self._cost, feed_dict=feed)]
        print("\rIterative optimization ({}): {:7}".format(self.name, "done"))
        return z_curr
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号