API¶
-
neural_schrodinger.bin_to_float(binary)[source]¶ Converts a binary number encoded with fixed point format. Here the first digit is reserved for sign and the rest are binary places starting with 2^1 and decreasing. Here we use ten bits to encode a number.
Parameters: binary : string
A string of ten digits representing the number in binary fixed point format.
Returns: number : float
A float that corresponds to the fixed point binary format.
-
neural_schrodinger.breed_genes(gene1, gene2)[source]¶ Mates two genes using the uniform crossover algorithm.
Parameters: gene1 : string
The string representing the first gene to mate
gene2 : string
The string representing the second gene to mate.
Returns: newgene : string
The child of the two mated strings
-
neural_schrodinger.eigenfunction(net, x)[source]¶ Converts the two outputs of the neural network to the value of the wavefunction at x.
Parameters: net : PyBrain FeedForwardNetwork
The neural network that represents the wavefunction.
x : float
The location at which one wants to evaluate the wavefunction.
Returns: wavefunction : float
The value of the wavefunction at x
-
neural_schrodinger.eigenfunction_second_deriv(net, x)[source]¶ Calculates the second derivative of the wavefunction represented by net.
Parameters: net : PyBrain FeedForwardNetwork
The neural network representing the wavefunction.
x : float
The location at which one wishes to evaluate the wavefunction.
-
neural_schrodinger.float_to_bin(number)[source]¶ Converts a floating point number to a ten bit fixed point format as specified in bin_to_float.
Parameters: number : float
The floating point number to convert.
Returns: binary : string
A string representing the binary encoding of the floating point number in ten bit fixed point format.
-
neural_schrodinger.gene_fitness(gene, net, points, mass)[source]¶ Calculates the fitness of the gene based on the difference between the energy and the hamiltonian applied to the wavefunction squared evaluated at the points specified by points.
Parameters: gene : string
The gene with which one wishes to get the fitness of.
net : PyBrain FeedForwardNetwork
The neural network used to represent the wavefunction.
points : array of floats
An array of random points with which one wishes to evaluate the hamiltonian.
mass : float
The reduced mass of the harmonic oscillator system.
Returns: float
The fitness of the gene.
-
neural_schrodinger.gene_to_system(gene)[source]¶ Converts a gene to a system which corresponds to a set of neural network weights and an energy.
Parameters: gene : string
A string representing the binary encoding of the system
Returns: weights,energy : (float list,float)
A tuple containing the weights and energy of the system.
-
neural_schrodinger.get_random_gene(gene_length)[source]¶ Returns a random gene which corresponds to a random binary sequence of length specified by gene_length.
Parameters: gene_length : int
Length og the random gene to generate
Returns: gene : string
A string representing a random gene of length gene_length
-
neural_schrodinger.get_random_points(xmin, xmax, M)[source]¶ Gets n random points between xmin and xmax used for the random point evaluation method.
Parameters: xmin : float
Minimum value that the points can take.
xmax : float
Maximum value that the points can take.
M : int
The number of points to generate.
Returns: array of floats
An array of M random points.
-
neural_schrodinger.get_weights_by_layer(net, layername)[source]¶ Get the weights of the layer specified by layername of a PyBrain neural network net.
Parameters: net : PyBrain FeedForwardNetwork
A feed forward neural network created using PyBrain
layername : string
A string specifying the name of the layer that one wishes to get the weights of.
Returns: weights : numpy array of floats
A Numpy array of floats containing the weights of the specified layer.
-
neural_schrodinger.hamiltonian(net, x, mass)[source]¶ Calculates the hamiltonian of a harmonic oscillator of reduced mass “mass” applied to the wavefunction represented by net.
Parameters: net : PyBrain FeedForwardNetwork
The neural network that represents the wavefunction one wishes to apply the hamiltonian to.
x : float
The location at which one wishes to get the value of the hamiltonian
mass : float
The reduced mass of the harmonic oscillator
Returns: float
The value of the hamiltonian applied to the wavefunction
-
neural_schrodinger.initialize_nn()[source]¶ Initializes a neural network using PyBrain with 6 hidden layers, 1 input layerm and 2 output layers.
-
neural_schrodinger.natural_selection(genes, net, num_survivors, points, mass)[source]¶ Applies “natural selection” to a list of genes using the tournament methodology. In this methodology genes are pitted against each other in pairs and the gene with the greatest fitness wins. This continues until the specified amount of genes are obtained.
Parameters: genes : list of strings
A list of strings each of which corresponds to a gene.
net : PyBrain FeedForwardNetwork
The neural network used to approximate the wavefunction
num_survivors : int
The number of survivors that are desired to be left.
points : array of floats
A set of points one wishes to evaluate the genes fitness on.
mass : float
The reduced mass used in the Schrodinger equation to evaluate fitness.
Returns: survivors, survivor_fitnesses : (list of strings, list of floats)
A list of survivor genes and their associated fitnesses.
-
neural_schrodinger.nn_array(net, array)[source]¶ Apply the neural network over an array.
Parameters: net : PyBrain FeedForwardNetwork
Neural network to apply over an array.
array : array of floats
Array of floats to activate the neural network over
Returns: array of floats
The output of the neural network for each element of the array
-
neural_schrodinger.nn_first_derivative(net, x)[source]¶ The first derivative of a feedforward neural network with one hidden sigmoid layer.
Parameters: net : PyBrain FeedForwardNetwork
The neural network one wishes to get the first derivative of.
x : float
The location x where one wants the derivative
Returns: output1_derivative, output2_derivative : (float,float)
The first derivative of the first and second output of the neural network.
-
neural_schrodinger.nn_second_derivative(net, x)[source]¶ The second derivative of a feedforward neural network with one hidden sigmoid layer.
Parameters: net : PyBrain FeedForwardNetwork
The neural network one wishes to get the first derivative of.
x : float
The location x where one wants the derivative
Returns: output1_derivative, output2_derivative : (float,float)
The second derivative of the first and second output of the neural network.
-
neural_schrodinger.system_to_gene(net, energy)[source]¶ Converts a system specified by the given PyBrain neural network and energy to a binary encoding specified by float_to_bin.
Parameters: net : PyBrain FeedForwardNetwork
A PyBrain neural network that corresponds to the wavefunction guess
energy : float
The guessed energy that corresponds to the given neural network
Returns: string
A string which specifies the binary encoding of the given system.
-
neural_schrodinger.weights_to_binary(net)[source]¶ Converts the weights of a PyBrain neural network to the binary encoding specified by float_to_bin.
Parameters: net : PyBrain FeedForwardNetwork
Returns: gene : string
A string that corresponds to the binary encoding of the neural network which corresponds to the binary encoding of the neural network weights.