Beispiel #1
0
 def generate_image(self, known_indexes=tuple(), known_pixels=tuple(), generate_mode='average'):
     # testing code
     known_indexes, known_pixels = list(known_indexes), list(known_pixels)
     n_pixels = len(known_indexes)
     if operator.eq(list(range(n_pixels)), list(known_indexes)):
         if self.tensor_info['regular_center'] > n_pixels:
             self.mps_regularization(n_pixels)
         tmp_left_tensor = numpy.array([1])
         tmp_left_tensor.shape = (1, 1)
         index = 0
         while index < self.tensor_info['n_length']:
             if index >= n_pixels:
                 tmp_tensor = wf.tensor_contract(
                     tmp_left_tensor, self.tensor_data[index], [[1], [0]])
                 tmp_tensor /= numpy.linalg.norm(tmp_tensor)
                 probability, state = numpy.linalg.eigh(
                     wf.tensor_contract(tmp_tensor, tmp_tensor, [[0, -1], [0, -1]]))
                 pixels = self.anti_feature_map(state)
                 if generate_mode == 'max':
                     # stupid code
                     probability[numpy.where(probability == probability.min())] = 0
                     probability /= probability.max()
                 known_pixels.append((numpy.array(probability) * numpy.array(pixels)).sum())
             tmp_left_tensor = numpy.dot(
                 tmp_left_tensor,
                 wf.tensor_contract(
                     self.tensor_data[index],
                     self.feature_map([known_pixels[index]]).flatten(),
                     [[1], [0]]))
             tmp_left_tensor /= numpy.linalg.norm(tmp_left_tensor)
             index += 1
         return numpy.array(known_pixels)
     else:
         print('only work when i know first n pixels')
Beispiel #2
0
 def measure_mps(self, operator=numpy.diag([1, -1])):
     # testing code
     measure_data = numpy.zeros(self.tensor_info['n_length'])
     if self.tensor_info['regular_center'] != 0:
         self.mps_regularization(0)
     self.tensor_data[0] /= self.tensor_data[0].norm()
     for ii in range(self.tensor_info['n_length']):
         measure_data[ii] = wf.tensor_contract(
             wf.tensor_contract(self.tensor_data[ii], self.tensor_data[ii], [[0, -1], [0, -1]]),
             operator, [[0, 1], [1, 0]])
         if ii < self.tensor_info['n_length'] - 1:
             self.move_regular_center2next()
     return measure_data
 def calculate_single_entropy(self, dot_index='all'):
     if operator.eq(dot_index, 'all'):
         dot_index = list(range(self.tensor_info['n_length']))
     elif isinstance(dot_index, int):
         dot_index = [dot_index]
     entropy = dict()
     for ii in dot_index:
         self.mps_regularization(ii)
         tmp_tensor = copy.deepcopy(self.tensor_data[ii])
         tmp_tensor = tmp_tensor / numpy.linalg.norm(tmp_tensor)
         tmp_tensor = wf.tensor_contract(tmp_tensor, tmp_tensor, [[0, -1], [0, -1]])
         tmp_spectrum = numpy.linalg.eigh(tmp_tensor)[0]
         tmp_spectrum /= numpy.sum(tmp_spectrum)
         tmp_spectrum[tmp_spectrum <= 0] = 1
         entropy[ii] = abs((tmp_spectrum * numpy.log(tmp_spectrum)).sum())
     return entropy