NeuralNetwork¶
-
class
safe_learning.
NeuralNetwork
(layers, nonlinearities, output_scale=1.0, use_bias=True, name='neural_network')¶ A simple neural network.
The neural network also exposes its Lipschitz constant as NeuralNetwork.lipschitz.
Parameters: - layers : list
A list of layer sizes, [l1, l2, l3, .., ln]. l1 corresponds to the input dimension of the neural network, while ln is the output dimension.
- nonlinearities : list
A list of nonlinearities applied after each layer. Can be None if no nonlinearity should be applied.
- output_scale : float, optional
A constant scaling factor applied to the neural network output.
- use_bias : bool, optional
A boolean determining whether bias terms are included in each hidden layer; bias terms are never used in the output layer.
- name : string, optional
Attributes: parameters
Return the variables within the current scope.
- scope_name
Methods
__call__
(self, \*args, \*\*kwargs)Evaluate the function using the template to ensure variable sharing. build_evaluation
(self, points)Build the evaluation graph. copy_parameters
(self, other_instance)Copy over the parameters of another instance. lipschitz
(self)Return the Lipschitz constant as a Tensor. -
build_evaluation
(self, points)¶ Build the evaluation graph.
-
copy_parameters
(self, other_instance)¶ Copy over the parameters of another instance.
-
lipschitz
(self)¶ Return the Lipschitz constant as a Tensor.
This assumes that only contractive nonlinearities are used! Examples are ReLUs and Sigmoids.
Returns: - lipschitz : Tensor
The Lipschitz constant of the neural network.
-
parameters
¶ Return the variables within the current scope.