greenlearning package

class greenlearning.Model(G_network, U_hom_network)[source]

Bases: object

Create a model to learn Green’s function from input-output data with deep learning.

Example:

 # Construct neural networks for G and homogeneous solution
G_network = gl.matrix_networks([2] + [50] * 4 + [1], "rational", (2,2))
U_hom_network = gl.matrix_networks([1] + [50] * 4 + [1], "rational", (2,))

# Define the model
model = gl.Model(G_network, U_hom_network)

# Train the model on the selected dataset in the path "examples/datasets/"
model.train("examples/datasets/", "ODE_system")

# Plot the results
model.plot_results()

# Close the session
model.sess.close()
callback(loss)[source]

“Callback for optimizers: save the current value of the loss function.

init_optimizer()[source]

Initialize the variables and optimizers.

plot_results()[source]

Plot the learned Green’s function and homogeneous solution.

print_weights()[source]

Print all the trainable weights.

save_loss()[source]

Save the loss function in a file after training.

save_results()[source]

Save the Green’s function evaluated at a grid in a csv file.

train(example_path, example_name)[source]

Train the Green’s function and homogeneous solution networks.

class greenlearning.NeuralNetwork(layers, activation_name)[source]

Bases: object

Create a fully connected neural network with given number of layers and activation function.

Example:

gl.NeuralNetwork([2] + [50] * 4 + [1], "rational")

creates a rational neural network with 4 hidden layers of 50 neurons.

evaluate(X)[source]

Evaluate the neural network at the array X.

initialize_NN()[source]

Initialize the weights of the neural network.

xavier_init(size)[source]

Initializer for weights and biases.

greenlearning.matrix_networks(layers, activation, shape)[source]

Create a matrix of neural networks with the given parameters.

Example:

gl.matrix_networks([2] + [50] * 4 + [1], "rational", (2,1))

creates a matrix size 2 x 1 of rational networks with 4 hidden layers of 50 neurons.

Subpackages

Submodules

greenlearning.activations module

greenlearning.activations.get(identifier, weights)[source]

Return the activation function.

greenlearning.activations.initialize_weights(identifier)[source]

Initialize the weights of the activation functions.

greenlearning.activations.rational(x, weights)[source]

Define the rational activation function.

greenlearning.loss_function module

class greenlearning.loss_function.loss_function(G, N)[source]

Bases: object

Loss function for learning Green’s functions and homogeneous solutions.

Inputs: matrices of neural networks G and N.

build()[source]

Create Tensorflow placeholders and build the loss function.

feed_dict(inputs_xU, inputs_xF, inputs_f, inputs_u, weights_x, weights_y)[source]

Construct a feed_dict to feed values to TensorFlow placeholders.

property outputs

greenlearning.matrix_networks module

greenlearning.matrix_networks.matrix_networks(layers, activation, shape)[source]

Create a matrix of neural networks with the given parameters.

Example:

gl.matrix_networks([2] + [50] * 4 + [1], "rational", (2,1))

creates a matrix size 2 x 1 of rational networks with 4 hidden layers of 50 neurons.

greenlearning.model module

class greenlearning.model.Model(G_network, U_hom_network)[source]

Bases: object

Create a model to learn Green’s function from input-output data with deep learning.

Example:

 # Construct neural networks for G and homogeneous solution
G_network = gl.matrix_networks([2] + [50] * 4 + [1], "rational", (2,2))
U_hom_network = gl.matrix_networks([1] + [50] * 4 + [1], "rational", (2,))

# Define the model
model = gl.Model(G_network, U_hom_network)

# Train the model on the selected dataset in the path "examples/datasets/"
model.train("examples/datasets/", "ODE_system")

# Plot the results
model.plot_results()

# Close the session
model.sess.close()
callback(loss)[source]

“Callback for optimizers: save the current value of the loss function.

init_optimizer()[source]

Initialize the variables and optimizers.

plot_results()[source]

Plot the learned Green’s function and homogeneous solution.

print_weights()[source]

Print all the trainable weights.

save_loss()[source]

Save the loss function in a file after training.

save_results()[source]

Save the Green’s function evaluated at a grid in a csv file.

train(example_path, example_name)[source]

Train the Green’s function and homogeneous solution networks.

greenlearning.neural_network module

class greenlearning.neural_network.NeuralNetwork(layers, activation_name)[source]

Bases: object

Create a fully connected neural network with given number of layers and activation function.

Example:

gl.NeuralNetwork([2] + [50] * 4 + [1], "rational")

creates a rational neural network with 4 hidden layers of 50 neurons.

evaluate(X)[source]

Evaluate the neural network at the array X.

initialize_NN()[source]

Initialize the weights of the neural network.

xavier_init(size)[source]

Initializer for weights and biases.

greenlearning.quadrature_weights module

greenlearning.quadrature_weights.get_weights(identifier, x)[source]

Get the type of quadrature weights associated to the numpy array x.

greenlearning.quadrature_weights.trapezoidal(x)[source]

Trapezoidal weights for trapezoidal rule integration.

greenlearning.quadrature_weights.uniform(x)[source]

Uniform weights for Monte-Carlo integration.