def iterate_density(self, map_operator, T, transient): # Method that iterates a quantum neural network # with a neural map applied to a sequence of density operators densities = [] # sequence of density operators is stored in a list # Iterate the network for t in range(0, T): self.rho = svect.transformDensity(map_operator, self.rho) if t >= transient: densities.append(self.rho) # Return the sequence of densities return densities
transient = 10000 # transient seed_base = 3 # seed base step = 10 # step for seed generation coupling = 0.001 # noise coupling level h = get_hamiltonian(factor=1) # Hamiltonian for total firing energy mutual_information = [] mean_energy = [] # Iterate the network extracting the mean firing energy and mutual information for n in range(0, max_it): z = qn.get_seed(seed_base, n, step) angle = np.mod(r * 2 * pi + coupling * z.normal(), 2 * pi) / 2 neural_operators = get_unitaries(angle) NeuralMap = Net.build_quantum_neural_map(neural_operators) Net.rho = sv.transformDensity(NeuralMap, Net.rho) if n >= transient: entropy_0 = Net.calculate_entropy(neuron_index=0, multipliers_list=mult_2, print_density=False) entropy_1 = Net.calculate_entropy(neuron_index=1, multipliers_list=mult_2, print_density=False) mutual_information.append(entropy_0 + entropy_1) mean_energy.append(np.trace(np.dot(Net.rho, h)).real) # Plot the energy versus mutual information results fig, ax = plt.subplots(1) ax.scatter(mean_energy, mutual_information, c='k', marker='.', s=0.0001)
def iterate(self, map_operator, T, multipliers_list=None, entropy=False, density=False): # Method to iterate a quantum neural network applying # a unitary map and calculating the quantum averages if # asked for # 1. Initialize the relevant lists # If the sequence is for the density operators if density == True: # Initialize the density operators densities = [] # Otherwise the sequence is for the calculation of the # quantum averages for the local neural firing operators else: # Initialize the quantum averages list quantum_averages = [] # If the entropy is to be calculated for the reduced # local densities if entropy == True: # Initialize the entropies list entropies = [] # 2. Iterate the network # For each iteration of the quantum neural map for t in range(0, T): # Update the density self.rho = svect.transformDensity(map_operator, self.rho) # If we want the density as the final result then append # the neural network's density to the densities list if density == True: densities.append(self.rho) # Otherwise the quantum averages (and entropies are extracted) else: if entropy == True: new_point, entropy_values = self.extract_averages( multipliers_list, entropy) quantum_averages.append(new_point) entropies.append(entropy_values) else: new_point = self.extract_averages(multipliers_list, entropy) quantum_averages.append(new_point) # 3. Return the relevant lists for further processing if density == True: return densities else: if entropy == True: return np.array(quantum_averages), np.matrix(entropies) else: return np.array(quantum_averages)