Beispiel #1
0
 def update_virtual_vecs_train(self, which_t, which_side):
     if (which_side is 'left') or (which_side is 'both'):
         tmp = tm.khatri(self.vecsLeft[which_t], self.vecsImages[:, which_t, :].squeeze())
         self.vecsLeft[which_t + 1] = np.tensordot(
             self.mps.mps[which_t], tmp, ([0, 1], [0, 1]))
     if (which_side is 'right') or (which_side is 'both'):
         tmp = tm.khatri(self.vecsRight[which_t], self.vecsImages[:, which_t, :].squeeze())
         self.vecsRight[which_t - 1] = np.tensordot(
             self.mps.mps[which_t], tmp, ([2, 1], [0, 1]))
Beispiel #2
0
 def env_tensor(self, nt, way):
     s = self.mps.mps[nt].shape
     env = tm.khatri(tm.khatri(
         self.vecsLeft[nt], self.vecsImages[:, nt, :].squeeze()).reshape(
         self.mps.virtual_dim[nt] * self.d, self.numVecSample), self.vecsRight[nt])
     if way is 'mera':
         env = env.dot(np.ones((self.numVecSample, )))
     elif way is 'gradient':
         weight = self.mps.mps[nt].reshape(1, -1).dot(env)
         env = env.dot(1 / weight)
     return env.reshape(s)
 def update_virtual_vecs_train(self, which_t, which_side):
     if (which_side is 'left') or (which_side is 'both'):
         tmp = tm.khatri(self.vecsLeft[which_t],
                         self.vecsImages[:, which_t, :])
         self.vecsLeft[which_t + 1] = np.tensordot(self.mps.mps[which_t],
                                                   tmp, ([0, 1], [0, 1]))
         norm = np.linalg.norm(self.vecsLeft[which_t + 1], axis=0)
         self.norms[which_t, :] = norm
         self.vecsLeft[which_t + 1] /= norm.repeat(
             self.mps.virtual_dim[which_t + 1]).reshape(
                 self.numVecSample, self.mps.virtual_dim[which_t + 1]).T
     if (which_side is 'right') or (which_side is 'both'):
         tmp = tm.khatri(self.vecsRight[which_t],
                         self.vecsImages[:, which_t, :])
         self.vecsRight[which_t - 1] = np.tensordot(self.mps.mps[which_t],
                                                    tmp, ([2, 1], [0, 1]))
         norm = np.linalg.norm(self.vecsRight[which_t - 1], axis=0)
         self.norms[which_t, :] = norm
         self.vecsRight[which_t - 1] /= norm.repeat(
             self.mps.virtual_dim[which_t]).reshape(
                 self.numVecSample, self.mps.virtual_dim[which_t]).T
 def compute_fidelities(self, mps):
     fid = np.zeros((self.numVecSample, 1))
     vecs = np.ones((1, self.numVecSample))
     for nt in range(self.length):
         s = mps[nt].shape
         vecs = np.tensordot(mps[nt],
                             tm.khatri(vecs, self.vecsImages[:, nt, :]),
                             ([0, 1], [0, 1]))
         norm = np.linalg.norm(vecs, axis=0)
         vecs /= norm.repeat(s[2]).reshape(self.numVecSample, s[2]).T
         fid -= np.log(norm.reshape(self.numVecSample, 1))
     return fid / self.length
 def compute_bond_vectors(self, nb=0):
     # Contract the samples to the MPS but left the nb-th physical bond empty
     # The bond vectors are normalized
     vecsL = np.ones((1, self.numVecSample))
     for nt in range(0, nb):
         s = self.mps.mps[nt].shape
         tmp = tm.khatri(vecsL, self.vecsImages[:, nt, :].squeeze())
         vecsL = np.tensordot(self.mps.mps[nt], tmp, ([0, 1], [0, 1]))
         norm = np.linalg.norm(vecsL, axis=0)
         vecsL /= norm.repeat(s[2]).reshape(self.numVecSample, s[2]).T
     vecsR = np.ones((1, self.numVecSample))
     for nt in range(self.length - 1, nb, -1):
         s = self.mps.mps[nt].shape
         tmp = tm.khatri(vecsR, self.vecsImages[:, nt, :].squeeze())
         vecsR = np.tensordot(self.mps.mps[nt], tmp, ([2, 1], [0, 1]))
         norm = np.linalg.norm(vecsR, axis=0)
         vecsR /= norm.repeat(s[2]).reshape(self.numVecSample, s[2]).T
     s = self.mps.mps[nb].shape
     tmp = np.tensordot(self.mps.mps[nb], tm.khatri(vecsL, vecsR),
                        ([0, 2], [0, 1]))
     norm = np.linalg.norm(tmp, axis=0)
     tmp /= norm.repeat(s[2]).reshape(self.numVecSample, s[2]).T
     return tmp